Skip to content

feat(rl): add score-centered policy gradients - #4

Closed
nanjiangwill wants to merge 1130 commits into
mainfrom
feat/score-centering-paper
Closed

nanjiangwill wants to merge 1130 commits into
mainfrom
feat/score-centering-paper

Conversation

@nanjiangwill

Copy link
Copy Markdown
Owner

Summary

Implement score-centered policy gradients from arXiv:2609.20807 for FSDP and Megatron training.

At every generated-token prefix, the loss subtracts the sampler expectation of the trainer score. Sampler probabilities and optional importance weights are stop-gradient coefficients; gradients flow only through trainer log probabilities.

Dependencies

The branch includes bounded sampling-support replay. Exact-support score centering also uses sgl-project/sglang#40932, which returns the complete normalized sampler behavior distribution aligned with realized-support IDs.

Modes

  • Modeled tail: with untruncated, unit-temperature rollout sampling, retain the sampler's highest-probability head and model the omitted tail with the trainer distribution. --score-centering-head-size defaults to 128 and does not alter sampling.
  • Exact support: with rollout top-p/top-k, use every token in the realized sampling support. SGLang supplies normalized sampler probabilities q; Miles normalizes trainer logits p on the same replayed support.

Modeled-tail mode currently fails closed at non-unit temperature because SGLang's generic top-logprob response does not expose whether a remote server selected pre- or post-temperature semantics. Exact-support mode uses an explicit behavior-probability contract and supports any positive configured temperature.

Correctness boundaries

  • Reject unsupported sampler transforms, beam search, incompatible logprob recomputation, and objectives that do not share the required probability space.
  • Preserve singleton distributions for tool and environment tokens, giving them exactly zero policy gradient.
  • Compose with built-in TIS and IcePop weights using the paper's weighted-score extension.
  • Carry typed sampler metadata through direct rollout, sessions, object-store conversion, FSDP, Megatron, tensor parallelism, and context parallelism.
  • Avoid full-vocabulary materialization with sparse vocabulary-parallel logprob/autograd primitives.

Validation

  • 555 focused replay, score-centering, argument, rollout, session, transport, and sparse-math tests passed.
  • 56 FSDP and Megatron model/lifecycle tests passed with Megatron-LM on PYTHONPATH.
  • isort, Black, Ruff, documentation JSON validation, and git diff --check pass.

GPU end-to-end score-centering execution remains to be run.

alisonshao and others added 29 commits September 21, 2026 17:48
…ang checkout (radixark#3588)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
…s it (radixark#3587)

--fully-async selects FullyAsyncRolloutFn, but naming that class through
--rollout-function-path selected the same producer while leaving the mode off, so
the run skipped every --fully-async check (colocate, partial rollout, legacy
rollout v1, pause mode, multi-LoRA) and train.py's async-driver guard.

Normalize the path spelling into the flag before validation runs. Only the exact
class is recognized; a subclass still passes --fully-async explicitly.
…ion creation (radixark#3585)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
…#3)

* test(e2e): check sampling-support replay exactly under true-on-policy

The sampling-support replay e2e compares trainer and rollout log-probs
with a 0.03 tolerance on one rollout. Scoring over the full vocabulary
instead of the replayed support shifts the mean by only about 0.037 on
that data, so a milder top-p or a support wrong on some positions passes.

Under true-on-policy the actor's support-normalized log-probs equal the
rollout's exactly, and --ci-test asserts log_probs == rollout_log_probs
on every rollout. Megatron still rejects --true-on-policy-mode, so the
new test runs FSDP: Qwen3-0.6B, top-p 0.8 / top-k 32, 5 rollouts on two
GPUs. It uses gsm8k with 1024 response tokens because dapo at 128 tokens
truncates every response, which zeroes advantages and leaves the weights
nearly unchanged across steps. The Megatron test stays as a smoke run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): drop tolerance-based replay test and gate KL and grad norm

The Megatron sampling-support replay test checked log-probs only within
0.03 over one rollout. The true-on-policy FSDP test checks them exactly
on every rollout, so the Megatron test is removed.

The FSDP test now also declares history gates for train_rollout_kl,
ppo_kl and grad_norm. ppo_kl compares the training forward with
forward-only scoring, so it covers the replay mask on the loss path,
which the --ci-test log-prob assertion does not reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): drop the grad_norm gate from the true-on-policy replay test

grad_norm is not bit-reproducible across runs of this test and is 0 on
steps where every prompt's samples share one reward, so its band carries
little signal here. The exact log-prob and KL gates stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): note that exact replay log-probs hold through bf16 rounding

SGLang's fp32 log(p / sum_S p) and the trainer's masked bf16 log_softmax
can differ by one bf16 ulp on a small fraction of tokens. Record the
measured rate and why it rarely trips --ci-test next to the check, so a
nonzero train_rollout_logprob_abs_diff is not mistaken for a regression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.