Repository navigation
fix: treat near-zero temperature as greedy and bound the seed (#167) - #184
Merged
Merged
Conversation
temperature=1e-40 turned logits into inf/NaN and seeds >= ~9.2e12 overflowed manual_seed(seed * 1_000_003 + p). Both passed SamplingParams validation, so the error surfaced inside the batcher's step() and poisoned the service. SamplingParams now treats temperature < 1e-5 as greedy and accepts seeds in [0, 2**32); the HTTP parser already maps the ValueError to a 400. Co-Authored-By: Claude Opus 5.5 <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.
Background
A request with
temperature=1e-40madeselect_tokendivide logits into inf/NaN, andmultinomialraised. A request withseed >= ~9.2e12overflowedmanual_seed(seed * 1_000_003 + p). Both values passedSamplingParamsvalidation and the HTTP parser, so the error came out of the batcher'sstep()and failed every in-flight request.Changes
opt_prime/opt_prime/accel/pd/contracts.py(SamplingParams):greedyis nowtemperature < 1e-5 or top_k == 1(vLLM uses the same epsilon). Seeds must be in[0, 2**32), soseed * 1_000_003 + positionstays well inside int64. Docstring updated.accel/serve/llmd.py) already turns aSamplingParamsValueError into a 400, so it needed no change. The other constructors (prefill_server.py, the RNGD batcher) go through the same validation.opt_prime/tests/test_pd_sampling.py::test_extreme_sampling_values_cannot_poison_a_batch: runs atemperature=1e-40request next to a normal sampled request in oneContinuousBatcher. Both finish, and the tiny-temperature output equals HF greedy.seed=2**62raises ValueError, and the stage service returns 400 for it.Verification
Python 3.10, torch 2.10.0+cu128, transformers 5.1.0, CPU plus one A100 (
CUDA_VISIBLE_DEVICES=1) on the RNGD+A100 host. Base: optimus-rm @253be20.RuntimeError: probability tensor contains either inf, nan or element < 0atsampling.py:25. Also checked on the unfixed code:SamplingParams(temperature=1.0, seed=2**62)is accepted andselect_tokenraisesValueError: Overflow when unpacking long long.tests/test_pd_sampling.py tests/test_pd_llmd.py tests/test_pd_batching.pygave 26 passed.opt_prime/:TORCH_DEVICE_BACKEND_AUTOLOAD=0 CUDA_VISIBLE_DEVICES=1 PYTHONPATH=$PWD python3 -m pytest -q tests): 400 passed, 23 skipped before; 401 passed, 23 skipped after.Compatibility and limits
(0, 1e-5)now decode greedily. They used to crash or behave as near-argmax anyway.2**32or more is now rejected with a 400 (OpenAI-style clients that send 64-bit seeds have to reduce them). The RNGD batcher already reduced its per-call seed mod2**31, so it behaves the same.Related Issue
Closes #167
🤖 Generated with Claude Code