{"record":{"id":"8172dc918799a19f","repo":"Lightning-AI/pytorch-lightning","slug":"gpus-requested-but-none-are-available","errorCode":null,"errorMessage":"GPUs requested but none are available.","messagePattern":"GPUs requested but none are available\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"critical","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":89,"sourceCode":"\n    .. note::\n        ``include_cuda`` and ``include_mps`` default to ``False`` so that you only\n        have to specify which device type to use and all other devices are not disabled.\n\n    \"\"\"\n    # Check that gpus param is None, Int, String or Sequence of Ints\n    _check_data_type(gpus)\n\n    # Handle the case when no GPUs are requested\n    if gpus is None or (isinstance(gpus, int) and gpus == 0) or str(gpus).strip() in (\"0\", \"[]\"):\n        return None\n\n    # We know the user requested GPUs therefore if some of the\n    # requested GPUs are not available an exception is thrown.\n    gpus = _normalize_parse_gpu_string_input(gpus)\n    gpus = _normalize_parse_gpu_input_to_list(gpus, include_cuda=include_cuda, include_mps=include_mps)\n    if not gpus:\n        raise MisconfigurationException(\"GPUs requested but none are available.\")\n\n    if (\n        torch.distributed.is_available()\n        and torch.distributed.is_torchelastic_launched()\n        and len(gpus) != 1\n        and len(_get_all_available_gpus(include_cuda=include_cuda, include_mps=include_mps)) == 1\n    ):\n        # Omit sanity check on torchelastic because by default it shows one visible GPU per process\n        return gpus\n\n    # Check that GPUs are unique. Duplicate GPUs are not supported by the backend.\n    _check_unique(gpus)\n\n    return _sanitize_gpu_ids(gpus, include_cuda=include_cuda, include_mps=include_mps)\n\n\ndef _normalize_parse_gpu_string_input(s: Union[int, str, list[int]]) -> Union[int, list[int]]:\n    if not isinstance(s, str):","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L71-L107","documentation":"After normalizing the user's GPU request, Lightning found zero actually-available GPUs — the request could not be matched to any visible CUDA (or MPS) devices. Since the user explicitly asked for GPUs, Lightning raises MisconfigurationException rather than silently falling back to CPU.","triggerScenarios":"Setting `Trainer(gpus=...)`/`accelerator='gpu'` (or Fabric devices) on a machine with no visible CUDA devices: CUDA not installed, `CUDA_VISIBLE_DEVICES=''` or pointing at invalid IDs, driver mismatch, MPS requested but unavailable, or requesting specific GPU indices that don't exist.","commonSituations":"Running on CPU-only machines or containers without the NVIDIA runtime; `CUDA_VISIBLE_DEVICES` typo'd or emptied in slurm/docker; requesting GPU index 1 on a single-GPU node; torch installed without CUDA support (cpu-only wheel).","solutions":["Verify torch sees GPUs: `python -c \"import torch; print(torch.cuda.is_available(), torch.cuda.device_count())\"`; if False, install a CUDA-enabled torch build/driver.","Check and fix `CUDA_VISIBLE_DEVICES` (not empty, valid indices) in your shell/container/slurm job.","If requesting specific IDs, confirm they exist via `nvidia-smi` and are within range.","If the node truly has no GPU, switch the accelerator/devices to CPU."],"exampleFix":"# before\ntrainer = Trainer(accelerator=\"gpu\", devices=1)  # on a CPU-only machine\n\n# after\ntrainer = Trainer(accelerator=\"cpu\")  # or fix CUDA env / install cuda torch","handlingStrategy":"validation","validationCode":"import torch\n\nif not torch.cuda.is_available() or torch.cuda.device_count() == 0:\n    accelerator, devices = \"cpu\", None  # or fail fast with a clear message\ntrainer = Trainer(accelerator=accelerator, devices=devices)","typeGuard":"def gpus_available() -> bool:\n    import torch\n    return torch.cuda.is_available() and torch.cuda.device_count() > 0","tryCatchPattern":"from lightning.fabric.utilities import LightningEnvironment  # example\ntry:\n    trainer = Trainer(accelerator=\"gpu\", devices=1)\nexcept MisconfigurationException as e:\n    if \"GPUs requested but none are available\" in str(e):\n        trainer = Trainer(accelerator=\"cpu\")\n    else:\n        raise","preventionTips":["Check torch.cuda.is_available()/device_count() at startup before configuring devices.","Validate CUDA_VISIBLE_DEVICES in launch scripts and containers (nvidia-smi sanity check).","Install CUDA-enabled torch wheels on GPU nodes; verify driver compatibility after upgrades."],"tags":["pytorch-lightning","cuda","gpu","environment","device-availability"],"backgroundTag":"cuda-device-not-available","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}