{"record":{"id":"9a116601e5de808f","repo":"Lightning-AI/pytorch-lightning","slug":"received-both-precision-precision-flag-and-pl","errorCode":null,"errorMessage":"Received both `precision={precision_flag}` and `plugins={self._precision_plugin_flag}`. Choose one.","messagePattern":"Received both `precision=(.+?)` and `plugins=(.+?)`\\. Choose one\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":260,"sourceCode":"                            \" plugin, but this is not allowed. Choose one or the other.\"\n                        )\n                    self._layer_sync = plugin\n                    plugins_flags_types[TorchSyncBatchNorm.__name__] += 1\n                else:\n                    raise MisconfigurationException(\n                        f\"Found invalid type for plugin {plugin}. Expected one of: Precision, \"\n                        \"CheckpointIO, ClusterEnvironment, or LayerSync.\"\n                    )\n\n            duplicated_plugin_key = [k for k, v in plugins_flags_types.items() if v > 1]\n            if duplicated_plugin_key:\n                raise MisconfigurationException(\n                    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?","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L242-L278","documentation":"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).","triggerScenarios":"Trainer(precision='16-mixed', plugins=[MixedPrecision('16-mixed')]) or any combination where a Precision instance is in plugins and precision flag is not None.","commonSituations":"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.","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"],"exampleFix":"# before\ntrainer = Trainer(precision=\"bf16-mixed\", plugins=[MyPrecisionPlugin()])\n# after\ntrainer = Trainer(plugins=[MyPrecisionPlugin()])","handlingStrategy":"validation","validationCode":"from lightning.pytorch.plugins import Precision\nhas_precision_plugin = any(isinstance(p, Precision) for p in plugins)\nif has_precision_plugin:\n    precision = None  # let the plugin win\ntrainer = Trainer(precision=precision, plugins=plugins)","typeGuard":"def precision_conflict(precision, plugins) -> bool:\n    from lightning.pytorch.plugins import Precision\n    return precision is not None and any(isinstance(p, Precision) for p in (plugins or []))","tryCatchPattern":"try:\n    trainer = Trainer(precision=precision, plugins=plugins)\nexcept ValueError as e:\n    if \"Received both\" in str(e):\n        trainer = Trainer(plugins=plugins)\n    else:\n        raise","preventionTips":["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"],"tags":["pytorch-lightning","precision","conflicting-config"],"backgroundTag":"conflicting-config-options","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}