{"record":{"id":"a121ccd6a74c6cb2","repo":"Lightning-AI/pytorch-lightning","slug":"the-xla-strategy-can-only-work-with-the-xlaprecis-a121cc","errorCode":null,"errorMessage":"The XLA strategy can only work with the `XLAPrecision` plugin, found {precision_plugin}","messagePattern":"The XLA strategy can only work with the `XLAPrecision` plugin, found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/strategies/single_xla.py","lineNumber":88,"sourceCode":"    def checkpoint_io(self, io: Optional[CheckpointIO]) -> None:\n        if io is not None and not isinstance(io, (XLACheckpointIO, _WrappingCheckpointIO)):\n            raise TypeError(f\"The XLA strategy can only work with the `XLACheckpointIO` plugin, found {io}\")\n        self._checkpoint_io = io\n\n    @property\n    @override\n    def precision_plugin(self) -> XLAPrecision:\n        plugin = self._precision_plugin\n        if plugin is not None:\n            assert isinstance(plugin, XLAPrecision)\n            return plugin\n        return XLAPrecision()\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, XLAPrecision):\n            raise TypeError(f\"The XLA strategy can only work with the `XLAPrecision` plugin, found {precision_plugin}\")\n        self._precision_plugin = precision_plugin\n\n    @override\n    def setup(self, trainer: \"pl.Trainer\") -> None:\n        if self.debug:\n            os.environ[\"PT_XLA_DEBUG\"] = str(1)\n\n        assert self.accelerator is not None\n        self.accelerator.setup(trainer)\n\n        assert self.model is not None\n        self.precision_plugin.convert_module(self.model)\n\n        shared_params = find_shared_parameters(self.model)\n        self.model_to_device()\n        set_shared_parameters(self.model, shared_params)\n\n        self.model = self._setup_model(self.model)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/single_xla.py#L70-L106","documentation":"The XLA strategies require the XLAPrecision precision plugin (it handles TPU-specific mixed precision via torch_xla). The precision_plugin setter rejects any other Precision implementation with TypeError.","triggerScenarios":"Assigning strategy.precision_plugin = MixedPrecision() or Precision(), or constructing SingleDeviceXLAStrategy/XLAStrategy with precision_plugin=<non-XLAPrecision plugin>; often from reusing a config built for CUDA strategies.","commonSituations":"Setting 16-bit precision via a generic plugin object; sharing strategy kwargs across GPU and TPU runs.","solutions":["Use XLAPrecision (default) — configure precision through Trainer(precision=...) instead of a custom plugin","If customizing, subclass XLAPrecision","Remove precision_plugin from the strategy kwargs"],"exampleFix":"# before\nfrom lightning.pytorch.plugins.precision import MixedPrecision\nstrategy = SingleDeviceXLAStrategy(precision_plugin=MixedPrecision())\n\n# after\nstrategy = SingleDeviceXLAStrategy()\ntrainer = L.Trainer(strategy=strategy, precision=\"16-mixed\")","handlingStrategy":"type-guard","validationCode":"assert precision_plugin is None or isinstance(precision_plugin, XLAPrecision)","typeGuard":"def is_valid_xla_precision(p) -> bool:\n    from lightning.pytorch.plugins.precision.xla import XLAPrecision\n    return p is None or isinstance(p, XLAPrecision)","tryCatchPattern":null,"preventionTips":["Configure precision via Trainer(precision=...) and let the strategy default to XLAPrecision","Never pass MixedPrecision plugins to XLA strategies"],"tags":["xla","precision-plugin","plugin-mismatch"],"backgroundTag":"plugin-type-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}