unslothai/unsloth · error · ValueError

learning_rate must be parseable as float (got {v!r})

Error message

learning_rate must be parseable as float (got {v!r})

What it means

Raised by the _parse_lr parser when float(v) raises TypeError or ValueError, i.e. the supplied learning_rate is a string (or other object) that cannot be parsed as a float. The parser is deliberately lenient with numeric strings (it returns str(lr) for downstream call sites), but arbitrary strings like "fast" or "1e-" fail here. The message includes the repr of the offending value for debugging.

Source

Thrown at studio/backend/models/training.py:91

        # Require either IAM role auth or a full key pair so credentials are never half-configured.
        if not self.use_iam_role and not (self.access_key_id and self.secret_access_key):
            raise ValueError(
                "s3_config requires either use_iam_role=True or both "
                "access_key_id and secret_access_key"
            )
        return self


def _parse_lr(v: Any) -> float:
    """Parse learning_rate as a positive float strictly below _MAX_LR_VALUE."""
    if v is None:
        raise ValueError("learning_rate is required")
    if isinstance(v, bool):
        raise ValueError("learning_rate must be a number, not a bool")
    try:
        lr = float(v)
    except (TypeError, ValueError):
        raise ValueError(f"learning_rate must be parseable as float (got {v!r})")
    if not (lr > 0.0):
        raise ValueError(f"learning_rate must be > 0 (got {lr!r}); typical range is 1e-6 .. 1e-3")
    if lr >= _MAX_LR_VALUE:
        raise ValueError(
            f"learning_rate must be < 1.0 (got {lr!r}); values that large always diverge training"
        )
    return lr


class TrainingStartRequest(BaseModel):
    """Request schema for starting training"""

    model_name: str = Field(
        ..., description = "Model identifier (e.g., 'unsloth/llama-3-8b-bnb-4bit')"
    )
    project_name: Optional[str] = Field(
        None,
        max_length = 80,

View on GitHub (pinned to 203007d190)

Solutions

  1. Send a numeric or cleanly formatted numeric-string value, e.g. 0.0002 or "2e-5".
  2. Validate with a numeric regex or parseFloat + round-trip check in the client before submit.
  3. Strip whitespace and reject placeholder values like 'auto'/'default' in the request builder.

Example fix

// before
body = { ..., learning_rate: "auto" }
// after
body = { ..., learning_rate: 2e-5 }
Defensive patterns

Strategy: validation

Validate before calling

def lr_parses(body: dict) -> bool:
    v = body.get("learning_rate")
    if v is None or isinstance(v, bool):
        return False
    try:
        float(v)
        return True
    except (TypeError, ValueError):
        return False

Type guard

function lrParses(v: unknown): boolean {
  if (typeof v === 'number') return Number.isFinite(v);
  if (typeof v === 'string') return Number.isFinite(Number(v)) && v.trim() !== '';
  return false;
}

Prevention

When it happens

Trigger: POST a training start request with "learning_rate": "fast", "auto", "1e-", an empty string, or a dict/list. Numeric strings like "0.0002" or "2e-5" are fine; malformed numeric strings are not.

Common situations: UI free-text input for LR that is not validated; config values like "auto" or "default" intended to trigger server-side defaults that do not exist; locale-formatted numbers like "0,0002"; a prompt-style string field mistakenly mapped to learning_rate.

Related errors


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