{"record":{"id":"b27a7d6cdfd1b13c","repo":"Lightning-AI/pytorch-lightning","slug":"device-id-s-gpu-must-be-unique","errorCode":null,"errorMessage":"Device ID's (GPU) must be unique.","messagePattern":"Device ID's \\(GPU\\) must be unique\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":183,"sourceCode":"\n    cuda_gpus = _get_all_visible_cuda_devices() if include_cuda else []\n    mps_gpus = _get_all_available_mps_gpus() if include_mps else []\n    return cuda_gpus + mps_gpus\n\n\ndef _check_unique(device_ids: list[int]) -> None:\n    \"\"\"Checks that the device_ids are unique.\n\n    Args:\n        device_ids: List of ints corresponding to GPUs indices\n\n    Raises:\n        MisconfigurationException:\n            If ``device_ids`` of GPUs aren't unique\n\n    \"\"\"\n    if len(device_ids) != len(set(device_ids)):\n        raise MisconfigurationException(\"Device ID's (GPU) must be unique.\")\n\n\ndef _check_data_type(device_ids: object) -> None:\n    \"\"\"Checks that the device_ids argument is one of the following: int, string, or sequence of integers.\n\n    Args:\n        device_ids: gpus/tpu_cores parameter as passed to the Trainer\n\n    Raises:\n        TypeError:\n            If ``device_ids`` of GPU/TPUs aren't ``int``, ``str`` or sequence of ``int```\n\n    \"\"\"\n    msg = \"Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed\"\n    if device_ids is None:\n        raise TypeError(f\"{msg} None\")\n    if isinstance(device_ids, (MutableSequence, tuple)):\n        for id_ in device_ids:","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L165-L201","documentation":"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)).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nFabric(accelerator=\"gpu\", devices=[0, 0])\n\n# after\nFabric(accelerator=\"gpu\", devices=[0, 1])  # or devices=2","handlingStrategy":"validation","validationCode":"devices = [0, 0]\nassert len(devices) == len(set(devices)), \"duplicate GPU ids in devices\"\ndevices = list(dict.fromkeys(devices))  # dedupe, keep order","typeGuard":"def has_unique_int_ids(devices: list) -> bool:\n    return all(type(d) is int for d in devices) and len(devices) == len(set(devices))","tryCatchPattern":null,"preventionTips":["Prefer devices=<count> or 'auto' over explicit id lists","Lint configs for repeated indices in comma-separated device strings"],"tags":["gpu","duplicate-ids","device-configuration","validation"],"backgroundTag":"duplicate-device-ids","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}