Skip to content

fix(sglang): return log-probs before temperature scaling - #531

Draft
XiaoyuanWang111 wants to merge 1 commit into
alibaba:mainfrom
XiaoyuanWang111:fix/sglang_original_logprob
Draft

XiaoyuanWang111 wants to merge 1 commit into
alibaba:mainfrom
XiaoyuanWang111:fix/sglang_original_logprob

Conversation

@XiaoyuanWang111

Copy link
Copy Markdown

What

ROLL's trainer computes old_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 in its scheduler processes. With SGLang, old_log_probs - infer_logprobs therefore contains a temperature term, which train_infer_correction (IS weights, filters and the train_infer_kl / ratio metrics), the SAO ratio and on-policy distillation read as train-infer mismatch. Switching strategy_name from 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_logits and compute_train_infer_correction were 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].

T / top-p / top-k Backend mean abs gap train_infer_kl mean sequence ratio sequence filter keeps
0.99 / 0.99 / 100 (example recipes) vLLM 6.9e-7 -2.3e-10 1.000 100%
SGLang, main 1.4e-3 7.8e-6 0.956 100%
SGLang, this PR 1.3e-8 -1.5e-9 1.000 100%
0.95 / 0.7 / 50 (GeneratingArguments defaults) vLLM 4.9e-7 -3.3e-10 1.000 100%
SGLang, main 4.4e-3 4.1e-5 0.552 0 of 32
SGLang, this PR 1.2e-8 -1.7e-9 1.000 100%

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

  • New 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 its sampler.py reads. 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.
  • Unchanged on main and branch: the CPU CI paths (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) and tests/third_party/sglang (collection errors only where sglang is missing).
  • Not run: SGLang itself, GPU or NPU jobs.

Questions

  1. Is the train-infer correction meant to compare against the temperature-1 policy (this PR; the docs read that way) or against the sampling policy? The second would mean dividing the logits by temperature in op_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.
  2. SGLang 0.4.10.post2 still returns tempered values. Document it, warn, or leave it?
  3. Should vLLM's logprobs_mode="raw_logprobs" be set explicitly as well, so a future default change cannot reintroduce the gap?
  4. The zh-Hans copy of rollout_filtering.md is not updated here.

Related: #273 and #288, which added the train-infer correction; this keeps what it measures the same on both backends.

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.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

2 participants