{"record":{"id":"3f1039e519d1ba07","repo":"Lightning-AI/pytorch-lightning","slug":"cluster-environment-set-through-both-strategy-clas-3f1039","errorCode":null,"errorMessage":"cluster_environment set through both strategy class and plugins, choose one","messagePattern":"cluster_environment set through both strategy class and plugins, choose one","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":290,"sourceCode":"                if self._accelerator_flag != \"auto\":\n                    raise MisconfigurationException(\n                        \"accelerator set through both strategy class and accelerator flag, choose one\"\n                    )\n                self._accelerator_flag = self._strategy_flag._accelerator\n            if self._strategy_flag._precision_plugin:\n                # [RFC] handle precision plugin set up conflict?\n                if self._precision_plugin_flag:\n                    raise MisconfigurationException(\"precision set through both strategy class and plugins, choose one\")\n                self._precision_plugin_flag = self._strategy_flag._precision_plugin\n            if self._strategy_flag._checkpoint_io:\n                if self.checkpoint_io:\n                    raise MisconfigurationException(\n                        \"checkpoint_io set through both strategy class and plugins, choose one\"\n                    )\n                self.checkpoint_io = self._strategy_flag._checkpoint_io\n            if getattr(self._strategy_flag, \"cluster_environment\", None):\n                if self._cluster_environment_flag:\n                    raise MisconfigurationException(\n                        \"cluster_environment set through both strategy class and plugins, choose one\"\n                    )\n                self._cluster_environment_flag = getattr(self._strategy_flag, \"cluster_environment\")\n\n            if hasattr(self._strategy_flag, \"parallel_devices\") and self._strategy_flag.parallel_devices:\n                if self._strategy_flag.parallel_devices[0].type == \"cpu\":\n                    if self._accelerator_flag and self._accelerator_flag not in (\"auto\", \"cpu\"):\n                        raise MisconfigurationException(\n                            f\"CPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,\"\n                            f\" but accelerator set to {self._accelerator_flag}, please choose one device type\"\n                        )\n                    self._accelerator_flag = \"cpu\"\n                if self._strategy_flag.parallel_devices[0].type == \"cuda\":\n                    if self._accelerator_flag and self._accelerator_flag not in (\"auto\", \"cuda\", \"gpu\"):\n                        raise MisconfigurationException(\n                            f\"GPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,\"\n                            f\" but accelerator set to {self._accelerator_flag}, please choose one device type\"\n                        )","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L272-L308","documentation":"A strategy instance with a cluster_environment attached conflicts with an explicit Trainer(plugins=[<ClusterEnvironment>]) setting. The connector enforces single ownership of the cluster environment configuration.","triggerScenarios":"Trainer(strategy=DDPStrategy(cluster_environment=SLURMEnvironment()), plugins=[SLURMEnvironment()]) — any strategy with cluster_environment set plus a cluster env plugin/flag.","commonSituations":"HPC/SLURM setups where a shared strategy factory pre-binds SLURMEnvironment and the training script also adds it to plugins.","solutions":["Provide the cluster environment in only one location (strategy or plugins)","For SLURM, often neither is needed since it is auto-detected via env var detection"],"exampleFix":"# before\nstrategy = DDPStrategy(cluster_environment=SLURMEnvironment())\ntrainer = Trainer(strategy=strategy, plugins=[SLURMEnvironment()])\n# after\nstrategy = DDPStrategy()\ntrainer = Trainer(strategy=strategy, plugins=[SLURMEnvironment()])","handlingStrategy":"validation","validationCode":"from lightning.pytorch.plugins import ClusterEnvironment\nif isinstance(strategy, Strategy) and getattr(strategy, \"cluster_environment\", None):\n    plugins = [p for p in plugins if not isinstance(p, ClusterEnvironment)]\ntrainer = Trainer(strategy=strategy, plugins=plugins)","typeGuard":"def cluster_env_conflict(strategy, plugins) -> bool:\n    from lightning.pytorch.plugins import ClusterEnvironment\n    return bool(getattr(strategy, \"cluster_environment\", None)) and any(isinstance(p, ClusterEnvironment) for p in (plugins or []))","tryCatchPattern":null,"preventionTips":["Rely on auto-detection of SLURMEnvironment instead of manually passing it twice","Keep HPC-specific cluster env setup in one config module"],"tags":["pytorch-lightning","strategy","cluster-environment","conflicting-config"],"backgroundTag":"conflicting-config-options","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}