Lightning-AI/pytorch-lightning · error · ValueError
Received both `precision={precision_flag}` and `plugins={sel
Error message
Received both `precision={precision_flag}` and `plugins={self._precision_plugin_flag}`. Choose one. What it means
Precision can be configured either via the convenience Trainer(precision=...) flag or via a Precision plugin in plugins=[...], but not both. Note this specific check raises ValueError (not MisconfigurationException).
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:260
" plugin, but this is not allowed. Choose one or the other."
)
self._layer_sync = plugin
plugins_flags_types[TorchSyncBatchNorm.__name__] += 1
else:
raise MisconfigurationException(
f"Found invalid type for plugin {plugin}. Expected one of: Precision, "
"CheckpointIO, ClusterEnvironment, or LayerSync."
)
duplicated_plugin_key = [k for k, v in plugins_flags_types.items() if v > 1]
if duplicated_plugin_key:
raise MisconfigurationException(
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?View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the precision= flag and keep only the plugin (or vice versa)
- If the plugin was added by shared helper code, parameterize it so it is only added when no precision flag is set
Example fix
# before trainer = Trainer(precision="bf16-mixed", plugins=[MyPrecisionPlugin()]) # after trainer = Trainer(plugins=[MyPrecisionPlugin()])
Defensive patterns
Strategy: validation
Validate before calling
from lightning.pytorch.plugins import Precision
has_precision_plugin = any(isinstance(p, Precision) for p in plugins)
if has_precision_plugin:
precision = None # let the plugin win
trainer = Trainer(precision=precision, plugins=plugins) Type guard
def precision_conflict(precision, plugins) -> bool:
from lightning.pytorch.plugins import Precision
return precision is not None and any(isinstance(p, Precision) for p in (plugins or [])) Try / catch
try:
trainer = Trainer(precision=precision, plugins=plugins)
except ValueError as e:
if "Received both" in str(e):
trainer = Trainer(plugins=plugins)
else:
raise Prevention
- Choose one precision configuration mechanism per project and document it
- Guard shared config builders with an assert that precision flag and Precision plugin never coexist
When it happens
Trigger: Trainer(precision='16-mixed', plugins=[MixedPrecision('16-mixed')]) or any combination where a Precision instance is in plugins and precision flag is not None.
Common situations: Upgrading code that sets precision='16-mixed' while a tutorial/dependency also injects a precision plugin; refactors that add a custom precision plugin without removing the old precision flag.
Related errors
- precision set through both strategy class and plugins, choos
- Passed `{type(self).__name__}(precision={precision!r})`. Pre
- `precision='bf16-mixed'` does not use a scaler, found {scale
- `precision={precision!r})` is not supported in DeepSpeed. `p
- `precision={precision!r})` is not supported in FSDP. `precis
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/9a116601e5de808f.
Report an issue: GitHub.