Lightning-AI/pytorch-lightning · error · ValueError
At least one gpu type should be specified!
Error message
At least one gpu type should be specified!
What it means
Raised by Lightning's GPU device parser when _sanitize_gpu_ids is called without any GPU backend flag. Internally, _parse_gpu_ids/_sanitize_gpu_ids must know whether to check CUDA or MPS availability, and passing include_cuda=False and include_mps=False makes the availability query ambiguous, so it refuses with a ValueError. This is essentially an internal-contract error that surfaces when callers (or custom accelerators/strategies) invoke the parser incorrectly.
Source
Thrown at src/lightning/fabric/utilities/device_parser.py:132
def _sanitize_gpu_ids(gpus: list[int], include_cuda: bool = False, include_mps: bool = False) -> list[int]:
"""Checks that each of the GPUs in the list is actually available. Raises a MisconfigurationException if any of the
GPUs is not available.
Args:
gpus: List of ints corresponding to GPU indices
Returns:
Unmodified gpus variable
Raises:
MisconfigurationException:
If machine has fewer available GPUs than requested.
"""
if sum((include_cuda, include_mps)) == 0:
raise ValueError("At least one gpu type should be specified!")
all_available_gpus = _get_all_available_gpus(include_cuda=include_cuda, include_mps=include_mps)
for gpu in gpus:
if gpu not in all_available_gpus:
raise MisconfigurationException(
f"You requested gpu: {gpus}\n But your machine only has: {all_available_gpus}"
)
return gpus
def _normalize_parse_gpu_input_to_list(
gpus: Union[int, list[int], tuple[int, ...]], include_cuda: bool, include_mps: bool
) -> Optional[list[int]]:
assert gpus is not None
if isinstance(gpus, (MutableSequence, tuple)):
return list(gpus)
# must be an int
if not gpus: # gpus==0View on GitHub (pinned to 9fed5c27d2)
Solutions
- If you're a normal user: don't call these private helpers; configure Fabric/Trainer with accelerator='gpu', devices=..., and let Lightning pick the backend
- If you call _parse_gpu_ids yourself, set include_cuda=True (NVIDIA) or include_mps=True (Apple silicon) appropriately
- On CPU-only machines use accelerator='cpu' instead of 'gpu'
Example fix
# before
ids = _parse_gpu_ids("0", include_cuda=False, include_mps=False)
# after
ids = _parse_gpu_ids("0", include_cuda=torch.cuda.is_available(), include_mps=torch.backends.mps.is_available()) Defensive patterns
Strategy: validation
Validate before calling
from lightning.fabric.utilities.device_parser import _parse_gpu_ids
import torch
ids = _parse_gpu_ids(
"0",
include_cuda=torch.cuda.is_available(),
include_mps=torch.backends.mps.is_available(),
) Prevention
- Don't call private _parse_gpu_ids/_sanitize_gpu_ids directly; configure Fabric/Trainer devices instead
- Always derive include_cuda/include_mps from torch availability checks
When it happens
Trigger: Calling lightning.fabric.utilities.device_parser._parse_gpu_ids or _sanitize_gpu_ids with both include_cuda=False and include_mps=False; e.g. requesting devices='gpu' on a build where neither CUDA nor MPS detection was requested, or a custom Strategy/Accelerator reusing these helpers without setting a backend flag.
Common situations: Developers writing custom accelerators or calling private parsing helpers directly; running on CPU-only machines while forcing accelerator='gpu'; refactors that pass the include flags positionally in the wrong order.
Related errors
- You requested gpu: {gpus} But your machine only has: {all_a
- GPU parallel_devices set through {self._strategy_flag.__clas
- GPUs requested but none are available.
- Device ID's (GPU) must be unique.
- TensorRT only supports CUDA devices. The current device is {
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/21b3f1e2c801ab79.
Report an issue: GitHub.