[#17158][fix] Reject NaN top_p, min_p and temperature in SamplingParams - #17159
[#17158][fix] Reject NaN top_p, min_p and temperature in SamplingParams#17159Yigtwxx wants to merge 2 commits into
Conversation
…ngParams The range checks for these three parameters were written in positive form, as `value < low or value > high`. Every comparison against NaN is False, so NaN passed validation and reached the sampling backend, which applies no guard of its own. Rewrite the three checks as negated range checks, which rejects NaN while leaving all other values unchanged. This is the form the neighbouring top_p_decay and top_p_min checks already use. Signed-off-by: Yigtwxx <yigiterdogan023@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
WalkthroughChangesSampling parameter validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unittest/llmapi/test_sampling_params.py`:
- Around line 118-121: Add tests/unittest/llmapi/test_sampling_params.py to both
the CI test-db lists and the QA test lists, using the existing list conventions
and preserving the newly added SamplingParams coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 613ef542-c6f1-435d-abf2-587812ac16e1
📒 Files selected for processing (2)
tensorrt_llm/sampling_params.pytests/unittest/llmapi/test_sampling_params.py
BowenFu
left a comment
There was a problem hiding this comment.
Verified the rewrite is exactly equivalent to the old checks for every non-NaN input, including the 0/1 boundaries and ±inf, so the only behavior change is that NaN now raises. test_sampling_params_accepts_in_range_values is the right guard against over-tightening.
Not blocking: tests/unittest/llmapi/test_sampling_params.py isn't in any test-db/ list, so these tests won't actually run in pre-merge L0. Worth registering.
…re-merge list The module was absent from every test list, so none of its cases -- including the NaN regression tests added in this branch -- ran in CI. Add it to the llmapi group of the A10 pre-merge stage, alongside the other CPU-only llmapi unit tests such as test_reasoning_parser.py. Signed-off-by: Yigtwxx <yigiterdogan023@gmail.com>
Description
Fixes #17158.
SamplingParams._validate()boundedtop_p,min_pandtemperaturewith positiverange checks of the form
value < low or value > high. Every comparison against NaNevaluates to
False, soSamplingParams(top_p=float("nan"))and itsmin_p/temperatureequivalents passed validation unchanged and were forwarded to the samplingbackend, which applies no guard of its own —
sampler_strategy.py:325-337divides thelogits by the raw temperature tensor and
ops/flashinfer.py:216hands it to the fusedsoftmax. The user got a request sampling from an undefined distribution rather than a
clear error at the API boundary.
The three checks are rewritten as negated range checks (
not 0 <= top_p <= 1,not 0 <= min_p <= 1,not temperature >= 0). This rejects NaN and leaves the acceptedset otherwise identical, with the existing error messages unchanged. It is also the form
the
top_p_decayandtop_p_minchecks a few lines below already use — those twoconsequently reject NaN today, which is what made the file inconsistent with itself.
Deliberately out of scope:
temperature=float("inf")is still accepted. It flattens thedistribution rather than corrupting it, so rejecting it would be a behavior change to
input that currently works. #15715, which asks for very small non-zero temperatures to be
clamped, is likewise a separate discussion about valid input and is not addressed here.
No API signature changes;
tests/unittest/api_stabilityis unaffected.Test Coverage
tests/unittest/llmapi/test_sampling_params.py(CPU-only, no model weights):test_sampling_params_rejects_nan— parametrized overtop_p,min_p,temperature;each must raise
ValueError. This is the regression guard: all three cases failagainst
main, where NaN is accepted, and pass with this change.test_sampling_params_rejects_out_of_range— the previously covered rejections(
-0.1,1.1,temperature=-1.0) still raise, confirming the rewrite did not narrowthe checks.
test_sampling_params_accepts_in_range_values— boundary and typical values (0.0,0.9,1.0,0.5,temperature=0.0,temperature=1.0) are still accepted and roundtrip unchanged.
Results: 16 cases, all passing on this branch. Against
mainwith only the test changesapplied, exactly the 3 NaN cases fail and the other 13 pass, so the accepted set is
otherwise unchanged.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.Dev Engineer Review
SamplingParams._validate()now rejectsNaNfortop_p,min_p, andtemperature.top_kvalidation is unchanged.Verdict: sufficient
QA Engineer Review
NaNrejection fortop_p,min_p, andtemperature.tests/integration/test_lists/test-db/l0_a10.yml.Verdict: sufficient