Lightning-AI/pytorch-lightning · error · MisconfigurationException
Was unable to infer precision type, received {self.precision
Error message
Was unable to infer precision type, received {self.precision!r}. What it means
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.
Source
Thrown at src/lightning/pytorch/plugins/precision/fsdp.py:111
@property
def mixed_precision_config(self) -> "TorchMixedPrecision":
from torch.distributed.fsdp.fully_sharded_data_parallel import MixedPrecision as TorchMixedPrecision
if self.precision in ("16-true", "bf16-true"):
rank_zero_warn(
f"FSDP with `{self.precision}` enables computation in lower precision. "
"FSDP will always retain a full-precision copy of the model parameters for sharding."
)
if self.precision in ("16-true", "16-mixed"):
param_dtype = reduce_dtype = buffer_dtype = torch.float16
elif self.precision in ("bf16-true", "bf16-mixed"):
param_dtype = reduce_dtype = buffer_dtype = torch.bfloat16
elif self.precision == "32-true":
param_dtype = reduce_dtype = buffer_dtype = torch.float32
else:
raise MisconfigurationException(f"Was unable to infer precision type, received {self.precision!r}.")
return TorchMixedPrecision(
param_dtype=param_dtype,
reduce_dtype=reduce_dtype,
buffer_dtype=buffer_dtype,
)
@override
def tensor_init_context(self) -> AbstractContextManager:
return _DtypeContextManager(self._desired_input_dtype)
@override
def module_init_context(self) -> AbstractContextManager:
return _DtypeContextManager(self._desired_input_dtype)
@override
def forward_context(self) -> AbstractContextManager:
if "mixed" in self.precision:View on GitHub (pinned to 9fed5c27d2)
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
Example fix
# before plugin = FSDPMixedPrecisionPlugin(precision='16-mixed') plugin.precision = 'tf32' # later mutation -> raises in mixed_precision_config # after plugin = FSDPMixedPrecisionPlugin(precision='32-true') # choose a supported value up front
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'16-mixed','16-true','bf16-mixed','bf16-true','32-true'}
def make_fsdp_plugin(precision):
assert precision in SUPPORTED, f'unsupported FSDP precision {precision!r}'
return FSDPMixedPrecisionPlugin(precision=precision) Type guard
SUPPORTED = {'16-mixed','16-true','bf16-mixed','bf16-true','32-true'}
def has_dtype_mapping(precision: str) -> bool:
return precision in SUPPORTED Prevention
- Treat plugin.precision as immutable after construction
- If subclassing FSDPMixedPrecisionPlugin, override mixed_precision_config for custom precisions
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- `precision={precision!r})` is not supported in FSDP. `precis
- `precision={precision!r})` is not supported in FSDP. `precis
- `precision={precision!r}` does not use a scaler, found {scal
- The optimizer has references to the model's meta-device para
- `precision={precision!r})` is not supported in DeepSpeed. `p
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/f8db2aece56fc017.
Report an issue: GitHub.