{"record":{"id":"21b3f1e2c801ab79","repo":"Lightning-AI/pytorch-lightning","slug":"at-least-one-gpu-type-should-be-specified","errorCode":null,"errorMessage":"At least one gpu type should be specified!","messagePattern":"At least one gpu type should be specified!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":132,"sourceCode":"\n\ndef _sanitize_gpu_ids(gpus: list[int], include_cuda: bool = False, include_mps: bool = False) -> list[int]:\n    \"\"\"Checks that each of the GPUs in the list is actually available. Raises a MisconfigurationException if any of the\n    GPUs is not available.\n\n    Args:\n        gpus: List of ints corresponding to GPU indices\n\n    Returns:\n        Unmodified gpus variable\n\n    Raises:\n        MisconfigurationException:\n            If machine has fewer available GPUs than requested.\n\n    \"\"\"\n    if sum((include_cuda, include_mps)) == 0:\n        raise ValueError(\"At least one gpu type should be specified!\")\n    all_available_gpus = _get_all_available_gpus(include_cuda=include_cuda, include_mps=include_mps)\n    for gpu in gpus:\n        if gpu not in all_available_gpus:\n            raise MisconfigurationException(\n                f\"You requested gpu: {gpus}\\n But your machine only has: {all_available_gpus}\"\n            )\n    return gpus\n\n\ndef _normalize_parse_gpu_input_to_list(\n    gpus: Union[int, list[int], tuple[int, ...]], include_cuda: bool, include_mps: bool\n) -> Optional[list[int]]:\n    assert gpus is not None\n    if isinstance(gpus, (MutableSequence, tuple)):\n        return list(gpus)\n\n    # must be an int\n    if not gpus:  # gpus==0","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'"],"exampleFix":"# before\nids = _parse_gpu_ids(\"0\", include_cuda=False, include_mps=False)\n\n# after\nids = _parse_gpu_ids(\"0\", include_cuda=torch.cuda.is_available(), include_mps=torch.backends.mps.is_available())","handlingStrategy":"validation","validationCode":"from lightning.fabric.utilities.device_parser import _parse_gpu_ids\nimport torch\n\nids = _parse_gpu_ids(\n    \"0\",\n    include_cuda=torch.cuda.is_available(),\n    include_mps=torch.backends.mps.is_available(),\n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["gpu","device-configuration","lightning","cuda","mps"],"backgroundTag":"invalid-device-configuration","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}