Repository navigation
feat(loss): add score centering with sampler top-k capture - #4818
Conversation
|
Comparison with ertkonuk / Tugrul Konuk's original two commits: fd4681687 — sampler top-k capture and 3e63b6d — score-centering loss. The current PR revision is f52f93fb7. The original commits already provide the SingleController/V2 token-capture path, CPU/data-plane transport, ordinary TP/CP trainer gathering, and an additive score-centering correction. This PR retains those foundations and extends them:
Validation at this revision: 34 focused CPU cases pass with heavyweight runtime imports isolated; real two-process Gloo checks pass for packed TP values/gradients and CP forward reconstruction, including actual packed-loss preparation. Functional-launch configurations and metric checks are validated, but the GPU smoke, CP backward, full Ray/vLLM integration, and convergence have not run locally. Full typechecking remains blocked by the uninitialized Automodel submodule. Remaining limits: sequence-level IS / |
guyueh1
left a comment
There was a problem hiding this comment.
Thanks for the thorough work and validation notes on this feature. Highlights:
- Please rebase: the PR is currently
CONFLICTINGwithmain. - Merge order: the Gym pin depends on draft Gym#4930 (see inline comment).
- Test collection:
test_score_centering.pyundertests/unit/models/generation/is not collected by any L0 shard. - Positives: the sampler adapter is a clean seam shared by Gym/vLLM/the worker,
compute_score_centering_termis a pure, well-tested function, column plumbing follows the OPD/routed-experts pattern, and config validation is centralized. The estimator math (head + modeled tail, TIS/ICEPOP handling, sign, position alignment) checked out by hand; nothing was run (no GPU). - Lint: ruff/ruff-format/taplo pass; pyrefly was not verified on this host.
Generated by Claude Code
token_capture.top_logprobs=K keeps the top-K log-probs of every generated token on captured calls: the request class raises SamplingParams.logprobs to K while the response stays cut at top_logprobs=0, the worker writes the two columns onto the call's staging row after the digest-covered put, and the finalizer carries them token-aligned into the training rows as generation_topk_ids / generation_topk_logprobs. Off by default (0). Signed-off-by: Tugrul Konuk <[email protected]>
loss_fn.score_centering adds, per token, A * sum_v sg(c_v) log p_v over the sampler's captured top-k ids (Marek and Ryabinin, arXiv:2609.20807, Eq. 14, tail modeled as rho * p). Its gradient is the sampler-expected score, in closed form for token-level "tis" weights, so the update stops drifting toward the sampler. The head log-probs come from ChunkedDistributedGatherLogprob (fp32 backward, TP + CP). Off by default. Signed-off-by: Tugrul Konuk <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
…erface Signed-off-by: Guyue Huang <[email protected]>
Adapt head/tail importance weighting, internal packed TP/CP gathering and strict sampler probability validation from Oleg's c8f508bba implementation. Preserve the clipped actor objective, token-capture transport, sampler adapter, and existing OPD names and behavior. Add gradient, masking, probability and packed preparation coverage, and expand the functional smoke to all IS modes. Co-authored-by: Oleg Rybakov <[email protected]> Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
0134154 to
0be7831
Compare
Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test 0dc043c |
@guyueh1, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 0dc043c |
@guyueh1, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 0dc043c |
…compatibility Signed-off-by: Guyue Huang <[email protected]>
…ount Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test d05ecfc |
Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test c9d5fbe |
… fixture Signed-off-by: Guyue Huang <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test 276e93a |
Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test 39c2642 |
…dy-first Applies the net diff of guyueh1/NeMo-RL pr/codex/score-centering (276e93a) against its upstream base dd2e251, without merging upstream main. Conflicts resolved: - vllm/utils.py: drop the PR-side PrefixSplice import (unused here; it comes from an upstream commit we do not carry). - tests/unit/data_plane/test_tq_token_sink.py: import only SAMPLER_TOPK_FIELDS (ROUTED_EXPERTS_FIELD unused in our test). - tests/unit/single_controller/test_setup.py: keep our first_step_partial tests and the PR's score-centering tests; drop TestAdaptiveLossRestore (adaptive-ppo-clip is not in our base). Not taken: the Gym submodule bump to NVIDIA-NeMo/Gym d8f4db46 (we stay on subhankar-ghosh/Gym dabstep-patches; Gym NVIDIA-NeMo#4930 must be ported there) and the matching uv.lock nemo-gym metadata line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Guyue Huang <[email protected]>
|
/ok to test ee7f18f |
Resolves conflicts with NVIDIA-NeMo#4818 (score centering): keep both chat_generation_tokens and attach_sampler_topk_logprobs_to_chat_response_choices in vllm/utils.py, and add test_score_centering.py to the L0 vLLM shards while keeping test_swe1_dynamo_config.py out (it moved to NVIDIA-NeMo#4979). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
The zero-tail branch set rho = 0 whenever the trainer tail was below 1e-6, including unfiltered capture, where a tiny trainer tail can still carry a large sampler tail. With a top-2 head, p = [0.6, 0.3999991, 9e-7] and q = [0.5, 0.3, 0.2], IS-off centering then left an expected tail-logit gradient of about 0.2 instead of the clamped estimate's 0.02. Only replay, where the trainer renormalizes over the sampler's support and the head holds all of p, has no tail. compute_score_centering_term now takes sampler_replay and zeroes rho only then; unfiltered capture is back to NVIDIA-NeMo#4818's estimate. ClippedPGLossFn derives the flag from policy_support_mask, which only filtering supplies, and filtered score centering always replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hayate Iso <[email protected]>
Adds optional score centering to the clipped PPO/GRPO policy-gradient loss. The sampler head retains its original probability mass; the unobserved tail is modeled as a rescaled current-policy distribution. The feature is off by default.
The shared utility adds the correction to the existing clipped objective. Original capture/loss commits fd46816 and 3e63b6d retain Tugrul Konuk's authorship. Broader IS handling, packed gathering, and probability validation are adapted from Oleg Rybakov's implementation.
Behavior and configuration
sequence_packing.fuse_loss=true. Packs candidate IDs together, performs full-vocabulary normalized gathering under TP, and reconstructs padded sequences under CP.loss_fn.score_centering=true,token_capture.enabled=true, andpolicy.generation.top_logprobs=K. Setup automatically raises vLLM'smax_logprobscap and preserves explicit-1. The oldtoken_capture.top_logprobssetting has moved to generation configuration.Request and transport
Gym explicitly sends
logprobs=true, top_logprobs=K; normal vLLM request resolution supplies SamplingParams. Standalone request, validation, and extraction functions provide an extension interface returning CPU sampler IDs and logprobs.Engine output → CPU int32 IDs/float32 logprobs → per-call staging → CPU finalizer → canonical rollout columns → policy leader fetch/broadcast → differentiable trainer logprobs at sampler IDs → loss.
Tokens, media, and sampler tensors share a staging write. Failures return
capture_failedwith best-effort partial-row cleanup. Captured top-k fields are stripped before HTTP serialization. Uncaptured calls to the policy server also request K and return their top-k values over HTTP. Top-k extraction runs in a worker thread to avoid blocking the serving event loop.Pins merged Gym #4930 at d8f4db463ef04a40b8a1db7088f69247dcbcebb7. No unmerged Gym dependency remains.
Documentation and tests
See
docs/guides/score-centering.mdfor mathematics, configuration, transport, extension points, limits, and costs.Validation
Previous head f0d9860 passed CI run 40089875747, attempt 2, including H100 and GB200 score-centering functional smokes for all four IS modes. The unit distributed jobs passed their two-GPU cases; the four-GPU cases were skipped there.
For the review fixes and merged Gym pin:
Remaining limits and evidence
SingleController + Gym + vLLM token capture is required. Sequence-level IS, seq-mask-tis, Automodel distributed logits, externally prepacked inputs, full-vocabulary OPD, and fused linear logprobs remain unsupported. Sampling must be unfiltered with positive finite temperature; non-unit temperatures require processed logprobs. Raw/default logprobs are accepted at temperature 1 and assume no other processor changes the distribution. Logits-return modes and explicit
logprob_token_idsare rejected.K scales CPU work, storage, transport, broadcast, and trainer communication linearly. Sampler arrays alone cost
8*T*Kbytes before copies/padding/trainer outputs.Still outstanding: real K=0/32/128 step-time, throughput, peak-memory and long-output latency comparisons, convergence A/B for the four IS modes with nontrivial importance ratios, and the GPU four-rank TP=2/CP=2 backward run. The smoke establishes integration and finiteness, not convergence or large-K performance.