[None][fix] Clamp very small non-zero temperature in SamplingParams#16287
[None][fix] Clamp very small non-zero temperature in SamplingParams#16287CodersAcademy006 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthrough
ChangesSampling temperature validation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/unittest/llmapi/test_sampling_params_temperature.py (2)
7-11: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winVerify the warning side effect.
This test confirms clamping but not the required warning emission. Add an assertion using the repository’s logger-capture mechanism that the warning is emitted before/while clamping.
As per path instructions, test coverage should explicitly validate the requested behavior.
🤖 Prompt for 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. In `@tests/unittest/llmapi/test_sampling_params_temperature.py` around lines 7 - 11, Add logger-capture assertions to test_tiny_temperature_is_clamped so it verifies that clamping a temperature below MIN_SAMPLING_TEMPERATURE emits the required warning. Keep the existing clamped-value assertion and use the repository’s established mechanism to inspect the warning message and severity.Source: Path instructions
14-15: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert greedy decoding, not only zero preservation.
The test name promises greedy behavior, but it only checks that
temperatureremains0.0. Also assert the resultingSamplingParamsinstance is recognized as greedy, or exercise the public path that consumes that state.As per path instructions, test coverage should explicitly validate the requested behavior.
🤖 Prompt for 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. In `@tests/unittest/llmapi/test_sampling_params_temperature.py` around lines 14 - 15, Update test_zero_temperature_stays_greedy to assert that the resulting SamplingParams instance is recognized as greedy, in addition to preserving the temperature value; use the class’s existing public greedy-state indicator or consumer path.Source: Path instructions
🤖 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.
Nitpick comments:
In `@tests/unittest/llmapi/test_sampling_params_temperature.py`:
- Around line 7-11: Add logger-capture assertions to
test_tiny_temperature_is_clamped so it verifies that clamping a temperature
below MIN_SAMPLING_TEMPERATURE emits the required warning. Keep the existing
clamped-value assertion and use the repository’s established mechanism to
inspect the warning message and severity.
- Around line 14-15: Update test_zero_temperature_stays_greedy to assert that
the resulting SamplingParams instance is recognized as greedy, in addition to
preserving the temperature value; use the class’s existing public greedy-state
indicator or consumer path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c9743aff-1472-41d1-b275-e296c385ee74
📒 Files selected for processing (2)
tensorrt_llm/sampling_params.pytests/unittest/llmapi/test_sampling_params_temperature.py
6c08736 to
feab6e0
Compare
SamplingParams only validated temperature >= 0, so a positive but tiny value like 1e-12 passed unchanged into the sampling backend, where logits / temperature overflows to inf/nan in float16/bfloat16 (a logit ~10 divided by 1e-12 is ~1e13, far past fp16's ~65504 max), giving undefined sampling. Add MIN_SAMPLING_TEMPERATURE (1e-2) and clamp 0 < temperature < MIN up to that floor (mirrors vLLM). Also reject non-finite temperature (inf/nan) up front, which the old >= 0 check let through. temperature == 0 (greedy) is left untouched and negatives are still rejected. Fixes NVIDIA#15715. Signed-off-by: Srijan Upadhyay <srjnupadhyay@gmail.com>
feab6e0 to
e2b6763
Compare
|
Noting there are two earlier PRs for this same issue — #15716 (from the reporter @chfeng-cs) and #16222 (@lonexreb) — so maintainers can pick whichever they prefer. This one aims to be the most complete of the three:
Happy to consolidate into one of the existing PRs instead if that's cleaner for review. |
Description
Fixes #15715.
SamplingParamsonly validatedtemperature >= 0, so a positive but tiny value like1e-12passed validation unchanged and was forwarded to the sampling backend. There,logits / temperatureoverflows toinf/naninfloat16/bfloat16(a typical logit ~10 divided by1e-12is ~1e13, far past fp16's ~65504 max), producing undefined sampling behavior.This clamps
0 < temperature < MIN_SAMPLING_TEMPERATURE(1e-2) up to that floor, mirroring the guard vLLM uses. Behavior for the other cases is unchanged:temperature = 0.00.0(greedy)0 < temperature < 1e-21e-2(with a warning)temperature >= 1e-2temperature < 0Test Coverage
Adds
tests/unittest/llmapi/test_sampling_params_temperature.pycovering the clamp, the greedy (0.0) passthrough, the boundary/normal passthrough, and the negative-rejection path.PR Checklist
[JIRA/NVBugs/GitHub issue/None][type] Summaryformatcc @chfeng-cs — thanks for the detailed report and repro.
Summary by CodeRabbit
Bug Fixes
Tests