Lightning-AI/pytorch-lightning · error · MisconfigurationException
accelerator set through both strategy class and accelerator
Error message
accelerator set through both strategy class and accelerator flag, choose one
What it means
When a Strategy instance is passed to Trainer(strategy=...) that already carries an accelerator (strategy._accelerator set), you must not also set the accelerator flag explicitly. The connector refuses ambiguous accelerator ownership.
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:273
f"Received multiple values for {', '.join(duplicated_plugin_key)} flags in `plugins`."
" Expected one value for each type at most."
)
if plugins_flags_types.get(Precision.__name__) and precision_flag is not None:
raise ValueError(
f"Received both `precision={precision_flag}` and `plugins={self._precision_plugin_flag}`."
f" Choose one."
)
self._precision_flag = "32-true" if precision_flag is None else precision_flag
# handle the case when the user passes in a strategy instance which has an accelerator, precision,
# checkpoint io or cluster env set up
# TODO: improve the error messages below
if self._strategy_flag and isinstance(self._strategy_flag, Strategy):
if self._strategy_flag._accelerator:
if self._accelerator_flag != "auto":
raise MisconfigurationException(
"accelerator set through both strategy class and accelerator flag, choose one"
)
self._accelerator_flag = self._strategy_flag._accelerator
if self._strategy_flag._precision_plugin:
# [RFC] handle precision plugin set up conflict?
if self._precision_plugin_flag:
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"View on GitHub (pinned to 9fed5c27d2)
Solutions
- Drop the accelerator= argument from Trainer and let the strategy provide it
- Or construct the strategy without an accelerator and pass accelerator= to Trainer
Example fix
# before strategy = DDPStrategy(accelerator=CUDAAccelerator()) trainer = Trainer(strategy=strategy, accelerator="gpu") # after strategy = DDPStrategy() trainer = Trainer(strategy=strategy, accelerator="gpu")
Defensive patterns
Strategy: validation
Validate before calling
if isinstance(strategy, Strategy) and strategy._accelerator and accelerator != "auto":
accelerator = "auto" # or raise a clear config error early
trainer = Trainer(strategy=strategy, accelerator=accelerator) Type guard
def strategy_accelerator_conflict(strategy, accelerator) -> bool:
from lightning.pytorch.strategies import Strategy
return isinstance(strategy, Strategy) and strategy._accelerator is not None and accelerator not in (None, "auto") Prevention
- Construct strategies without accelerators; let Trainer own accelerator selection
- Centralize strategy construction so hidden state like _accelerator is known
When it happens
Trigger: strategy = DDPStrategy(accelerator=CUDAAccelerator()); Trainer(strategy=strategy, accelerator='gpu') — any non-'auto' accelerator flag combined with a pre-configured strategy instance.
Common situations: Reusing a pre-configured strategy object built by a shared factory and adding accelerator='gpu' at Trainer construction; copy-pasted configs from examples that build strategies manually.
Related errors
- 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
- accelerator set through both strategy class and accelerator
- CPU parallel_devices set through {self._strategy_flag.__clas
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/d9f4abfc40570888.
Report an issue: GitHub.