sgl-project/sglang · error · ValueError

--diff-threshold expects a single float shorthand or (regex

Error message

--diff-threshold expects a single float shorthand or (regex predicate) pairs; got an odd number of arguments: {raw}

What it means

parse_diff_threshold_rules raises this when the --diff-threshold argument list has an odd number of elements (>1). Per-regex rules are consumed as (regex predicate) pairs, so any leftover token means a regex is missing its predicate or vice versa.

Source

Thrown at python/sglang/srt/debug_utils/comparator/threshold_dsl.py:35


def parse_diff_threshold_rules(
    raw: Optional[list[str]], *, default_predicate: str
) -> list[DiffThresholdRule]:
    if not raw:
        return [DiffThresholdRule(".*", default_predicate)]
    if len(raw) == 1:
        try:
            value = float(raw[0])
        except ValueError as e:
            raise ValueError(
                f"--diff-threshold with a single argument must be a float shorthand "
                f"(e.g. 0.0085); got {raw[0]!r}. For per-regex predicates pass "
                f"(regex predicate) pairs."
            ) from e
        return [DiffThresholdRule(".*", f"rel <= {value}")]
    if len(raw) % 2 != 0:
        raise ValueError(
            f"--diff-threshold expects a single float shorthand or (regex predicate) "
            f"pairs; got an odd number of arguments: {raw}"
        )
    rules = [DiffThresholdRule(raw[i], raw[i + 1]) for i in range(0, len(raw), 2)]
    for rule in rules:
        parse_predicate(rule.predicate)
    return rules


def resolve_predicate(
    name: str,
    diff_threshold_rules: Optional[list[DiffThresholdRule]],
    *,
    default_predicate: str,
) -> str:
    if not diff_threshold_rules:
        return default_predicate
    for rule in diff_threshold_rules:

View on GitHub (pinned to 0132848349)

Solutions

  1. Add the missing predicate (or remove the dangling regex) so the list has an even length
  2. Verify shell quoting: each regex and each predicate must arrive as separate argv entries
  3. Pre-validate with a simple len(raw) % 2 == 0 check in wrapper scripts

Example fix

# before
parse_diff_threshold_rules(['blk0.*','rel <= 0.01','blk1.*'])
# after
parse_diff_threshold_rules(['blk0.*','rel <= 0.01','blk1.*','rel <= 0.01'])
Defensive patterns

Strategy: validation

Validate before calling

if len(raw) > 1 and len(raw) % 2 != 0:
    raise SystemExit(f'odd number of --diff-threshold args: {raw}')

Try / catch

try:
    rules = parse_diff_threshold_rules(raw)
except ValueError as e:
    print(e); sys.exit(2)

Prevention

When it happens

Trigger: Calling parse_diff_threshold_rules(['a.*','rel <= 1','b.*']) — three tokens — or a CLI invocation where one pair member was forgotten or a space split a pair incorrectly.

Common situations: Forgetting the predicate half of a pair, shell quoting dropping an argument, or appending an extra flag value to the same list.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/e717286d670ad0b7. Report an issue: GitHub.