Lightning-AI/pytorch-lightning · error · RuntimeError

No precision set

Error message

No precision set

What it means

After trying all precision configuration branches in _check_and_init_precision, none matched the current precision flag, so the connector has no Precision plugin to install and raises RuntimeError('No precision set'). It indicates an unrecognized precision value or a code path gap.

Source

Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:492

            return TransformerEnginePrecision(weights_dtype=torch.bfloat16)
        if self._precision_flag == "transformer-engine-float16":
            return TransformerEnginePrecision(weights_dtype=torch.float16)

        if self._precision_flag == "16-mixed" and self._accelerator_flag == "cpu":
            rank_zero_warn(
                "You passed `Trainer(accelerator='cpu', precision='16-mixed')` but AMP with fp16 is not supported on "
                "CPU. Using `precision='bf16-mixed'` instead."
            )
            self._precision_flag = "bf16-mixed"

        if self._precision_flag in ("16-mixed", "bf16-mixed"):
            rank_zero_info(
                f"Using {'16bit' if self._precision_flag == '16-mixed' else 'bfloat16'} Automatic Mixed Precision (AMP)"
            )
            device = self._accelerator_flag if self._accelerator_flag in ("cpu", "mps") else "cuda"
            return MixedPrecision(self._precision_flag, device)

        raise RuntimeError("No precision set")

    def _validate_precision_choice(self) -> None:
        """Validate the combination of choices for precision, AMP type, and accelerator."""
        if isinstance(self._precision_plugin_flag, BitsandbytesPrecision) and not isinstance(
            self.accelerator, CUDAAccelerator
        ):
            raise RuntimeError("Bitsandbytes is only supported on CUDA GPUs.")
        mp_precision_supported = ("32-true", "bf16-mixed", "bf16-true", "16-true")
        if (
            isinstance(self._strategy_flag, ModelParallelStrategy)
            and self._precision_flag not in mp_precision_supported
        ):
            raise ValueError(
                f"The `ModelParallelStrategy` does not support `Fabric(..., precision={self._precision_flag!r})`."
                f" Choose a different precision among: {', '.join(mp_precision_supported)}."
            )

    def _lazy_init_strategy(self) -> None:

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use a supported precision literal: '32-true', '16-mixed', 'bf16-mixed', 'bf16-true', '16-true', '64-true'
  2. For custom precision, pass a Precision plugin via plugins=[...] instead of a precision string
  3. Upgrade Lightning if using recently added precision names

Example fix

# before
trainer = Trainer(precision="bf16")
# after
trainer = Trainer(precision="bf16-mixed")
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {"32-true", "16-true", "bf16-true", "16-mixed", "bf16-mixed", "64-true"}
if precision not in SUPPORTED:
    precision = "32-true"  # or route to a custom Precision plugin
trainer = Trainer(precision=precision)

Type guard

def valid_precision(p) -> bool:
    return p in {"32-true", "16-true", "bf16-true", "16-mixed", "bf16-mixed", "64-true"}

Try / catch

try:
    trainer = Trainer(precision=precision)
except RuntimeError as e:
    if "No precision set" in str(e):
        trainer = Trainer(precision="32-true")
    else:
        raise

Prevention

When it happens

Trigger: Trainer(precision=<unsupported-value>) that matches neither 32-true, 16-true, bf16-true, 16-mixed, bf16-mixed, 64-true nor a plugin-based path; custom precision strings not handled by any branch.

Common situations: Typos in precision strings ('bf16', 'mixed' from older versions); custom precision plugin flows where the flag remains set but no branch handles it; version drift between Lightning releases changing accepted precision tokens.

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


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