{"record":{"id":"0cfc75d4ffebb27d","repo":"Lightning-AI/pytorch-lightning","slug":"passed-type-self-name-precision-precision","errorCode":null,"errorMessage":"Passed `{type(self).__name__}(precision={precision!r})`. Precision must be '16-mixed' or 'bf16-mixed'.","messagePattern":"Passed `(.+?)\\(precision=(.+?)\\)`\\. Precision must be '16-mixed' or 'bf16-mixed'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/precision/amp.py","lineNumber":46,"sourceCode":"\nclass MixedPrecision(Precision):\n    \"\"\"Plugin for Automatic Mixed Precision (AMP) training with ``torch.autocast``.\n\n    Args:\n        precision: Whether to use ``torch.float16`` (``'16-mixed'``) or ``torch.bfloat16`` (``'bf16-mixed'``).\n        device: The device for ``torch.autocast``.\n        scaler: An optional :class:`torch.cuda.amp.GradScaler` to use.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        precision: Literal[\"16-mixed\", \"bf16-mixed\"],\n        device: str,\n        scaler: Optional[\"torch.amp.GradScaler\"] = None,\n    ) -> None:\n        if precision not in (\"16-mixed\", \"bf16-mixed\"):\n            raise ValueError(\n                f\"Passed `{type(self).__name__}(precision={precision!r})`.\"\n                \" Precision must be '16-mixed' or 'bf16-mixed'.\"\n            )\n\n        self.precision = precision\n        if scaler is None and self.precision == \"16-mixed\":\n            scaler = torch.amp.GradScaler(device=device)\n        if scaler is not None and self.precision == \"bf16-mixed\":\n            raise ValueError(f\"`precision='bf16-mixed'` does not use a scaler, found {scaler}.\")\n        self.device = device\n        self.scaler = scaler\n\n        self._desired_input_dtype = torch.bfloat16 if self.precision == \"bf16-mixed\" else torch.float16\n\n    @override\n    def forward_context(self) -> AbstractContextManager:\n        return torch.autocast(self.device, dtype=self._desired_input_dtype)\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/precision/amp.py#L28-L64","documentation":"MixedPrecision.__init__ validates its precision argument: only the literal strings '16-mixed' and 'bf16-mixed' are accepted. Any other value (e.g. 'float16', 16, 'bf16') raises this ValueError.","triggerScenarios":"Constructing MixedPrecision(precision=...) with anything other than '16-mixed' or 'bf16-mixed'; often from Fabric(precision=...) which forwards the value.","commonSituations":"Migrating from older Lightning where precision was 'mixed'/'bf16', or passing raw dtypes/numbers like 16, 'fp16', 'bf16' instead of the mixed-precision literal names.","solutions":["Use precision='16-mixed' (fp16) or precision='bf16-mixed' (bf16)","For full (non-mixed) 16-bit precision use the MixedPrecisionLite/other precision plugins or pass a dtype instead of this plugin","Check the installed Lightning docs for accepted precision strings for your version"],"exampleFix":"# before\nfabric = Fabric(precision=\"bf16\")  # or \"mixed\"\n\n# after\nfabric = Fabric(precision=\"bf16-mixed\")","handlingStrategy":"validation","validationCode":"from typing import Literal\nMixedPrecisionValue = Literal[\"16-mixed\", \"bf16-mixed\"]\n\ndef check_precision(p: str) -> MixedPrecisionValue:\n    assert p in (\"16-mixed\", \"bf16-mixed\"), f\"invalid precision {p!r}\"\n    return p","typeGuard":"from typing import Literal, TypeGuard\nMixedPrecisionValue = Literal[\"16-mixed\", \"bf16-mixed\"]\ndef is_mixed_precision_value(p: str) -> TypeGuard[MixedPrecisionValue]:\n    return p in (\"16-mixed\", \"bf16-mixed\")","tryCatchPattern":null,"preventionTips":["Type precision config as Literal['16-mixed','bf16-mixed'] so mypy catches typos","Never pass raw dtypes or numbers as the precision string"],"tags":["amp","precision","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"}