{"record":{"id":"ad8d9deab881ef6a","repo":"Lightning-AI/pytorch-lightning","slug":"the-fsdp-strategy-can-only-work-with-the-fsdpprec-ad8d9d","errorCode":null,"errorMessage":"The FSDP strategy can only work with the `FSDPPrecision` plugin, found {precision_plugin}","messagePattern":"The FSDP strategy can only work with the `FSDPPrecision` plugin, found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/strategies/fsdp.py","lineNumber":239,"sourceCode":"        plugin = self.precision_plugin\n        if isinstance(plugin, FSDPPrecision):\n            return plugin.mixed_precision_config\n        return None\n\n    @property\n    @override\n    def precision_plugin(self) -> FSDPPrecision:\n        plugin = self._precision_plugin\n        if plugin is not None:\n            assert isinstance(plugin, FSDPPrecision)\n            return plugin\n        return FSDPPrecision(\"32-true\")\n\n    @precision_plugin.setter\n    @override\n    def precision_plugin(self, precision_plugin: Optional[Precision]) -> None:\n        if precision_plugin is not None and not isinstance(precision_plugin, FSDPPrecision):\n            raise TypeError(\n                f\"The FSDP strategy can only work with the `FSDPPrecision` plugin, found {precision_plugin}\"\n            )\n        self._precision_plugin = precision_plugin\n\n    @property\n    @override\n    def distributed_sampler_kwargs(self) -> dict:\n        return {\"num_replicas\": (self.num_nodes * self.num_processes), \"rank\": self.global_rank}\n\n    @property\n    @override\n    def restore_checkpoint_after_setup(self) -> bool:\n        return True\n\n    @property\n    @override\n    def lightning_restore_optimizer(self) -> bool:\n        return False","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/fsdp.py#L221-L257","documentation":"FSDP requires its own precision plugin (FSDPPrecision) because mixed precision under FSDP is applied via wrapped policy dtypes, not the generic MixedPrecision plugin. The precision_plugin setter on FSDPStrategy rejects any non-None plugin that is not an FSDPPrecision instance with TypeError.","triggerScenarios":"Assigning `strategy.precision_plugin = MixedPrecision(...)` (or passing a non-FSDP precision plugin) to an FSDPStrategy/FSDPStrategy instance; typically via `Trainer(strategy=FSDPStrategy(...), plugins=[precision_plugin])` with a generic plugin.","commonSituations":"Copy-pasting `plugins=[MixedPrecision(precision=\"16-mixed\", device=\"cuda\")]` from a DDP example onto an FSDP run; wrapping FSDPStrategy with a custom Precision subclass.","solutions":["Use `FSDPPrecision` (e.g. `FSDPPrecision(\"16-mixed\")`) or simply set `Trainer(precision=\"16-mixed\")` and let FSDPStrategy build its plugin","Remove the generic MixedPrecision plugin from the plugins list when using FSDP","For custom precision logic, subclass FSDPPrecision instead of Precision"],"exampleFix":"# before\nfrom lightning.pytorch.plugins import MixedPrecision\ntrainer = Trainer(strategy=FSDPStrategy(), plugins=[MixedPrecision(precision=\"16-mixed\", device=\"cuda\")])\n\n# after\nfrom lightning.fabric.plugins.precision.fsdp import FSDPPrecision\ntrainer = Trainer(strategy=FSDPStrategy(), plugins=[FSDPPrecision(\"16-mixed\")])","handlingStrategy":"type-guard","validationCode":"from lightning.fabric.plugins.precision.fsdp import FSDPPrecision\nplugins = [p for p in plugins if not isinstance(p, Precision) or isinstance(p, FSDPPrecision)]\ntrainer = Trainer(strategy=FSDPStrategy(), plugins=plugins)","typeGuard":"from lightning.pytorch.plugins import Precision\nfrom lightning.fabric.plugins.precision.fsdp import FSDPPrecision\n\ndef is_fsdp_compatible(p: Precision) -> bool:\n    return p is None or isinstance(p, FSDPPrecision)","tryCatchPattern":null,"preventionTips":["Prefer Trainer(precision=\"16-mixed\") and let FSDPStrategy build FSDPPrecision","Never attach generic MixedPrecision plugins to FSDP runs"],"tags":["fsdp","precision-plugin","mixed-precision","type-mismatch"],"backgroundTag":"incompatible-precision-plugin","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}