{"record":{"id":"362dedfe1897417a","repo":"Lightning-AI/pytorch-lightning","slug":"the-xla-strategy-can-only-work-with-the-xlaprecis-362ded","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/xla.py","lineNumber":102,"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    @property\n    @override\n    def root_device(self) -> torch.device:\n        if not self._launched:\n            raise RuntimeError(\"Accessing the XLA device before processes have spawned is not allowed.\")\n        import torch_xla.core.xla_model as xm\n\n        return xm.xla_device()\n\n    @property\n    @override\n    def global_rank(self) -> int:\n        return super().global_rank if self._launched else 0\n\n    @property\n    @override","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/xla.py#L84-L120","documentation":"XLAStrategy's precision_plugin setter only accepts XLAPrecision, since XLA mixed precision and optimizer handling are TPU-specific. Assigning any other Precision plugin raises TypeError.","triggerScenarios":"XLAStrategy(precision_plugin=MixedPrecision(...)) or strategy.precision_plugin = Precision() with the multi-device XLA strategy.","commonSituations":"Porting GPU training configs (MixedPrecision with native amp) to TPU; plugin lists in YAML/Sweeps that include precision plugins.","solutions":["Let the strategy default to XLAPrecision; express precision via Trainer(precision=...)","Subclass XLAPrecision if you need custom behavior","Drop precision_plugin from shared config files for TPU runs"],"exampleFix":"# before\nstrategy = XLAStrategy(precision_plugin=MixedPrecision())\n\n# after\nstrategy = XLAStrategy()\ntrainer = L.Trainer(strategy=strategy, precision=\"bf16-true\")","handlingStrategy":"type-guard","validationCode":"assert precision_plugin is None or isinstance(precision_plugin, XLAPrecision), \"XLA strategies require XLAPrecision\"","typeGuard":"def is_valid_xla_precision(p) -> bool:\n    return p is None or type(p).__name__ == \"XLAPrecision\"","tryCatchPattern":null,"preventionTips":["Express precision through Trainer(precision=...)","Build strategy kwargs per accelerator type"],"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"}