Lightning-AI/pytorch-lightning · error · MisconfigurationException
Received multiple values for {', '.join(duplicated_plugin_ke
Error message
Received multiple values for {', '.join(duplicated_plugin_key)} flags in `plugins`. Expected one value for each type at most. What it means
Each plugin type may appear at most once in Trainer(plugins=[...]). The connector counts instances per type and raises when any type key has more than one entry. This prevents ambiguity about which plugin instance should win.
Source
Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:254
self._cluster_environment_flag = plugin
plugins_flags_types[ClusterEnvironment.__name__] += 1
elif isinstance(plugin, LayerSync):
if sync_batchnorm and not isinstance(plugin, TorchSyncBatchNorm):
raise MisconfigurationException(
f"You set `Trainer(sync_batchnorm=True)` and provided a `{plugin.__class__.__name__}`"
" 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":View on GitHub (pinned to 9fed5c27d2)
Solutions
- Inspect the plugins list and keep exactly one instance of the duplicated type
- If you need combined behavior, wrap the two plugins in a single composite/custom plugin subclassing the same base
Example fix
# before
trainer = Trainer(plugins=[Precision16(), MixedPrecision('bf16-mixed')])
# after
trainer = Trainer(plugins=[MixedPrecision('bf16-mixed')]) Defensive patterns
Strategy: validation
Validate before calling
from collections import Counter
from lightning.pytorch.plugins import Precision, CheckpointIO, ClusterEnvironment, LayerSync
_KEYS = {Precision: "Precision", CheckpointIO: "CheckpointIO", ClusterEnvironment: "ClusterEnvironment", LayerSync: "LayerSync"}
counts = Counter(_KEYS[type(p)] for p in plugins)
assert all(v == 1 for v in counts.values()), f"duplicate plugins: {counts}" Type guard
def has_duplicate_plugin_types(plugins: list) -> bool:
seen = set()
for p in plugins:
k = type(p).__name__
if k in seen:
return True
seen.add(k)
return False Prevention
- Build plugins in one place per project; never concatenate plugin lists from multiple modules
- Deduplicate by plugin type before constructing the Trainer
When it happens
Trigger: Trainer(plugins=[PrecisionPluginA(), PrecisionPluginB()]) or two CheckpointIO/ClusterEnvironment/LayerSync instances in the same plugins list.
Common situations: Combining shared code snippets or copy-pasted configs that each add their own precision plugin; passing both a LayersSync/TorchSyncBatchNorm and enabling sync_batchnorm style setups multiple times.
Related errors
- You set `Trainer(sync_batchnorm=True)` and provided a `{plug
- Found invalid type for plugin {plugin}. Expected one of: Pre
- Device should be CPU, got {device} instead.
- `devices` selected with `CPUAccelerator` should be an int >
- Device should be CUDA, got {device} instead.
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/2e7a72a6c2b4ee8c.
Report an issue: GitHub.