unslothai/unsloth · error · ValueError

llama-server flag '{flag}' requires an integer value

Error message

llama-server flag '{flag}' requires an integer value

What it means

ValueError from the context-flag override parser (llama_server_args.py:665, feeding resolve/parse of _CONTEXT_FLAGS like --ctx-size/-c): a context flag's value token is missing or not consumable — the next token after the flag is itself flag-shaped (_flag_name(tokens[i+1]) is not None) or the flag is the last token in the list, so no integer value can be read. Note '=' spelling takes the attached part and skips this branch; this raise is specifically the two-token form gone wrong.

Source

Thrown at studio/backend/core/inference/llama_server_args.py:665

    if not args:
        return None

    tokens = [str(a) for a in args]
    override: Optional[int] = None
    i, n = 0, len(tokens)
    while i < n:
        tok = tokens[i]
        flag = _flag_name(tok)
        if flag is None or flag not in _CONTEXT_FLAGS:
            i += 1
            continue

        if "=" in tok:
            raw_value = tok.split("=", 1)[1]
            i += 1
        else:
            if i + 1 >= n or _flag_name(tokens[i + 1]) is not None:
                raise ValueError(f"llama-server flag '{flag}' requires an integer value")
            raw_value = tokens[i + 1]
            i += 2

        try:
            value = int(str(raw_value).strip())
        except ValueError as exc:
            raise ValueError(f"llama-server flag '{flag}' requires an integer value") from exc
        if value < 0:
            raise ValueError(f"llama-server flag '{flag}' requires a non-negative integer value")
        override = value

    return override


def resolve_requested_ctx(args: Optional[Iterable[str]], fallback_n_ctx: int) -> int:
    """Return the context size load_model should treat as requested.

    Single source of truth for load_model's ctx-override conditional so

View on GitHub (pinned to 203007d190)

Solutions

  1. Put the integer right after the flag: '--ctx-size 4096'.
  2. For values that look like flags (negative numbers), use the attached form '--ctx-size=-1' — but note the separate non-negative check rejects negatives anyway, so pass unsigned values.
  3. If the flag is unwanted, delete both the flag and its value rather than just the value.

Example fix

# before
extra_args = ["--ctx-size", "--flash-attn", "on"]

# after
extra_args = ["--ctx-size", "4096", "--flash-attn", "on"]
Defensive patterns

Strategy: validation

Validate before calling

def context_flag_has_value(tokens):
    for i, t in enumerate(tokens):
        if _flag_name(t) in _CONTEXT_FLAGS and '=' not in t:
            if i + 1 >= len(tokens) or _flag_name(tokens[i+1]) is not None:
                return False
    return True

Type guard

def ctx_value_well_formed(tokens) -> bool:
    return context_flag_has_value(tokens)

Try / catch

try:
    validate_extra_args(args)
except ValueError as e:
    if "requires an integer value" in str(e):
        raise HTTPException(400, "context flag needs a plain integer value token")
    raise

Prevention

When it happens

Trigger: Passing '--ctx-size' as the last token, or '--ctx-size --flash-attn ...' where a flag immediately follows: the parser expects a bare value token next and finds none. Also '--ctx-size -1' — '-1' is flag-shaped to _flag_name, so it is rejected here rather than parsed.

Common situations: Hand-editing drops the value; a negative number written as a separate token (use '--ctx-size=-1' spelling or an unsigned value); ordering bugs in generated arg lists putting the flag's value before the flag.

Related errors


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