Lightning-AI/pytorch-lightning · error · ValueError

`precision={precision!r})` is not supported in FSDP. `precis

Error message

`precision={precision!r})` is not supported in FSDP. `precision` must be one of: {supported_precision}.

What it means

FSDPMixedPrecisionPlugin was constructed with a precision string outside the _PRECISION_INPUT union (e.g. '64-true' or a typo like '16_true'). Like the DeepSpeed plugin it validates eagerly because it must map precision to FSDP's MixedPrecision dtypes (param/reduce/buffer).

Source

Thrown at src/lightning/pytorch/plugins/precision/fsdp.py:56

    """Precision plugin for training with Fully Sharded Data Parallel (FSDP).

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    Args:
        precision: Full precision (32-true), half precision (16-true, bf16-true) or
            mixed precision (16-mixed, bf16-mixed).
        scaler: An optional :class:`torch.distributed.fsdp.sharded_grad_scaler.ShardedGradScaler` to use.

    Raises:
        ValueError:
            If unsupported ``precision`` is provided.

    """

    def __init__(self, precision: _PRECISION_INPUT, scaler: Optional["ShardedGradScaler"] = None) -> None:
        supported_precision = get_args(_PRECISION_INPUT)
        if precision not in supported_precision:
            raise ValueError(
                f"`precision={precision!r})` is not supported in FSDP."
                f" `precision` must be one of: {supported_precision}."
            )

        from torch.distributed.fsdp.sharded_grad_scaler import ShardedGradScaler

        if scaler is not None and self.precision != "16-mixed":
            raise ValueError(f"`precision={precision!r}` does not use a scaler, found {scaler}.")

        self.scaler = ShardedGradScaler() if scaler is None and precision == "16-mixed" else None
        self.precision = precision

        precision_to_type = {
            "bf16-mixed": torch.float32,
            "16-mixed": torch.float32,
            "bf16-true": torch.bfloat16,
            "16-true": torch.float16,
            "32-true": torch.float32,

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use a supported precision literal such as '16-mixed', 'bf16-mixed', '32-true', 'bf16-true', or '16-true'
  2. Copy the value from the error's supported_precision list
  3. Validate precision strings at config-load time with a lint/test

Example fix

# before
Trainer(strategy='fsdp', precision='bfloat16')

# after
Trainer(strategy='fsdp', precision='bf16-mixed')
Defensive patterns

Strategy: type-guard

Validate before calling

from typing import get_args
from lightning.pytorch.plugins.precision.fsdp import _PRECISION_INPUT

def valid_fsdp_precision(p: str) -> bool:
    return p in get_args(_PRECISION_INPUT)

assert valid_fsdp_precision(precision), f'{precision!r} unsupported for FSDP'

Type guard

from typing import get_args
from lightning.pytorch.plugins.precision.fsdp import _PRECISION_INPUT
SUPPORTED = set(get_args(_PRECISION_INPUT))

def is_supported_fsdp_precision(p: str) -> bool:
    return p in SUPPORTED

Prevention

When it happens

Trigger: FSDPMixedPrecisionPlugin(precision=<invalid>) or Trainer(strategy='fsdp', precision=<invalid string>); values not in get_args(_PRECISION_INPUT) fail the membership check.

Common situations: Typos when switching an FSDP run between precisions; passing torch dtypes instead of strings; configs written for older Lightning versions with different precision naming ('mixed16' vs '16-mixed').

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/a6b931c7da49b4d2. Report an issue: GitHub.