Lightning-AI/pytorch-lightning · error · ValueError
You selected an invalid accelerator name: `accelerator={acce
Error message
You selected an invalid accelerator name: `accelerator={accelerator!r}`. Available names are: auto, {', '.join(self._accelerator_types)}. What it means
AcceleratorConnector validates the `accelerator` argument against the known accelerator types plus 'auto'/'gpu'. Any unknown string (or non-Accelerator object) raises this ValueError listing valid names.
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:204
if isinstance(strategy, str):
strategy = strategy.lower()
self._strategy_flag = strategy
if strategy != "auto" and strategy not in self._registered_strategies and not isinstance(strategy, Strategy):
raise ValueError(
f"You selected an invalid strategy name: `strategy={strategy!r}`."
" It must be either a string or an instance of `lightning.pytorch.strategies.Strategy`."
" Example choices: auto, ddp, ddp_spawn, deepspeed, ..."
" Find a complete list of options in our documentation at https://lightning.ai"
)
if (
accelerator not in self._accelerator_types
and accelerator not in ("auto", "gpu")
and not isinstance(accelerator, Accelerator)
):
raise ValueError(
f"You selected an invalid accelerator name: `accelerator={accelerator!r}`."
f" Available names are: auto, {', '.join(self._accelerator_types)}."
)
# MPS accelerator is incompatible with DDP family of strategies. It supports single-device operation only.
is_ddp_str = isinstance(strategy, str) and "ddp" in strategy
is_deepspeed_str = isinstance(strategy, str) and "deepspeed" in strategy
is_parallel_strategy = isinstance(strategy, ParallelStrategy) or is_ddp_str or is_deepspeed_str
is_mps_accelerator = MPSAccelerator.is_available() and (
accelerator in ("mps", "auto", "gpu", None) or isinstance(accelerator, MPSAccelerator)
)
if is_mps_accelerator and is_parallel_strategy:
raise ValueError(
f"You set `strategy={strategy}` but strategies from the DDP family are not supported on the"
f" MPS accelerator. Either explicitly set `accelerator='cpu'` or change the strategy."
)
self._accelerator_flag = acceleratorView on GitHub (pinned to 9fed5c27d2)
Solutions
- Use 'auto', 'gpu', 'cpu', 'mps', 'tpu', 'hpu', etc. — specifically replace 'cuda' with 'gpu'.
- Or pass an Accelerator instance such as `lightning.pytorch.accelerators.CUDAAccelerator()`.
- Alternatively set `devices` and leave accelerator='auto' to let Lightning pick.
Example fix
# before trainer = Trainer(accelerator='cuda', devices=1) # after trainer = Trainer(accelerator='gpu', devices=1)
Defensive patterns
Strategy: validation
Validate before calling
VALID = {'auto', 'gpu', 'cpu', 'mps', 'tpu', 'hpu', 'cuda'} # normalize 'cuda'->'gpu'
accel = 'gpu' if accelerator == 'cuda' else accelerator
assert accel in {'auto','gpu','cpu','mps','tpu','hpu'} or hasattr(accel, 'setup'), f'bad accelerator {accelerator!r}' Type guard
from lightning.pytorch.accelerators import Accelerator
def is_valid_accelerator(a) -> bool:
return isinstance(a, Accelerator) or (isinstance(a, str) and a.lower() in {'auto','gpu','cpu','mps','tpu','hpu'}) Try / catch
except ValueError as e: if 'invalid accelerator name' in str(e): normalize ('cuda'->'gpu') and retry Trainer construction Prevention
- Map device strings from user/CLI input: cuda/gpu -> 'gpu', mps -> 'mps'.
- Prefer accelerator='auto' and only set devices.
When it happens
Trigger: `Trainer(accelerator='cuda')` (invalid — should be 'gpu'), `accelerator='tpu'` without XLA support, `accelerator=3` or other non-string non-Accelerator values.
Common situations: Coming from raw PyTorch/HuggingFace where 'cuda' is the device string; passing torch.device objects or integers; typos like 'gpu '/ 'cpu-'.
Understand the failure class
Background: "Invalid configuration value" and "Unsupported/Unknown setting value" errors: why libraries reject your config strings, numbers, and types — this error's family across 30 libraries.
Related errors
- You requested to find {num_devices} devices but this machine
- You selected an invalid strategy name: `strategy={strategy!r
- f"`gradient_clip_algorithm` {gradient_clip_algorithm} is inv
- Device should be CUDA, got {device} instead.
- You requested to find {num_devices} devices but there are no
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/2dcb9ad2fe209d53.
Report an issue: GitHub.