sgl-project/sglang · error · ValueError
--diff-threshold with a single argument must be a float shor
Error message
--diff-threshold with a single argument must be a float shorthand (e.g. 0.0085); got {raw[0]!r}. For per-regex predicates pass (regex predicate) pairs. What it means
parse_diff_threshold_rules raises this when the --diff-threshold argument list has exactly one element that cannot be parsed as a float. The single-argument form is reserved for a float shorthand (e.g. 0.0085); per-regex predicates must be given as (regex predicate) pairs. The original float() ValueError is chained as the cause.
Source
Thrown at python/sglang/srt/debug_utils/comparator/threshold_dsl.py:28
_DUMMY_ENV: dict[str, float] = {name: 1.0 for name in ALLOWED_NAMES}
@dataclass(frozen=True)
class DiffThresholdRule:
pattern: str
predicate: str
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,View on GitHub (pinned to 0132848349)
Solutions
- If you want a global threshold, pass a valid float string, e.g. --diff-threshold 0.0085
- If you want per-pattern rules, pass an even-length list of (regex predicate) pairs, e.g. --diff-threshold '.*layer_0.*' 'rel <= 0.001' '.*' 'rel <= 0.0085'
- Fix locale/typo issues in the numeric string
Example fix
# before parse_diff_threshold_rules(['norm.*']) # after parse_diff_threshold_rules(['0.0085']) # or parse_diff_threshold_rules(['norm.*', 'rel <= 0.001', '.*', 'rel <= 0.0085'])
Defensive patterns
Strategy: validation
Validate before calling
def is_valid_shorthand(raw):
return len(raw) != 1 or _is_float(raw[0])
def _is_float(s):
try:
float(s); return True
except ValueError:
return False Try / catch
try:
rules = parse_diff_threshold_rules(raw)
except ValueError as e:
print(e); sys.exit(2) Prevention
- Always pass either a single float string or even-length (regex predicate) pairs
- Validate numeric strings with float() in CLI wrappers before forwarding
When it happens
Trigger: Calling parse_diff_threshold_rules(['relu']) or a CLI run with --diff-threshold abs-tol — a single non-numeric token instead of a float or pairs.
Common situations: User intends per-tensor rules but supplies a lone regex, or misspells a number ('0,0085', '1e'), or passes a bare predicate string.
Related errors
- --diff-threshold expects a single float shorthand or (regex
- This browser cannot encode H.264 MP4
- H.264 encoder did not return MP4 decoder config
- delta payload size mismatch: expected ${expectedSize}, got $
- Unknown serve backend {name!r}. Available values: {available
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2407671c8b2ffd04.
Report an issue: GitHub.