unslothai/unsloth · error · ValueError

cfg_dropout must be between 0 and 1

Error message

cfg_dropout must be between 0 and 1

What it means

cfg_dropout is a probability and must lie in [0.0, 1.0]. Values outside that range are meaningless as dropout rates and are rejected before training starts.

Source

Thrown at studio/backend/core/training/diffusion_train_common.py:1166

                try:
                    flow_shift = float(flow_shift)
                except ValueError as exc:
                    raise ValueError(
                        f"flow_shift must be a positive number or 'auto', got {self.flow_shift!r}"
                    ) from exc
        if not isinstance(flow_shift, str):
            flow_shift = float(flow_shift)
            # isfinite as well as positive: JSON accepts 1e309, which floats to inf and would poison every sampled sigma while progress looks normal.
            if not math.isfinite(flow_shift) or flow_shift <= 0:
                raise ValueError(
                    "flow_shift must be a finite number > 0 (1.0 disables the shift), or 'auto'"
                )
        try:
            cfg_dropout = float(self.cfg_dropout or 0.0)
        except (TypeError, ValueError) as exc:
            raise ValueError(f"cfg_dropout must be a number, got {self.cfg_dropout!r}") from exc
        if not 0.0 <= cfg_dropout <= 1.0:
            raise ValueError("cfg_dropout must be between 0 and 1")
        weighting_scheme = str(self.weighting_scheme or "none").strip().lower()
        if weighting_scheme not in ("none", "bell"):
            raise ValueError("weighting_scheme must be one of none / bell")
        # A zero/negative gamma would zero out (or invert) the min-SNR weight and silently train on a degenerate loss; None is the documented disable.
        if self.snr_gamma is not None and float(self.snr_gamma) <= 0:
            raise ValueError("snr_gamma must be > 0, or null to disable min-SNR weighting")
        # learning_rate can arrive as a string ("1e-4") from the Studio config path, so coerce it before AdamW sees it.
        try:
            learning_rate = float(self.learning_rate)
        except (TypeError, ValueError) as exc:
            raise ValueError(f"learning_rate must be a number, got {self.learning_rate!r}") from exc
        if learning_rate <= 0:
            raise ValueError("learning_rate must be > 0")
        alpha = self.lora_alpha if self.lora_alpha is not None else self.lora_rank
        targets = tuple(self.lora_target_modules) or DEFAULT_LORA_TARGETS
        # A blank Hub token (the Studio default when none is configured) must load anonymously, not as an explicit empty credential.
        token = self.hf_token.strip() if isinstance(self.hf_token, str) else self.hf_token
        from core.inference.diffusion_families import (

View on GitHub (pinned to 203007d190)

Solutions

  1. Express the dropout as a fraction: 10% -> 0.1, 100% -> 1.0.
  2. If the value arrives as a percentage from a UI, divide by 100 before assigning.

Example fix

# before
cfg = DiffusionLoraConfig(cfg_dropout=10)
# after
cfg = DiffusionLoraConfig(cfg_dropout=0.10)
Defensive patterns

Strategy: validation

Validate before calling

def clamp_dropout(v, default=0.0):
    v = float(v) if v is not None else default
    if not 0.0 <= v <= 1.0:
        raise ValueError('cfg_dropout must be a fraction in [0,1]')
    return v

Prevention

When it happens

Trigger: cfg_dropout = 10 (percent instead of fraction), -0.1, or 1.5 in the training config.

Common situations: Users entering 10 for '10%'; percent/fraction confusion is by far the most common cause.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/b848a5463ead0b43. Report an issue: GitHub.