Lightning-AI/pytorch-lightning · error · MisconfigurationException
Device ID's (GPU) must be unique.
Error message
Device ID's (GPU) must be unique.
What it means
When you pass an explicit list of GPU indices to Lightning (e.g. devices=[0,0] or '0,0'), _check_unique verifies there are no duplicates because duplicate ids would map two processes to the same GPU. A MisconfigurationException is raised when len(device_ids) != len(set(device_ids)).
Source
Thrown at src/lightning/fabric/utilities/device_parser.py:183
cuda_gpus = _get_all_visible_cuda_devices() if include_cuda else []
mps_gpus = _get_all_available_mps_gpus() if include_mps else []
return cuda_gpus + mps_gpus
def _check_unique(device_ids: list[int]) -> None:
"""Checks that the device_ids are unique.
Args:
device_ids: List of ints corresponding to GPUs indices
Raises:
MisconfigurationException:
If ``device_ids`` of GPUs aren't unique
"""
if len(device_ids) != len(set(device_ids)):
raise MisconfigurationException("Device ID's (GPU) must be unique.")
def _check_data_type(device_ids: object) -> None:
"""Checks that the device_ids argument is one of the following: int, string, or sequence of integers.
Args:
device_ids: gpus/tpu_cores parameter as passed to the Trainer
Raises:
TypeError:
If ``device_ids`` of GPU/TPUs aren't ``int``, ``str`` or sequence of ``int```
"""
msg = "Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed"
if device_ids is None:
raise TypeError(f"{msg} None")
if isinstance(device_ids, (MutableSequence, tuple)):
for id_ in device_ids:View on GitHub (pinned to 9fed5c27d2)
Solutions
- Inspect your devices argument and remove duplicate indices, e.g. '0,1' instead of '0,0'
- If you meant N processes, use devices=2 or 'auto' rather than listing ids
- Sanitize programmatically generated lists: devices=list(set(ids)) or dedupe preserving order
Example fix
# before Fabric(accelerator="gpu", devices=[0, 0]) # after Fabric(accelerator="gpu", devices=[0, 1]) # or devices=2
Defensive patterns
Strategy: validation
Validate before calling
devices = [0, 0] assert len(devices) == len(set(devices)), "duplicate GPU ids in devices" devices = list(dict.fromkeys(devices)) # dedupe, keep order
Type guard
def has_unique_int_ids(devices: list) -> bool:
return all(type(d) is int for d in devices) and len(devices) == len(set(devices)) Prevention
- Prefer devices=<count> or 'auto' over explicit id lists
- Lint configs for repeated indices in comma-separated device strings
When it happens
Trigger: devices=[0, 0]; devices='1,1'; a duplicated id produced by string splitting such as devices='0, 0'; programmatically built device lists that accidentally repeat an index.
Common situations: Copy-paste typos in comma-separated device strings; building the devices list from another list with duplicates; whitespace-insensitive string parsing producing the same id twice.
Related errors
- At least one gpu type should be specified!
- You requested gpu: {gpus} But your machine only has: {all_a
- Device should be CUDA, got {device} instead.
- You requested to find {num_devices} devices but there are no
- GPU parallel_devices set through {self._strategy_flag.__clas
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/b27a7d6cdfd1b13c.
Report an issue: GitHub.