{"record":{"id":"02b29811b70d19e3","repo":"Lightning-AI/pytorch-lightning","slug":"gpus-should-be-a-list","errorCode":null,"errorMessage":"GPUs should be a list","messagePattern":"GPUs should be a list","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":41,"sourceCode":"def _determine_root_gpu_device(gpus: list[_DEVICE]) -> Optional[_DEVICE]:\n    \"\"\"\n    Args:\n        gpus: Non-empty list of ints representing which GPUs to use\n\n    Returns:\n        Designated root GPU device id\n\n    Raises:\n        TypeError:\n            If ``gpus`` is not a list\n        AssertionError:\n            If GPU list is empty\n    \"\"\"\n    if gpus is None:\n        return None\n\n    if not isinstance(gpus, list):\n        raise TypeError(\"GPUs should be a list\")\n\n    assert len(gpus) > 0, \"GPUs should be a non-empty list\"\n\n    # set root gpu\n    return gpus[0]\n\n\ndef _parse_gpu_ids(\n    gpus: Optional[Union[int, str, list[int]]],\n    include_cuda: bool = False,\n    include_mps: bool = False,\n) -> Optional[list[int]]:\n    \"\"\"Parses the GPU IDs given in the format as accepted by the :class:`~lightning.pytorch.trainer.trainer.Trainer`.\n\n    Args:\n        gpus: An int -1 or string '-1' indicate that all available GPUs should be used.\n            A list of unique ints or a string containing a list of comma separated unique integers\n            indicates specific GPUs to use.","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L23-L59","documentation":"`_determine_root_gpu_device` expects the GPU specification to already be a list (as produced by earlier parsing stages such as `_parse_gpu_ids`). If it receives anything other than None or a list (e.g. an int or string passed directly to this internal helper), it raises TypeError('GPUs should be a list').","triggerScenarios":"Calling `lightning.fabric.utilities.device_parser._determine_root_gpu_device` directly with a non-list such as `gpus=1` or `gpus='0,1'` instead of a list like `[0]`, instead of going through `parse_devices`/`_parse_gpu_ids` which normalize input first.","commonSituations":"User code or tests bypassing the public device-resolution API and calling the internal helper with the raw Trainer-style `gpus` argument (int, string, or None-like sentinel).","solutions":["Call the public entry point `parse_devices(...)` (or `_parse_gpu_ids`) instead of `_determine_root_gpu_device` directly, so input is normalized.","If you must call it, normalize first: pass `gpus` as a list (e.g. `[0]`) or None.","Convert Trainer-style specs yourself: int n -> list(range(n)); '2' -> [0,1]; '-1' -> all available GPU indices."],"exampleFix":"# before\nroot = _determine_root_gpu_device(gpus=1)  # TypeError\n\n# after\nroot = _determine_root_gpu_device(gpus=[0])","handlingStrategy":"type-guard","validationCode":"assert gpus is None or (isinstance(gpus, list) and len(gpus) > 0)\nroot_gpu = _determine_root_gpu_device(gpus)","typeGuard":"def is_gpu_list(v) -> bool:\n    return v is None or (isinstance(v, list) and len(v) > 0 and all(isinstance(i, int) for i in v))","tryCatchPattern":null,"preventionTips":["Prefer public APIs (parse_devices / Trainer devices) over internal _determine_root_gpu_device.","Normalize gpus specs to lists (or None) before calling internal helpers."],"tags":["pytorch-lightning","gpu","device-parser","internal-api"],"backgroundTag":"invalid-argument-type","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}