{"record":{"id":"f8db2aece56fc017","repo":"Lightning-AI/pytorch-lightning","slug":"was-unable-to-infer-precision-type-received-self","errorCode":null,"errorMessage":"Was unable to infer precision type, received {self.precision!r}.","messagePattern":"Was unable to infer precision type, received (.+?)\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/plugins/precision/fsdp.py","lineNumber":111,"sourceCode":"\n    @property\n    def mixed_precision_config(self) -> \"TorchMixedPrecision\":\n        from torch.distributed.fsdp.fully_sharded_data_parallel import MixedPrecision as TorchMixedPrecision\n\n        if self.precision in (\"16-true\", \"bf16-true\"):\n            rank_zero_warn(\n                f\"FSDP with `{self.precision}` enables computation in lower precision. \"\n                \"FSDP will always retain a full-precision copy of the model parameters for sharding.\"\n            )\n\n        if self.precision in (\"16-true\", \"16-mixed\"):\n            param_dtype = reduce_dtype = buffer_dtype = torch.float16\n        elif self.precision in (\"bf16-true\", \"bf16-mixed\"):\n            param_dtype = reduce_dtype = buffer_dtype = torch.bfloat16\n        elif self.precision == \"32-true\":\n            param_dtype = reduce_dtype = buffer_dtype = torch.float32\n        else:\n            raise MisconfigurationException(f\"Was unable to infer precision type, received {self.precision!r}.\")\n\n        return TorchMixedPrecision(\n            param_dtype=param_dtype,\n            reduce_dtype=reduce_dtype,\n            buffer_dtype=buffer_dtype,\n        )\n\n    @override\n    def tensor_init_context(self) -> AbstractContextManager:\n        return _DtypeContextManager(self._desired_input_dtype)\n\n    @override\n    def module_init_context(self) -> AbstractContextManager:\n        return _DtypeContextManager(self._desired_input_dtype)\n\n    @override\n    def forward_context(self) -> AbstractContextManager:\n        if \"mixed\" in self.precision:","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/plugins/precision/fsdp.py#L93-L129","documentation":"The FSDPMixedPrecisionPlugin.mixed_precision_config property maps the precision string to FSDP MixedPrecision dtypes for 16-mixed/16-true/bf16-true/bf16-mixed/32-true; any other value that survived __init__ validation (or was set directly on the attribute afterwards) reaches the else branch and raises this MisconfigurationException.","triggerScenarios":"Setting plugin.precision directly to an unmapped value after construction (bypassing __init__ validation), subclassing FSDPMixedPrecisionPlugin without extending the dtype map, or a precision alias not covered by the if/elif chain in a fork/older version.","commonSituations":"Monkey-patching or mutating plugin.precision in experiments; custom precision plugins inheriting from the FSDP plugin without overriding mixed_precision_config; version drift where the union and the mapping get out of sync.","solutions":["Only use the supported precision literals and set them at construction time, not by mutating the attribute","If you subclass, override mixed_precision_config (or the dtype map) to cover your custom precision","Upgrade lightning so the validated union matches the mapping"],"exampleFix":"# before\nplugin = FSDPMixedPrecisionPlugin(precision='16-mixed')\nplugin.precision = 'tf32'  # later mutation -> raises in mixed_precision_config\n\n# after\nplugin = FSDPMixedPrecisionPlugin(precision='32-true')  # choose a supported value up front","handlingStrategy":"validation","validationCode":"SUPPORTED = {'16-mixed','16-true','bf16-mixed','bf16-true','32-true'}\n\ndef make_fsdp_plugin(precision):\n    assert precision in SUPPORTED, f'unsupported FSDP precision {precision!r}'\n    return FSDPMixedPrecisionPlugin(precision=precision)","typeGuard":"SUPPORTED = {'16-mixed','16-true','bf16-mixed','bf16-true','32-true'}\n\ndef has_dtype_mapping(precision: str) -> bool:\n    return precision in SUPPORTED","tryCatchPattern":null,"preventionTips":["Treat plugin.precision as immutable after construction","If subclassing FSDPMixedPrecisionPlugin, override mixed_precision_config for custom precisions"],"tags":["pytorch-lightning","fsdp","mixed-precision","dtype-mapping","config-validation"],"backgroundTag":"unsupported-precision-dtype-mapping","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}