{"record":{"id":"dc53b9ab4a30f50c","repo":"Lightning-AI/pytorch-lightning","slug":"precision-precision-r-is-not-supported-in-xla","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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/precision/xla.py","lineNumber":44,"sourceCode":"\nclass 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) -> None:\n        if not _XLA_AVAILABLE:\n            raise ModuleNotFoundError(str(_XLA_AVAILABLE))\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(\n        self,\n        optimizer: Optimizable,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/precision/xla.py#L26-L62","documentation":"XLAPrecision.__init__ validates the precision string against the _PRECISION_INPUT literal tuple before doing anything else. Any value that is not an exact supported precision mode string raises this ValueError, listing the accepted values.","triggerScenarios":"XLAPrecision('fp16'), XLAPrecision('bf16'), XLAPrecision(16), or any other value not in get_args(_PRECISION_INPUT).","commonSituations":"Reusing precision strings from older Lightning ('fp16'/'bf16') in a Fabric/XLA setup; passing a torch dtype instead of the string literal.","solutions":["Use an exact literal such as 'bf16-mixed' or '16-mixed'","Inspect get_args from lightning.fabric.plugins.precision.xla to see the accepted values for your version","Validate precision strings once at config-load time"],"exampleFix":"# before\nprecision = XLAPrecision(\"bf16\")\n# after\nprecision = XLAPrecision(\"bf16-mixed\")","handlingStrategy":"validation","validationCode":"from typing import get_args\nfrom lightning.fabric.plugins.precision.xla import _PRECISION_INPUT\nassert precision in get_args(_PRECISION_INPUT), f\"bad precision: {precision!r}\"","typeGuard":"from typing import get_args\nfrom lightning.fabric.plugins.precision.xla import _PRECISION_INPUT\n\ndef is_valid_precision(p: object) -> bool:\n    return isinstance(p, str) and p in get_args(_PRECISION_INPUT)","tryCatchPattern":"try:\n    plugin = XLAPrecision(precision)\nexcept ValueError:\n    plugin = XLAPrecision(\"bf16-mixed\")","preventionTips":["Share one precision-string validation helper across strategies"],"tags":["xla","precision","config-validation","pytorch-lightning"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}