{"record":{"id":"247386bfebeab4fa","repo":"sgl-project/sglang","slug":"tensor-name-r-matched-no-diff-threshold-patter","errorCode":null,"errorMessage":"tensor {name!r} matched no --diff-threshold pattern ({[rule.pattern for rule in diff_threshold_rules]}); add a catch-all '.*' rule or a matching pattern.","messagePattern":"tensor (.+?) matched no --diff-threshold pattern \\((.+?)\\); add a catch-all '\\.\\*' rule or a matching pattern\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/comparator/threshold_dsl.py","lineNumber":56,"sourceCode":"        )\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,\n    diff_threshold_rules: Optional[list[DiffThresholdRule]],\n    *,\n    default_predicate: str,\n) -> str:\n    if not diff_threshold_rules:\n        return default_predicate\n    for rule in diff_threshold_rules:\n        if re.fullmatch(rule.pattern, name):\n            return rule.predicate\n    raise ValueError(\n        f\"tensor {name!r} matched no --diff-threshold pattern \"\n        f\"({[rule.pattern for rule in diff_threshold_rules]}); add a catch-all '.*' rule or a matching pattern.\"\n    )\n\n\n@lru_cache(maxsize=None)\ndef parse_predicate(expr: str) -> CodeType:\n    try:\n        code = compile(expr, \"<predicate>\", \"eval\")\n    except SyntaxError as e:\n        raise ValueError(f\"invalid predicate {expr!r}: {e}\") from e\n    try:\n        eval(code, _EVAL_GLOBALS, dict(_DUMMY_ENV))\n    except Exception as e:\n        raise ValueError(\n            f\"invalid predicate {expr!r}: {e}; allowed names are {ALLOWED_NAMES}.\"\n        ) from e\n    return code","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/comparator/threshold_dsl.py#L38-L74","documentation":"resolve_predicate raises this when a tensor name matches none of the provided --diff-threshold regex patterns (fullmatch semantics). The rule set is exhaustive by design: every tensor must resolve to a predicate, so either add a catch-all '.*' rule or a pattern that matches the failing tensor.","triggerScenarios":"Calling resolve_predicate(name, rules, ...) where every re.fullmatch(rule.pattern, name) fails, e.g. rules=['blk0.* ...'] but name='lm_head.weight' during compare_tensor_pair.","commonSituations":"User writes patterns covering only some tensor prefixes and the dump contains unexpected tensors (embeddings, lm_head, router weights) not covered; or patterns written for a different naming convention/model version.","solutions":["Append a catch-all pair: --diff-threshold '.*' 'rel <= <default>'","Add a pattern matching the reported tensor name (note: fullmatch, so 'blk0' won't match 'blk0.attn'; use 'blk0.*')","Print [r.pattern for r in rules] to debug which patterns are actually registered"],"exampleFix":"# before\nrules = parse_diff_threshold_rules(['blk0.*','rel <= 0.001'])\nresolve_predicate('lm_head.weight', rules, 'rel <= 0.0085')\n# after\nrules = parse_diff_threshold_rules(['blk0.*','rel <= 0.001','.*','rel <= 0.0085'])","handlingStrategy":"validation","validationCode":"import re\ndef all_tensors_covered(names, rules):\n    return all(any(re.fullmatch(r.pattern, n) for r in rules) for n in names)\n\n# or simply always append a catch-all:\nraw += ['.*', 'rel <= 0.0085']","typeGuard":null,"tryCatchPattern":"try:\n    pred = resolve_predicate(name, rules, default)\nexcept ValueError as e:\n    pred = default  # or log and skip tensor","preventionTips":["Always include a '.*' catch-all rule as the last pair","Remember patterns use fullmatch, so prefix patterns need a trailing '.*'"],"tags":["regex","threshold","pattern-matching","fullmatch"],"backgroundTag":"no-matching-pattern","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}