Lightning-AI/pytorch-lightning · error · ValueError
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 (e.g. DDPStrategy) is passed to Fabric and that instance already carries an `_accelerator`, the connector adopts it — but only if the separate `accelerator=` flag is still the default "auto". Setting both a strategy with an embedded accelerator and an explicit `accelerator=` flag is ambiguous and rejected.
Source
Thrown at src/lightning/fabric/connector.py:265
raise ValueError(
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_input is not None:
raise ValueError(
f"Received both `precision={precision_input}` and `plugins={self._precision_instance}`. Choose one."
)
self._precision_input = "32-true" if precision_input is None else precision_input
# 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 isinstance(self._strategy_flag, Strategy):
if self._strategy_flag._accelerator:
if self._accelerator_flag != "auto":
raise ValueError("accelerator set through both strategy class and accelerator flag, choose one")
self._accelerator_flag = self._strategy_flag._accelerator
if self._strategy_flag._precision:
# [RFC] handle precision plugin set up conflict?
if self._precision_instance:
raise ValueError("precision set through both strategy class and plugins, choose one")
self._precision_instance = self._strategy_flag._precision
if self._strategy_flag._checkpoint_io:
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"):View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the `accelerator=` flag from Fabric(...) and let the strategy decide
- Or construct the Strategy without an accelerator (e.g. DDPStrategy() ) and pass accelerator= separately
Example fix
# before strategy = DDPStrategy(accelerator=CUDAAccelerator()) fabric = Fabric(strategy=strategy, accelerator="gpu") # after strategy = DDPStrategy(accelerator=CUDAAccelerator()) fabric = Fabric(strategy=strategy)
Defensive patterns
Strategy: validation
Validate before calling
from lightning.fabric.strategies import Strategy
if isinstance(strategy, Strategy) and strategy._accelerator and accelerator != "auto":
raise SystemExit("Strategy already has an accelerator; drop the accelerator flag") Prevention
- Configure the accelerator in exactly one place: the strategy or the Fabric flag
- When reusing strategy objects across scripts, construct them without accelerator/precision/checkpoint_io
When it happens
Trigger: strategy = DDPStrategy(accelerator=CUDAAccelerator()); Fabric(strategy=strategy, accelerator="cpu") — any Strategy instance whose _accelerator is set combined with accelerator != "auto".
Common situations: Reusing a preconfigured strategy object across scripts that also set accelerator="gpu"/"cpu"; refactoring older code where accelerator was set in both places; sharing strategy instances from a config factory.
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
- CPU parallel_devices set through {self._strategy_flag.__clas
- GPU 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/020dab32a7c2f8b4.
Report an issue: GitHub.