Lightning-AI/pytorch-lightning · error · ValueError
precision set through both strategy class and plugins, choos
Error message
precision set through both strategy class and plugins, choose one
What it means
A passed-in Strategy instance already has a precision plugin (`_precision` is set), and a Precision plugin was also supplied via `plugins` (or precision resolution already produced one). Fabric refuses to silently pick one.
Source
Thrown at src/lightning/fabric/connector.py:270
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"):
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"View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the Precision plugin from `plugins` and keep precision inside the strategy
- Or construct the strategy without precision= and pass the Precision plugin via `plugins`
Example fix
# before
strategy = DDPStrategy(precision=MixedPrecision("16-mixed"))
fabric = Fabric(strategy=strategy, plugins=[MixedPrecision("16-mixed")])
# after
strategy = DDPStrategy(precision=MixedPrecision("16-mixed"))
fabric = Fabric(strategy=strategy) Defensive patterns
Strategy: validation
Validate before calling
from lightning.fabric.plugins import Precision
if isinstance(strategy, Strategy) and strategy._precision and any(isinstance(p, Precision) for p in plugins):
raise SystemExit("Precision defined both in strategy and plugins; keep one") Prevention
- DeepSpeedStrategy often bundles precision — check strategy._precision before adding Precision plugins
- Keep a single owner for precision configuration in your launch script
When it happens
Trigger: strategy = DDPStrategy(precision=MixedPrecision(...)); Fabric(strategy=strategy, plugins=[MixedPrecision(...)]) — strategy._precision non-None while self._precision_instance is set.
Common situations: Preconfigured strategy objects (DeepSpeedStrategy often bundles a precision plugin) combined with a plugins list; migrating Trainer setups where precision lived in the strategy; factory-created strategies reused with new plugin configs.
Related errors
- Received both `precision={precision_input}` and `plugins={se
- 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
- Received multiple values for {', '.join(duplicated_plugin_ke
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/b71a8c67c18eafba.
Report an issue: GitHub.