{"record":{"id":"2407671c8b2ffd04","repo":"sgl-project/sglang","slug":"diff-threshold-with-a-single-argument-must-be-a","errorCode":null,"errorMessage":"--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.","messagePattern":"--diff-threshold with a single argument must be a float shorthand \\(e\\.g\\. 0\\.0085\\); got (.+?)\\. For per-regex predicates pass \\(regex predicate\\) pairs\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/comparator/threshold_dsl.py","lineNumber":28,"sourceCode":"_DUMMY_ENV: dict[str, float] = {name: 1.0 for name in ALLOWED_NAMES}\n\n\n@dataclass(frozen=True)\nclass DiffThresholdRule:\n    pattern: str\n    predicate: str\n\n\ndef parse_diff_threshold_rules(\n    raw: Optional[list[str]], *, default_predicate: str\n) -> list[DiffThresholdRule]:\n    if not raw:\n        return [DiffThresholdRule(\".*\", default_predicate)]\n    if len(raw) == 1:\n        try:\n            value = float(raw[0])\n        except ValueError as e:\n            raise ValueError(\n                f\"--diff-threshold with a single argument must be a float shorthand \"\n                f\"(e.g. 0.0085); got {raw[0]!r}. For per-regex predicates pass \"\n                f\"(regex predicate) pairs.\"\n            ) from e\n        return [DiffThresholdRule(\".*\", f\"rel <= {value}\")]\n    if len(raw) % 2 != 0:\n        raise ValueError(\n            f\"--diff-threshold expects a single float shorthand or (regex predicate) \"\n            f\"pairs; got an odd number of arguments: {raw}\"\n        )\n    rules = [DiffThresholdRule(raw[i], raw[i + 1]) for i in range(0, len(raw), 2)]\n    for rule in rules:\n        parse_predicate(rule.predicate)\n    return rules\n\n\ndef resolve_predicate(\n    name: str,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/comparator/threshold_dsl.py#L10-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"User intends per-tensor rules but supplies a lone regex, or misspells a number ('0,0085', '1e'), or passes a bare predicate string.","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"],"exampleFix":"# before\nparse_diff_threshold_rules(['norm.*'])\n# after\nparse_diff_threshold_rules(['0.0085'])  # or\nparse_diff_threshold_rules(['norm.*', 'rel <= 0.001', '.*', 'rel <= 0.0085'])","handlingStrategy":"validation","validationCode":"def is_valid_shorthand(raw):\n    return len(raw) != 1 or _is_float(raw[0])\n\ndef _is_float(s):\n    try:\n        float(s); return True\n    except ValueError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    rules = parse_diff_threshold_rules(raw)\nexcept ValueError as e:\n    print(e); sys.exit(2)","preventionTips":["Always pass either a single float string or even-length (regex predicate) pairs","Validate numeric strings with float() in CLI wrappers before forwarding"],"tags":["cli","parsing","float","threshold"],"backgroundTag":"invalid-argument-format","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}