Lightning-AI/pytorch-lightning · error · ValueError
GPU parallel_devices set through {self._strategy_flag.__clas
Error message
GPU parallel_devices set through {self._strategy_flag.__class__.__name__} class, but accelerator set to {self._accelerator_flag}, please choose one device type What it means
The passed Strategy instance has `parallel_devices` whose first device is a CUDA torch.device, but the `accelerator=` flag was explicitly set to something other than "auto", "cuda", or "gpu" (e.g. "cpu" or "tpu"). The connector refuses contradictory device specifications.
Source
Thrown at src/lightning/fabric/connector.py:291
if self.checkpoint_io:
raise ValueError("checkpoint_io set through both strategy class and plugins, choose one")
self.checkpoint_io = self._strategy_flag._checkpoint_io
if getattr(self._strategy_flag, "cluster_environment", None):
if self._cluster_environment_flag:
raise ValueError("cluster_environment set through both strategy class and plugins, choose one")
self._cluster_environment_flag = getattr(self._strategy_flag, "cluster_environment")
if hasattr(self._strategy_flag, "parallel_devices") and self._strategy_flag.parallel_devices:
if self._strategy_flag.parallel_devices[0].type == "cpu":
if self._accelerator_flag and self._accelerator_flag not in ("auto", "cpu"):
raise ValueError(
f"CPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,"
f" but accelerator set to {self._accelerator_flag}, please choose one device type"
)
self._accelerator_flag = "cpu"
if self._strategy_flag.parallel_devices[0].type == "cuda":
if self._accelerator_flag and self._accelerator_flag not in ("auto", "cuda", "gpu"):
raise ValueError(
f"GPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,"
f" but accelerator set to {self._accelerator_flag}, please choose one device type"
)
self._accelerator_flag = "cuda"
self._parallel_devices = self._strategy_flag.parallel_devices
def _check_device_config_and_set_final_flags(self, devices: Union[list[int], str, int], num_nodes: int) -> None:
if not isinstance(num_nodes, int) or num_nodes < 1:
raise ValueError(f"`num_nodes` must be a positive integer, but got {num_nodes}.")
self._num_nodes_flag = num_nodes
self._devices_flag = devices
if self._devices_flag in ([], 0, "0"):
accelerator_name = (
self._accelerator_flag.__class__.__qualname__
if isinstance(self._accelerator_flag, Accelerator)
else self._accelerator_flagView on GitHub (pinned to 9fed5c27d2)
Solutions
- Drop the accelerator flag (it will be inferred as "cuda" from parallel_devices)
- Or set parallel_devices to CPU devices if you truly want CPU execution
- Ensure the strategy object matches the target hardware when reusing configs
Example fix
# before
strategy = DDPStrategy(parallel_devices=[torch.device("cuda", 0)])
fabric = Fabric(strategy=strategy, accelerator="cpu")
# after
strategy = DDPStrategy(parallel_devices=[torch.device("cuda", 0)])
fabric = Fabric(strategy=strategy) Defensive patterns
Strategy: validation
Validate before calling
devs = getattr(strategy, "parallel_devices", None)
if devs and devs[0].type == "cuda" and accelerator not in (None, "auto", "cuda", "gpu"):
raise SystemExit(f"GPU parallel_devices conflict with accelerator={accelerator}") Prevention
- For CPU debug runs, rebuild the strategy with CPU parallel_devices instead of forcing accelerator="cpu"
- Derive the accelerator flag from the strategy's devices rather than hardcoding
When it happens
Trigger: DDPStrategy(parallel_devices=[torch.device("cuda", 0)]) with Fabric(strategy=strategy, accelerator="cpu") — a GPU-configured strategy combined with a non-GPU accelerator flag.
Common situations: Forcing accelerator="cpu" for debugging while the strategy was auto-built with CUDA devices; reusing a GPU strategy object in CPU-only tests; cluster scripts that override accelerator without rebuilding the strategy.
Related errors
- CPU parallel_devices set through {self._strategy_flag.__clas
- accelerator set through both strategy class and accelerator
- precision set through both strategy class and plugins, choos
- checkpoint_io set through both strategy class and plugins, c
- cluster_environment set through both strategy class and plug
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/a803aca4a212acd1.
Report an issue: GitHub.