[Fix] validate_buckets_rule: raise ValueError instead of assert False on malformed rules by mlleo · Pull Request #45598 · sgl-project/sglang · GitHub
Skip to content

[Fix] validate_buckets_rule: raise ValueError instead of assert False on malformed rules - #45598

Open
mlleo wants to merge 1 commit into
sgl-project:mainfrom
mlleo:fix/buckets-rule-assert-false
Open

mlleo wants to merge 1 commit into
sgl-project:mainfrom
mlleo:fix/buckets-rule-assert-false

Conversation

@mlleo

@mlleo mlleo commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Two of the numeric checks in validate_buckets_rule raise via assert False in the parse-failure branch. Under python -O asserts get stripped, so a malformed rule like ['tse', 'x', '2', '8'] passes validation silently instead of dying at startup with a useful error.

Repro (extract validate_buckets_rule and call it with the bad rule):

$ python -O repro.py        # unpatched
tse non-float middle: ACCEPTED (no exception)
custom non-numeric:   ACCEPTED (no exception)

Same run against the patched code:

$ python -O repro.py        # patched
tse non-float middle: rejected with ValueError: --generation-tokens-buckets TSE rule parameters must be: [...]
custom non-numeric:   rejected with ValueError: --generation-tokens-buckets custom rule bucket values must be numeric

Modifications

python/sglang/srt/arg_groups/validation_hook.py: replace the two assert False in the parse-failure branches with raise ValueError(...). Messages unchanged. This also matches the rest of the function, which raises ValueError for bad input everywhere else (grpc port, gc_threshold, kv canary, ...).

Verification

Verified locally with the repro above: under python -O both malformed shapes now raise ValueError, and valid rules (tse / default / custom) still pass. No new test file — the diff only changes how the two parse-failure branches report the error.

No GPU needed; this is server-args validation only.

Checklist

  • pre-commit ruff gates pass (F401/F821/F823/UP037 + format)
  • unit test added and passing (n/a: two-line error-reporting change)
  • docs: n/a, error message text unchanged
  • benchmarks: n/a, startup validation path only

CI States

Latest PR Test (Base): ❌ Run #40298619201
Latest PR Test (Extra): ❌ Run #40298619121
Latest PR Test (AMD ROCm 10): ❌ Run #40298619180

@github-actions

This comment has been minimized.

Under python -O, asserts are stripped, so the two malformed-rule guards in
validate_buckets_rule silently passed and the invalid bucket config was
accepted:

  $ python -O repro.py   # unpatched
  tse non-float middle: ACCEPTED (no exception)
  custom non-numeric:   ACCEPTED (no exception)

Both branches now raise ValueError, matching the surrounding validation
style in the same function and surviving -O:

  $ python -O repro.py   # patched
  tse non-float middle: rejected with ValueError
  custom non-numeric:   rejected with ValueError

Adds a registered CPU unit test pinning that malformed tse/custom rules
raise ValueError (not AssertionError, so the guard cannot be stripped by
-O) and that valid rules still pass.

Signed-off-by: jeongho shin <jh_leo.shin@samsung.com>
@mlleo
mlleo force-pushed the fix/buckets-rule-assert-false branch from c685591 to 4c97bcb Compare October 26, 2026 09:19
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@mlleo mlleo changed the title [BugFix] validate_buckets_rule: raise ValueError instead of assert False on malformed rules [Fix] validate_buckets_rule: raise ValueError instead of assert False on malformed rules Oct 26, 2026
@mlleo

mlleo commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant