Lightning-AI/pytorch-lightning · error · TypeError
The XLA strategy can only work with the `XLAPrecision` plugi
Error message
The XLA strategy can only work with the `XLAPrecision` plugin, found {precision_plugin} What it means
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.
Source
Thrown at src/lightning/pytorch/strategies/single_xla.py:88
def checkpoint_io(self, io: Optional[CheckpointIO]) -> None:
if io is not None and not isinstance(io, (XLACheckpointIO, _WrappingCheckpointIO)):
raise TypeError(f"The XLA strategy can only work with the `XLACheckpointIO` plugin, found {io}")
self._checkpoint_io = io
@property
@override
def precision_plugin(self) -> XLAPrecision:
plugin = self._precision_plugin
if plugin is not None:
assert isinstance(plugin, XLAPrecision)
return plugin
return XLAPrecision()
@precision_plugin.setter
@override
def precision_plugin(self, precision_plugin: Optional[Precision]) -> None:
if precision_plugin is not None and not isinstance(precision_plugin, XLAPrecision):
raise TypeError(f"The XLA strategy can only work with the `XLAPrecision` plugin, found {precision_plugin}")
self._precision_plugin = precision_plugin
@override
def setup(self, trainer: "pl.Trainer") -> None:
if self.debug:
os.environ["PT_XLA_DEBUG"] = str(1)
assert self.accelerator is not None
self.accelerator.setup(trainer)
assert self.model is not None
self.precision_plugin.convert_module(self.model)
shared_params = find_shared_parameters(self.model)
self.model_to_device()
set_shared_parameters(self.model, shared_params)
self.model = self._setup_model(self.model)View on GitHub (pinned to 9fed5c27d2)
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
Example fix
# before from lightning.pytorch.plugins.precision import MixedPrecision strategy = SingleDeviceXLAStrategy(precision_plugin=MixedPrecision()) # after strategy = SingleDeviceXLAStrategy() trainer = L.Trainer(strategy=strategy, precision="16-mixed")
Defensive patterns
Strategy: type-guard
Validate before calling
assert precision_plugin is None or isinstance(precision_plugin, XLAPrecision)
Type guard
def is_valid_xla_precision(p) -> bool:
from lightning.pytorch.plugins.precision.xla import XLAPrecision
return p is None or isinstance(p, XLAPrecision) Prevention
- Configure precision via Trainer(precision=...) and let the strategy default to XLAPrecision
- Never pass MixedPrecision plugins to XLA strategies
When it happens
Trigger: 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.
Common situations: Setting 16-bit precision via a generic plugin object; sharing strategy kwargs across GPU and TPU runs.
Related errors
- The XLA strategy can only work with the `XLAPrecision` plugi
- The XLA strategy can only work with the `XLACheckpointIO` pl
- The XLA strategy can only work with the `XLACheckpointIO` pl
- To spawn processes with the `{type(self.strategy).__name__}`
- The `{type(self._strategy).__name__}` requires the model and
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/a121ccd6a74c6cb2.
Report an issue: GitHub.