{"record":{"id":"d9f4abfc40570888","repo":"Lightning-AI/pytorch-lightning","slug":"accelerator-set-through-both-strategy-class-and-ac-d9f4ab","errorCode":null,"errorMessage":"accelerator set through both strategy class and accelerator flag, choose one","messagePattern":"accelerator set through both strategy class and accelerator flag, choose one","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":273,"sourceCode":"                    f\"Received multiple values for {', '.join(duplicated_plugin_key)} flags in `plugins`.\"\n                    \" Expected one value for each type at most.\"\n                )\n\n            if plugins_flags_types.get(Precision.__name__) and precision_flag is not None:\n                raise ValueError(\n                    f\"Received both `precision={precision_flag}` and `plugins={self._precision_plugin_flag}`.\"\n                    f\" Choose one.\"\n                )\n\n        self._precision_flag = \"32-true\" if precision_flag is None else precision_flag\n\n        # handle the case when the user passes in a strategy instance which has an accelerator, precision,\n        # checkpoint io or cluster env set up\n        # TODO: improve the error messages below\n        if self._strategy_flag and isinstance(self._strategy_flag, Strategy):\n            if self._strategy_flag._accelerator:\n                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\"","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L255-L291","documentation":"When a Strategy instance is passed to Trainer(strategy=...) that already carries an accelerator (strategy._accelerator set), you must not also set the accelerator flag explicitly. The connector refuses ambiguous accelerator ownership.","triggerScenarios":"strategy = DDPStrategy(accelerator=CUDAAccelerator()); Trainer(strategy=strategy, accelerator='gpu') — any non-'auto' accelerator flag combined with a pre-configured strategy instance.","commonSituations":"Reusing a pre-configured strategy object built by a shared factory and adding accelerator='gpu' at Trainer construction; copy-pasted configs from examples that build strategies manually.","solutions":["Drop the accelerator= argument from Trainer and let the strategy provide it","Or construct the strategy without an accelerator and pass accelerator= to Trainer"],"exampleFix":"# before\nstrategy = DDPStrategy(accelerator=CUDAAccelerator())\ntrainer = Trainer(strategy=strategy, accelerator=\"gpu\")\n# after\nstrategy = DDPStrategy()\ntrainer = Trainer(strategy=strategy, accelerator=\"gpu\")","handlingStrategy":"validation","validationCode":"if isinstance(strategy, Strategy) and strategy._accelerator and accelerator != \"auto\":\n    accelerator = \"auto\"  # or raise a clear config error early\ntrainer = Trainer(strategy=strategy, accelerator=accelerator)","typeGuard":"def strategy_accelerator_conflict(strategy, accelerator) -> bool:\n    from lightning.pytorch.strategies import Strategy\n    return isinstance(strategy, Strategy) and strategy._accelerator is not None and accelerator not in (None, \"auto\")","tryCatchPattern":null,"preventionTips":["Construct strategies without accelerators; let Trainer own accelerator selection","Centralize strategy construction so hidden state like _accelerator is known"],"tags":["pytorch-lightning","strategy","accelerator","conflicting-config"],"backgroundTag":"conflicting-config-options","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}