Reject repetition_penalty=0 in SamplingParams.verify()#24874
Merged
hnyls2002 merged 2 commits intoMay 13, 2026
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Ratish1
reviewed
May 10, 2026
Collaborator
Ratish1
left a comment
There was a problem hiding this comment.
Hey @RulinJuice , thanks for this fix. It makes sense to me. Can we also update the docs which documents the wrong range? . The file to update is docs/basic_usage/sampling_params.md
9ea7aa6 to
6edb77e
Compare
`repetition_penalty=0` is currently accepted by `verify()` (range `[0, 2]`), but the kernel `apply_scaling_penalties` divides logits by the penalty, so 0 produces inf -> NaN in the probability tensor and crashes every TP rank with a device-side assert in `process_batch_result_decode`. Tighten the range to `(0, 2]`, matching the strict-positive convention already used for `top_p`. Update the error message to mention the "1.0 = no penalty" convention. Update unit tests accordingly.
6edb77e to
6fc0bcd
Compare
Contributor
Author
|
Thanks @Ratish1! Updated docs/basic_usage/sampling_params.md to reflect the new range. |
Collaborator
|
/tag-and-rerun-ci |
Ratish1
approved these changes
May 10, 2026
hzh0425
approved these changes
May 11, 2026
Collaborator
hzh0425
left a comment
There was a problem hiding this comment.
LGTM, Let's move on the ci
Collaborator
|
/rerun-failed-ci |
SimonCao1207
pushed a commit
to SimonCao1207/sglang
that referenced
this pull request
May 13, 2026
…4874) Co-authored-by: RulinJuice <265952454+RulinJuice@users.noreply.github.com>
5 tasks
Shunkangz
pushed a commit
to Shunkangz/sglang
that referenced
this pull request
May 27, 2026
…4874) Co-authored-by: RulinJuice <265952454+RulinJuice@users.noreply.github.com>
zijiexia
added a commit
to zijiexia/sglang
that referenced
this pull request
Jun 4, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
SamplingParams.verify()currently acceptsrepetition_penalty=0.0(range[0, 2]), but the kernelapply_scaling_penaltiesinpython/sglang/srt/sampling/penaltylib/repetition_penalty.pydivides logits by the penalty:A penalty of
0producesinf->NaNin the probability tensor and crashes every TP rank with:This brings down the entire engine and requires a full restart.
Encountered in the wild when an upstream wrapper used
0.0as a fallback default for "the user didn't specify a value" (it should default to1.0, butverify()should also reject the invalid value early instead of letting it reach the GPU kernel and crash all TP ranks).Modifications
python/sglang/srt/sampling/sampling_params.py: tighten the valid range from[0, 2]to(0, 2], matching the strict-positive convention already used fortop_p(if not 0.0 < self.top_p <= 1.0). Update the error message to clarify the new range and the1.0 = no penaltyconvention.test/registered/unit/sampling/test_sampling_params.py:test_repetition_penalty_zero_raisescovering the new rejection.test_repetition_penalty_boundaries_valid(which asserted both0.0and2.0were valid) intotest_repetition_penalty_boundary_two_valid(only the2.0boundary remains valid).test_repetition_penalty_small_positive_validto confirm small but positive values like1e-3are still accepted.Accuracy Tests
N/A — input validation only, no kernel/forward change. The kernel itself is unmodified.
Speed Tests and Profiling
N/A — verify() runs once per request at submission time, not in the hot path.
Checklist