{"record":{"id":"e87cb8d166384f37","repo":"Lightning-AI/pytorch-lightning","slug":"precision-precision-r-is-not-supported-in-xla-e87cb8","errorCode":null,"errorMessage":"`precision={precision!r})` is not supported in XLA. `precision` must be one of: {supported_precision}.","messagePattern":"`precision=(.+?)\\)` is not supported in XLA\\. `precision` must be one of: (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/plugins/precision/xla.py","lineNumber":47,"sourceCode":"class XLAPrecision(Precision):\n    \"\"\"Plugin for training with XLA.\n\n    Args:\n        precision: Full precision (32-true) or half precision (16-true, bf16-true).\n\n    Raises:\n        ValueError:\n            If unsupported ``precision`` is provided.\n\n    \"\"\"\n\n    def __init__(self, precision: _PRECISION_INPUT = \"32-true\") -> None:\n        if not _XLA_AVAILABLE:\n            raise ModuleNotFoundError(str(_XLA_AVAILABLE))\n\n        supported_precision = get_args(_PRECISION_INPUT)\n        if precision not in supported_precision:\n            raise ValueError(\n                f\"`precision={precision!r})` is not supported in XLA.\"\n                f\" `precision` must be one of: {supported_precision}.\"\n            )\n        self.precision = precision\n\n        if precision == \"16-true\":\n            os.environ[\"XLA_USE_F16\"] = \"1\"\n            self._desired_dtype = torch.float16\n        elif precision == \"bf16-true\":\n            os.environ[\"XLA_USE_BF16\"] = \"1\"\n            self._desired_dtype = torch.bfloat16\n        else:\n            self._desired_dtype = torch.float32\n\n    @override\n    def optimizer_step(  # type: ignore[override]\n        self,\n        optimizer: Optimizable,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/plugins/precision/xla.py#L29-L65","documentation":"XLAPrecision only accepts the literal precision strings defined in _PRECISION_INPUT (e.g. '32-true', '16-true', 'bf16-true'). Passing any other value (such as '16-mixed', which XLA does not implement via this plugin) raises this ValueError in the constructor.","triggerScenarios":"Calling XLAPrecision(precision='16-mixed') or Trainer(precision='16-mixed', strategy='xla', ...) where the XLA plugin is selected; any string not in get_args(_PRECISION_INPUT).","commonSituations":"Copying a GPU training config using '16-mixed' or 'bf16-mixed' to a TPU run; assuming Lightning's mixed-precision strings work identically on XLA.","solutions":["Use a true-precision value supported on XLA: '32-true' or '16-true' (and bf16-true where supported)","Check the allowed set programmatically: from typing import get_args; get_args(XLAPrecision.__init__.__annotations__['precision'])","For mixed precision on TPU, rely on torch_xla's own AMP handling rather than this plugin's precision argument"],"exampleFix":"# before\nplugin = XLAPrecision(precision=\"16-mixed\")  # ValueError\n\n# after\nplugin = XLAPrecision(precision=\"16-true\")","handlingStrategy":"validation","validationCode":"from typing import get_args\nfrom lightning.pytorch.plugins.precision.xla import _PRECISION_INPUT\nassert precision in get_args(_PRECISION_INPUT), f\"bad precision {precision}\"","typeGuard":"def is_valid_xla_precision(p: str) -> bool:\n    from typing import get_args\n    from lightning.pytorch.plugins.precision.xla import _PRECISION_INPUT\n    return p in get_args(_PRECISION_INPUT)","tryCatchPattern":"try:\n    XLAPrecision(precision=p)\nexcept ValueError as e:\n    # log and fall back to a supported precision\n    XLAPrecision(precision=\"32-true\")","preventionTips":["Use only true-precision strings on XLA","Validate config values against get_args(_PRECISION_INPUT) at config load time","Keep TPU configs separate from GPU configs"],"tags":["xla","precision","invalid-argument","pytorch-lightning"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}