Lightning-AI/pytorch-lightning · error · MisconfigurationException
CPU parallel_devices set through {self._strategy_flag.__clas
Error message
CPU 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 CPU devices in parallel_devices, but the accelerator flag was set to a non-CPU accelerator (anything besides 'auto'/'cpu'). The connector refuses the CPU/GPU mismatch and asks you to pick one device type.
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:298
raise MisconfigurationException("precision set through both strategy class and plugins, choose one")
self._precision_plugin_flag = self._strategy_flag._precision_plugin
if self._strategy_flag._checkpoint_io:
if self.checkpoint_io:
raise MisconfigurationException(
"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 MisconfigurationException(
"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 MisconfigurationException(
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 MisconfigurationException(
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_nodesView on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the accelerator= flag or set it to 'cpu' to match the CPU parallel_devices
- Or set parallel_devices to actual cuda devices (torch.device('cuda', i)) when targeting GPU
Example fix
# before
strategy = DDPStrategy(parallel_devices=[torch.device("cpu")] * 4)
trainer = Trainer(strategy=strategy, accelerator="gpu")
# after
strategy = DDPStrategy(parallel_devices=[torch.device("cpu")] * 4)
trainer = Trainer(strategy=strategy, accelerator="cpu") Defensive patterns
Strategy: validation
Validate before calling
if hasattr(strategy, "parallel_devices") and strategy.parallel_devices:
dev_type = strategy.parallel_devices[0].type
if dev_type == "cpu" and accelerator not in (None, "auto", "cpu"):
accelerator = "cpu" # match devices, or fail fast with your own message Type guard
def cpu_devices_accelerator_mismatch(strategy, accelerator) -> bool:
devs = getattr(strategy, "parallel_devices", None)
return bool(devs) and devs[0].type == "cpu" and accelerator not in (None, "auto", "cpu") Prevention
- Derive parallel_devices from torch.device('cuda', i) only when GPUs are actually available
- Prefer auto devices and let Lightning pick, rather than hard-coding CPU device lists
When it happens
Trigger: DDPStrategy(parallel_devices=[torch.device('cpu')]*4) with Trainer(strategy=..., accelerator='gpu'). Also accelerator set to 'cuda', 'tpu', 'mps', etc.
Common situations: Hard-coded CPU device lists in shared strategy builders running on machines where accelerator='gpu' is the default; switching hardware without updating parallel_devices.
Related errors
- GPU parallel_devices set through {self._strategy_flag.__clas
- CPU parallel_devices set through {self._strategy_flag.__clas
- GPU parallel_devices set through {self._strategy_flag.__clas
- You selected an invalid strategy name: `strategy={strategy!r
- accelerator set through both strategy class and accelerator
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/911734f7d1156835.
Report an issue: GitHub.