Lightning-AI/pytorch-lightning · critical · MisconfigurationException

GPUs requested but none are available.

Error message

GPUs requested but none are available.

What it means

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.

Source

Thrown at src/lightning/fabric/utilities/device_parser.py:89

    .. note::
        ``include_cuda`` and ``include_mps`` default to ``False`` so that you only
        have to specify which device type to use and all other devices are not disabled.

    """
    # Check that gpus param is None, Int, String or Sequence of Ints
    _check_data_type(gpus)

    # Handle the case when no GPUs are requested
    if gpus is None or (isinstance(gpus, int) and gpus == 0) or str(gpus).strip() in ("0", "[]"):
        return None

    # We know the user requested GPUs therefore if some of the
    # requested GPUs are not available an exception is thrown.
    gpus = _normalize_parse_gpu_string_input(gpus)
    gpus = _normalize_parse_gpu_input_to_list(gpus, include_cuda=include_cuda, include_mps=include_mps)
    if not gpus:
        raise MisconfigurationException("GPUs requested but none are available.")

    if (
        torch.distributed.is_available()
        and torch.distributed.is_torchelastic_launched()
        and len(gpus) != 1
        and len(_get_all_available_gpus(include_cuda=include_cuda, include_mps=include_mps)) == 1
    ):
        # Omit sanity check on torchelastic because by default it shows one visible GPU per process
        return gpus

    # Check that GPUs are unique. Duplicate GPUs are not supported by the backend.
    _check_unique(gpus)

    return _sanitize_gpu_ids(gpus, include_cuda=include_cuda, include_mps=include_mps)


def _normalize_parse_gpu_string_input(s: Union[int, str, list[int]]) -> Union[int, list[int]]:
    if not isinstance(s, str):

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. 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.
  2. Check and fix `CUDA_VISIBLE_DEVICES` (not empty, valid indices) in your shell/container/slurm job.
  3. If requesting specific IDs, confirm they exist via `nvidia-smi` and are within range.
  4. If the node truly has no GPU, switch the accelerator/devices to CPU.

Example fix

# before
trainer = Trainer(accelerator="gpu", devices=1)  # on a CPU-only machine

# after
trainer = Trainer(accelerator="cpu")  # or fix CUDA env / install cuda torch
Defensive patterns

Strategy: validation

Validate before calling

import torch

if not torch.cuda.is_available() or torch.cuda.device_count() == 0:
    accelerator, devices = "cpu", None  # or fail fast with a clear message
trainer = Trainer(accelerator=accelerator, devices=devices)

Type guard

def gpus_available() -> bool:
    import torch
    return torch.cuda.is_available() and torch.cuda.device_count() > 0

Try / catch

from lightning.fabric.utilities import LightningEnvironment  # example
try:
    trainer = Trainer(accelerator="gpu", devices=1)
except MisconfigurationException as e:
    if "GPUs requested but none are available" in str(e):
        trainer = Trainer(accelerator="cpu")
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/8172dc918799a19f. Report an issue: GitHub.