Lightning-AI/pytorch-lightning · error · ValueError
cluster_environment set through both strategy class and plug
Error message
cluster_environment set through both strategy class and plugins, choose one
What it means
A Strategy instance already carries a `cluster_environment` attribute, but a ClusterEnvironment plugin was also passed via `plugins` (setting _cluster_environment_flag). Fabric refuses to choose between two cluster environment specifications.
Source
Thrown at src/lightning/fabric/connector.py:278
# 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"
if self._strategy_flag.parallel_devices[0].type == "cuda":
if self._accelerator_flag and self._accelerator_flag not in ("auto", "cuda", "gpu"):
raise ValueError(
f"GPU 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 = "cuda"
self._parallel_devices = self._strategy_flag.parallel_devicesView on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the ClusterEnvironment plugin from `plugins` and keep it in the strategy
- Or construct the Strategy without cluster_environment and pass it via `plugins`
Example fix
# before strategy = DDPStrategy(cluster_environment=SLURMEnvironment()) fabric = Fabric(strategy=strategy, plugins=[SLURMEnvironment()]) # after strategy = DDPStrategy() fabric = Fabric(strategy=strategy, plugins=[SLURMEnvironment()])
Defensive patterns
Strategy: validation
Validate before calling
from lightning.fabric.plugins import ClusterEnvironment
if isinstance(strategy, Strategy) and getattr(strategy, "cluster_environment", None) and any(
isinstance(p, ClusterEnvironment) for p in plugins
):
raise SystemExit("cluster_environment defined in both strategy and plugins") Prevention
- In SLURM/K8s launchers, configure cluster environment in one place only
- Log which component supplies the cluster environment before constructing Fabric
When it happens
Trigger: Fabric(strategy=DDPStrategy(cluster_environment=SLURMEnvironment(...)), plugins=[SLURMEnvironment(...)]) — any strategy with a non-None cluster_environment plus a ClusterEnvironment plugin.
Common situations: SLURM/Kubernetes workflows where cluster env is baked into the strategy and later a plugin is added; reusable cluster-launch strategy objects combined with cluster-env plugins; migrating launcher scripts.
Related errors
- precision set through both strategy class and plugins, choos
- checkpoint_io set through both strategy class and plugins, c
- Received both `precision={precision_input}` and `plugins={se
- 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/b81f03039a8403dd.
Report an issue: GitHub.