Repository navigation
[rl] SGLang generator: reject SGLANG_RETURN_ORIGINAL_LOGPROB - #6375
Conversation
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging -- this is a 7-line raise that turns an env var that silently breaks the importance ratio into a clear error at engine init, and it brings SGLang in line with the vLLM engine.
What this PR does. SGLangEngine.__init__ now raises ValueError when SGLang's SGLANG_RETURN_ORIGINAL_LOGPROB is on. With that variable set, SGLang returns log_softmax(logits) instead of the logprob of the temperature-scaled distribution it actually samples from. The trainer uses that value as the old-policy q in p / q.
Example. SamplingConfig(temperature=0.8), logits [2, 1, 0], token 0 sampled, SGLANG_RETURN_ORIGINAL_LOGPROB=1 exported (as slime/verl setup guides suggest):
main: q = softmax([2,1,0])[0] = 0.665 (trainer expects softmax([2,1,0]/0.8)[0] = 0.731)
ratio p/q off by ~10% on every token, no error
this PR: ValueError at SGLangEngine init
Must fix
- PR description: "Summary (human-written)" is empty. The author needs to fill it in before merge.
Details
- Gate. The problem is real on main. Nothing in
torchtitan/rl/reads this variable, and SGLang's default sampler honors it. This is the right layer.SGLangEngineruns SGLang'sSchedulerin-process (engine.py:117-124, no scheduler subprocesses), so the module constant imported atengine.py:26is the same value the sampler branches on in the same process. Config-time validation can't see the generator process's environment, so__init__is the earliest point that works. - Symmetry. The vLLM engine already pins
logprobs_mode="processed_logprobs"(vllm/engine.py:366), so this closes the same gap on the SGLang side. No one-sided design concern. - Batch-invariant mode. There,
TrainerLogprobsSampler(batch_invariance.py:56-60) overwritesnext_token_logprobsfromlogits / T, so the sampled-token logprob would already be correct. The env var would still affect top-k logprobs, which the planned score-centering work reads. Banning it unconditionally is simpler than exempting that mode, and it is the right call. - Upstream symbol.
sglang.srt.layers.sampler.SGLANG_RETURN_ORIGINAL_LOGPROBis a module-level constant, not a stable API. If SGLang renames or moves it, the import fails loudly at module load rather than silently skipping the check, which is the behavior we want. - Tests. No test needed. A test would only set an env var and re-read it.
- Overlap: #6356 (non-positive temperature) and #5760 (score centering) are complementary, not superseding.
Not verified: that the import resolves at the SGLang commit the README pins. SGLang is not installed in this runner, so this relies on the author's check against .venv-sglang.
1451dd8 to
4988ee4
Compare
4988ee4 to
d8473f2
Compare
felipemello1
left a comment
There was a problem hiding this comment.
it is unclear to me how SGLANG_RETURN_ORIGINAL_LOGPROB is defined. It seems to import from sglang itself? So it doesn't seem to be a config. Is it an envvar?
Summary (human-written)
Why
The trainer scores each token under
softmax(logits / T), the distribution the generator sampled from, andDAPOLoss/GRPOLossuse the generator's logprob as the old policy: the importance ratio isp / q. SGLang'sSGLANG_RETURN_ORIGINAL_LOGPROB=1(documented by other RL frameworks for their own needs) makes SGLang's sampler returnlog_softmax(logits), before temperature. Nothing in torchtitan checks it, so with the variable set every SGLang-generated ratio is silently wrong wheneverT != 1.Example.
SGLangEngine,SamplingConfig(temperature=0.8), a token with logits[2.0, 1.0, 0.0], sampled token 0:What changed
SGLangEngine.__init__raisesValueErrorifSGLANG_RETURN_ORIGINAL_LOGPROBis set. It readssglang.srt.layers.sampler.SGLANG_RETURN_ORIGINAL_LOGPROB, the module constant SGLang's sampler itself branches on, so the check can't disagree with SGLang's parsing of the variable.Alternatives considered
logits / T(as the batch-invariantTrainerLogprobsSamplerdoes): extra work on every decode step to support a setting nobody needs.Testing
.venv-sglang).pytest tests/rl/unit_tests/cpu: 741 passed, 7 skipped (GB300, CPU only).Known issues / follow-ups
First PR of the score centering stack (arXiv 2609.20807, takes over #5760): score centering also reads SGLang's top-k logprobs, which this variable would turn pre-temperature too. Training with temperature <= 0 is handled separately by #6356.