unslothai/unsloth · error · ValueError

cfg_dropout must be a number, got {self.cfg_dropout!r}

Error message

cfg_dropout must be a number, got {self.cfg_dropout!r}

What it means

cfg_dropout (probability of dropping CFG conditioning during training) is coerced with float(); if the value is neither numeric nor a numeric string, float() raises TypeError/ValueError and the config re-raises with the offending value shown. Note None defaults to 0.0 via 'or'.

Source

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

            flow_shift = flow_shift.strip().lower()
            if flow_shift != "auto":
                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.

View on GitHub (pinned to 203007d190)

Solutions

  1. Pass cfg_dropout as a number between 0 and 1 (e.g. 0.1), or None/omit it for 0.0.
  2. Convert percentage input to a fraction (10% -> 0.1) before building the config.
  3. Validate payload types at the API boundary before they reach DiffusionLoraConfig.

Example fix

# before
cfg = DiffusionLoraConfig(cfg_dropout='10%')
# after
cfg = DiffusionLoraConfig(cfg_dropout=0.1)
Defensive patterns

Strategy: validation

Validate before calling

def coerce_dropout(v):
    if v is None or v == '':
        return 0.0
    return float(v)  # let float() reject non-numeric input early

Type guard

def is_numeric(v) -> bool:
    if isinstance(v, bool):
        return False
    if isinstance(v, (int, float)):
        return True
    try:
        float(v)
        return True
    except (TypeError, ValueError):
        return False

Prevention

When it happens

Trigger: cfg_dropout set to a non-numeric value: a list, dict, or string like 'ten' or '5%'.

Common situations: Form or API payloads passing percent strings ('10%'), booleans passed as 'true'/'false' strings, or a nested object where a scalar was expected.

Related errors


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