sgl-project/sglang · error · ValueError
tensor {name!r} matched no --diff-threshold pattern ({[rule.
Error message
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. What it means
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.
Source
Thrown at python/sglang/srt/debug_utils/comparator/threshold_dsl.py:56
)
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:
if re.fullmatch(rule.pattern, name):
return rule.predicate
raise ValueError(
f"tensor {name!r} matched no --diff-threshold pattern "
f"({[rule.pattern for rule in diff_threshold_rules]}); add a catch-all '.*' rule or a matching pattern."
)
@lru_cache(maxsize=None)
def parse_predicate(expr: str) -> CodeType:
try:
code = compile(expr, "<predicate>", "eval")
except SyntaxError as e:
raise ValueError(f"invalid predicate {expr!r}: {e}") from e
try:
eval(code, _EVAL_GLOBALS, dict(_DUMMY_ENV))
except Exception as e:
raise ValueError(
f"invalid predicate {expr!r}: {e}; allowed names are {ALLOWED_NAMES}."
) from e
return codeView on GitHub (pinned to 0132848349)
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
Example fix
# before
rules = parse_diff_threshold_rules(['blk0.*','rel <= 0.001'])
resolve_predicate('lm_head.weight', rules, 'rel <= 0.0085')
# after
rules = parse_diff_threshold_rules(['blk0.*','rel <= 0.001','.*','rel <= 0.0085']) Defensive patterns
Strategy: validation
Validate before calling
import re
def all_tensors_covered(names, rules):
return all(any(re.fullmatch(r.pattern, n) for r in rules) for n in names)
# or simply always append a catch-all:
raw += ['.*', 'rel <= 0.0085'] Try / catch
try:
pred = resolve_predicate(name, rules, default)
except ValueError as e:
pred = default # or log and skip tensor Prevention
- Always include a '.*' catch-all rule as the last pair
- Remember patterns use fullmatch, so prefix patterns need a trailing '.*'
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid dtype: {sampling_params.dtype}
- --diff-threshold with a single argument must be a float shor
- --diff-threshold expects a single float shorthand or (regex
- pattern must contain at least one token
- Both dtype and regex are set. Only dtype will be used. dtype
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/247386bfebeab4fa.
Report an issue: GitHub.