Skip to content

fix: treat near-zero temperature as greedy and bound the seed (#167) - #184

Merged
gspark-etri merged 2 commits into
optimus-rmfrom
fix/167-sampling-bounds
Oct 23, 2026
Merged

gspark-etri merged 2 commits into
optimus-rmfrom
fix/167-sampling-bounds

Conversation

@gspark-etri

Copy link
Copy Markdown
Collaborator

Background

A request with temperature=1e-40 made select_token divide logits into inf/NaN, and multinomial raised. A request with seed >= ~9.2e12 overflowed manual_seed(seed * 1_000_003 + p). Both values passed SamplingParams validation and the HTTP parser, so the error came out of the batcher's step() and failed every in-flight request.

Changes

  • opt_prime/opt_prime/accel/pd/contracts.py (SamplingParams): greedy is now temperature < 1e-5 or top_k == 1 (vLLM uses the same epsilon). Seeds must be in [0, 2**32), so seed * 1_000_003 + position stays well inside int64. Docstring updated.
  • The HTTP parser (accel/serve/llmd.py) already turns a SamplingParams ValueError 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 a temperature=1e-40 request next to a normal sampled request in one ContinuousBatcher. Both finish, and the tiny-temperature output equals HF greedy. seed=2**62 raises 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.

  • New test on the unfixed code: FAILED, RuntimeError: probability tensor contains either inf, nan or element < 0 at sampling.py:25. Also checked on the unfixed code: SamplingParams(temperature=1.0, seed=2**62) is accepted and select_token raises ValueError: Overflow when unpacking long long.
  • After the fix: tests/test_pd_sampling.py tests/test_pd_llmd.py tests/test_pd_batching.py gave 26 passed.
  • Whole suite (From 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

  • Temperatures in (0, 1e-5) now decode greedily. They used to crash or behave as near-argmax anyway.
  • A seed of 2**32 or 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 mod 2**31, so it behaves the same.

Related Issue

Closes #167

🤖 Generated with Claude Code

gspark-etri and others added 2 commits October 23, 2026 09:56
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>
@gspark-etri
gspark-etri merged commit c832062 into optimus-rm Oct 23, 2026
1 check passed
@gspark-etri
gspark-etri deleted the fix/167-sampling-bounds branch October 23, 2026 01:08
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