{"record":{"id":"330694801c524d66","repo":"Lightning-AI/pytorch-lightning","slug":"you-requested-gpu-gpus-but-your-machine-only-h","errorCode":null,"errorMessage":"You requested gpu: {gpus}\n But your machine only has: {all_available_gpus}","messagePattern":"You requested gpu: (.+?)\n But your machine only has: (.+?)","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":136,"sourceCode":"    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\n        return None\n    if gpus == -1:\n        return _get_all_available_gpus(include_cuda=include_cuda, include_mps=include_mps)\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L118-L154","documentation":"Lightning validates the GPU indices you requested (e.g. devices=[3] or CUDA_VISIBLE_DEVICES-derived ids) against the GPUs actually visible to the process. If any requested id is not in the list returned by _get_all_available_gpus, it raises MisconfigurationException showing both lists. This usually means the ids don't exist in the current environment (wrong node, wrong CUDA_VISIBLE_DEVICES, or fewer GPUs than requested).","triggerScenarios":"Passing devices=[1] or devices='1,' when only 1 GPU (index 0) is visible; setting devices=4 on a node with 2 GPUs; a CUDA_VISIBLE_DEVICES string like '2,3' on a machine with only 2 GPUs; requesting an MPS gpu id on a non-Apple machine.","commonSituations":"Multi-node jobs scheduled on nodes with heterogeneous GPU counts; Slurm/NGC containers restricting visible GPUs; hard-coded device indices moved between machines; typos in comma-separated device strings.","solutions":["Print torch.cuda.device_count() / check nvidia-smi and request valid indices (0..N-1)","Use devices='auto' or devices=N to let Lightning pick from available GPUs","Verify CUDA_VISIBLE_DEVICES on the target node and align requested ids with it"],"exampleFix":"# before\nfabric = Fabric(accelerator=\"gpu\", devices=[2, 3])  # node has 2 GPUs\n\n# after\nfabric = Fabric(accelerator=\"gpu\", devices=\"auto\")","handlingStrategy":"validation","validationCode":"import torch\n\ndef available_gpu_ids():\n    if torch.cuda.is_available():\n        return list(range(torch.cuda.device_count()))\n    if getattr(torch.backends, \"mps\", None) and torch.backends.mps.is_available():\n        return [0]\n    return []\n\nrequested = [2, 3]\nassert set(requested) <= set(available_gpu_ids()), f\"requested {requested}, have {available_gpu_ids()}\"","typeGuard":"def is_valid_gpu_list(devices: object) -> bool:\n    return (\n        isinstance(devices, (list, tuple))\n        and all(type(d) is int for d in devices)\n        and len(devices) == len(set(devices))\n    )","tryCatchPattern":null,"preventionTips":["Use devices='auto' unless you must pin specific GPUs","Check nvidia-smi / CUDA_VISIBLE_DEVICES on the node before hard-coding indices"],"tags":["gpu","device-configuration","cuda","multi-node","lightning"],"backgroundTag":"requested-device-not-available","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}