Repository navigation
fix(sglang): return log-probs before temperature scaling - #531
Draft
XiaoyuanWang111 wants to merge 1 commit into
Draft
XiaoyuanWang111 wants to merge 1 commit into
XiaoyuanWang111 wants to merge 1 commit into
Conversation
ROLL's trainer recomputes log-probs from unscaled logits (op_compute_log_probs in the DeepSpeed, FSDP2 and Megatron strategies), and vLLM returns its default raw_logprobs, which are also taken before temperature. SGLang instead returns log softmax(logits / temperature) for the sampled token unless RETURN_ORIGINAL_LOGPROB (0.5.2) or SGLANG_RETURN_ORIGINAL_LOGPROB (0.5.4.post2 and later) is set. With SGLang, infer_logprobs therefore differ from old_log_probs by a temperature term that train_infer_correction (IS weight, filters and its always-on metrics), the SAO ratio and on-policy distillation read as train-infer mismatch, and switching the rollout backend changes what they measure. Set the variable in the patched _set_envs_and_config, which runs before SGLang spawns its scheduler processes, unless it is already set. SGLang 0.4.10.post2 has no such switch and is left unchanged.
|
|
This branch has not been deployed
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.
What
ROLL's trainer computes
old_log_probsfrom unscaled logits (op_compute_log_probsin the DeepSpeed, FSDP2 and Megatron strategies), and vLLM returns its defaultraw_logprobs, which are also taken before temperature. SGLang instead returnslog softmax(logits / temperature)for the sampled token unlessRETURN_ORIGINAL_LOGPROB(0.5.2) orSGLANG_RETURN_ORIGINAL_LOGPROB(0.5.4.post2 and later) is set in its scheduler processes. With SGLang,old_log_probs - infer_logprobstherefore contains a temperature term, whichtrain_infer_correction(IS weights, filters and thetrain_infer_kl/ ratio metrics), the SAO ratio and on-policy distillation read as train-infer mismatch. Switchingstrategy_namefrom vllm to sglang changes what these measure.This PR sets the variable in ROLL's patched
_set_envs_and_config(v052_patch,v054_patch), which SGLang calls before it spawns the scheduler processes, unless the user has already set it. Both backends then store the quantity the trainer recomputes, as the rollout filtering docs describe; the docs page now says so. SGLang 0.4.10.post2 has no such switch and is unchanged.Measurement
Qwen2.5-0.5B-Instruct, fp32 on CPU. vLLM 0.11.0 sampled 32 sequences per setting (about 155 tokens each); ROLL's own
log_probs_from_logitsandcompute_train_infer_correctionwere run on them. SGLang does not run on CPU, so its stored value was computed from the same fp32 logits with SGLang 0.5.2's formula (srt/layers/sampler.py), and the variable each checkout sets was read by calling its_set_envs_and_config. Gap = infer - old per token; sequence filter =TrainInferFilterConfig(agg_type="sequence")with its default band [0.8, 1.2].train_infer_klGeneratingArgumentsdefaults)With the same weights, SGLang on main shows a gap 2000 to 9000 times vLLM's, all of it temperature; with this PR both are at float rounding. On GPUs both engines add their own bf16 and kernel mismatch, which is what the correction is meant to see.
Tests
tests/third_party/sglang/test_original_logprob_env.py: loads ROLL's patch modules against stand-ins for the three SGLang modules they import (no SGLang or GPU needed) and checks that the right variable is set for 0.5.2, 0.5.4.post2 and 0.5.7, that an explicit setting is kept, and, when SGLang is installed, that the variable is the one itssampler.pyreads. Against main's code: 3 failed, 1 passed, 1 skipped (and the installed-name check fails with SGLang 0.5.2 or 0.5.7 files); on this branch all pass.tests/utils tests/datasets tests/agentic tests/test_ref_worker_type_consistency.py: 98 passed, 6 skipped, 6 failures that need external services or fail in a Ray worker on both) andtests/third_party/sglang(collection errors only where sglang is missing).Questions
temperatureinop_compute_log_probs,logprobs_mode="processed_logprobs"for vLLM, and replaying the top-p / top-k support: in the same run, without replay, the truncation term left a mean gap of 2.3e-3 per token at the recipes' settings and the default sequence filter would keep 6% of sequences.logprobs_mode="raw_logprobs"be set explicitly as well, so a future default change cannot reintroduce the gap?rollout_filtering.mdis not updated here.Related: #273 and #288, which added the train-infer correction; this keeps what it measures the same on both backends.