Lightning-AI/pytorch-lightning · error · MisconfigurationException
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 Strategy instance passed via Trainer(strategy=...) may already have a precision plugin attached (strategy._precision_plugin). Setting Trainer(plugins=[<Precision>...]) at the same time is rejected to avoid two competing precision configurations.
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:280
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"
)
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(View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the precision plugin from the plugins list and let the strategy carry it
- Or unset precision on the strategy instance (pass precision=None / don't set it) and configure via plugins
Example fix
# before
strategy = DDPStrategy(precision_plugin=MixedPrecision("16-mixed"))
trainer = Trainer(strategy=strategy, plugins=[MixedPrecision("16-mixed")])
# after
strategy = DDPStrategy(precision_plugin=MixedPrecision("16-mixed"))
trainer = Trainer(strategy=strategy) Defensive patterns
Strategy: validation
Validate before calling
from lightning.pytorch.plugins import Precision
if isinstance(strategy, Strategy) and strategy._precision_plugin:
plugins = [p for p in plugins if not isinstance(p, Precision)]
trainer = Trainer(strategy=strategy, plugins=plugins) Type guard
def precision_double_config(strategy, plugins) -> bool:
from lightning.pytorch.plugins import Precision
return bool(getattr(strategy, "_precision_plugin", None)) and any(isinstance(p, Precision) for p in (plugins or [])) Prevention
- Attach precision to exactly one layer: Trainer flag, plugins, or strategy — never two
- When reusing strategy instances across runs, reset or rebuild them to avoid stale plugins
When it happens
Trigger: Trainer(strategy=strategy_with_precision, plugins=[MixedPrecision('16-mixed')]) where the strategy instance was constructed with a precision plugin.
Common situations: Shared strategy factories that pre-install precision; migrating from configs that specified precision on the strategy while keeping plugins entries.
Related errors
- Received both `precision={precision_flag}` and `plugins={sel
- accelerator set through both strategy class and accelerator
- checkpoint_io set through both strategy class and plugins, c
- cluster_environment set through both strategy class and plug
- precision set through both strategy class and plugins, choos
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/c0f882e5313d0cbe.
Report an issue: GitHub.