Lightning-AI/pytorch-lightning · error · ValueError
`precision={precision!r})` is not supported in DeepSpeed. `p
Error message
`precision={precision!r})` is not supported in DeepSpeed. `precision` must be one of: {supported_precision}. What it means
DeepSpeedPrecision.__init__ validates the precision argument against the _PRECISION_INPUT literal tuple (e.g. '32-true', '16-true', '16-mixed', 'bf16-true', 'bf16-mixed', '64-true'). If the string you passed is not one of those exact values (typo, old format like 'fp16', or None), it raises this ValueError before the plugin is constructed.
Source
Thrown at src/lightning/fabric/plugins/precision/deepspeed.py:49
class DeepSpeedPrecision(Precision):
"""Precision plugin for DeepSpeed integration.
Args:
precision: Full precision (32-true), half precision (16-true, bf16-true) or
mixed precision (16-mixed, bf16-mixed).
Raises:
ValueError:
If unsupported ``precision`` is provided.
"""
def __init__(self, precision: _PRECISION_INPUT) -> None:
supported_precision = get_args(_PRECISION_INPUT)
if precision not in supported_precision:
raise ValueError(
f"`precision={precision!r})` is not supported in DeepSpeed."
f" `precision` must be one of: {supported_precision}."
)
self.precision = precision
precision_to_type = {
"bf16-mixed": torch.bfloat16,
"16-mixed": torch.float16,
"bf16-true": torch.bfloat16,
"16-true": torch.float16,
"32-true": torch.float32,
}
self._desired_dtype = precision_to_type[self.precision]
@override
def convert_module(self, module: Module) -> Module:
if "true" in self.precision:
return module.to(dtype=self._desired_dtype)View on GitHub (pinned to 9fed5c27d2)
Solutions
- Set precision to one of the supported string literals, e.g. '16-mixed' for fp16 mixed precision or 'bf16-mixed' for bfloat16 mixed precision
- Check the value at runtime with typing.get_args(lightning.fabric.plugins.precision.deepspeed._PRECISION_INPUT) to see the exact accepted set
- If you take precision from user config, validate/normalize it before passing it to DeepSpeedStrategy/DeepSpeedPrecision
Example fix
// before strategy = DeepSpeedStrategy(precision="fp16") // after strategy = DeepSpeedStrategy(precision="16-mixed")
Defensive patterns
Strategy: validation
Validate before calling
from typing import get_args
from lightning.fabric.plugins.precision.deepspeed import _PRECISION_INPUT
assert precision in get_args(_PRECISION_INPUT), f"bad precision: {precision!r}" Type guard
from typing import get_args
from lightning.fabric.plugins.precision.deepspeed import _PRECISION_INPUT
def is_valid_precision(p: object) -> bool:
return isinstance(p, str) and p in get_args(_PRECISION_INPUT) Try / catch
try:
strategy = DeepSpeedStrategy(precision=precision)
except ValueError as e:
raise ConfigError(f"fix precision setting: {e}") from e Prevention
- Centralize precision strings in constants/enums in your config layer
- Add a config schema check for precision before building strategies
When it happens
Trigger: Creating DeepSpeedPrecision(precision=...) or DeepSpeedStrategy(precision=...) with a value outside get_args(_PRECISION_INPUT), e.g. 'fp16', 'bf16', 16, or 'mixed-precision'.
Common situations: Porting old PyTorch Lightning configs that used 'fp16'/'bf16' precision strings, or passing a raw torch.dtype instead of the string literal; typos like '16-mix'.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- `Trainer(strategy='deepspeed', precision={precision!r})` is
- `precision={precision!r})` is not supported in FSDP. `precis
- `precision={precision!r})` is not supported in XLA. `precisi
- `precision={precision!r})` is not supported in FSDP. `precis
- No precision set
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/124e0522c61656b9.
Report an issue: GitHub.