How sampler replay scores a top-k/top-p token, next to the existing "recompute the filters" path

NVIDIA-NeMo/RL #5006, stacked on the merged #4818 (score centering). All links pinned to head 77d3b094.

Before
With top_k/top_p sampling, the trainer re-applies the same filters to its own logits. When its numbers differ a little from vLLM's, its kept set can differ, and the sampled token is dropped from the loss. Score centering refuses filters entirely.
This PR
Adds policy.generation.sampler_replay (off by default): the trainer reads vLLM's kept set from the top-K list it already captures and scores the token over exactly that set.
Status
New feature, works as designed — two open bugs from the review (pages 2 and 3), both one-function fixes.

Three pages on this PR, one question each. This one: what replay is and where it differs from today. Background on the idea: #4818 "top-p support" page.

Where this sits. Replay runs only in the v2 single controller (SingleController + NeMo Gym + vLLM token capture), on Megatron or Automodel (TP=CP=1). The v1 loops (grpo_train, PPO, distillation) reject it at setup (grpo.py). Turn it on with:
policy:
  generation:
    top_k: 3              # replay needs a top_k: it bounds the kept set
    top_p: 1.0
    top_logprobs: 4       # (id, log-prob) pairs recorded per token; must be >= top_k
    sampler_replay:
      enabled: true
    vllm_cfg:
      logprobs_mode: processed_logprobs   # filtered tokens come back as -inf
token_capture:
  enabled: true
Dotted words have a short explanation: hover or tap them.

One sampled token, two ways

Example: top_k = 3 (vLLM may only sample from the 3 most likely tokens) and top_logprobs = 4 (vLLM records the 4 most likely tokens with their log-probs). They are two different settings: top_logprobs must be at least top_k so the record holds every token vLLM could sample, and the spare 4th slot comes back −inf. vLLM's logits for ids 17, 4, 9, 23 are 2.00, 1.40, 0.31, 0.30, so it keeps {17, 4, 9} and samples 9. The trainer, in different precision, gets 2.00, 1.40, 0.30, 0.31: ids 9 and 23 swap places at the cut. Probabilities below are computed from those logits.

today: recompute the filters this PR: sampler replay 1 · vLLM SAMPLES (same in both) kept {17, 4, 9}, q = 0.577, 0.317, 0.106 → sampled id 9 (log q = −2.24) vLLM's own top-3 on its logits 2.00, 1.40, 0.31 (23 has 0.30, cut) 2 · WHAT IS CAPTURED PER TOKEN sampled id 9 (+ head, unused here) top_logprobs may be 0 ids [17, 4, 9, 23], log q [−0.55, −1.15, −2.24, −inf] finite slots = vLLM's kept set 3 · TRAINER'S KEPT SET apply_top_k_top_p on trainer logits keeps {17, 4, 23}: id 9 is cut SamplerSupportLogprob: gathers 4 logits, logsumexp uses {17, 4, 9} from step 2 4 · TRAINER LOG-PROB OF id 9 log p = −inf token dropped (policy_support_excluded_tokens +1) log p = −2.249 (vLLM: −2.24, ratio 0.991) token trained 5 · SCORE CENTERING (#4818) rejected at setup with top_k / top_p unfiltered sampling only allowed: head = whole kept set, no tail to guess same 4 recorded slots feed the correction term matches the sampler differs from the sampler The PR body reports ~250 such dropped tokens per step with recompute and none with replay (Qwen3-0.6B, GB200).
  1. vLLM samples with top_k = 3 on its own logits and returns the 4 best processed log-probs. The cut id 23 comes back as −inf.
  2. Recompute re-runs the filter on the trainer's logits. A 0.01 difference moves id 9 below the cut, so its log-prob is −inf and the loss counts it as excluded.
  3. Replay never re-runs the filter. It takes the finite slots as the kept set and normalizes the trainer's logits over just those ids (SamplerSupportLogprob). Every sampled token is inside that set, so none is dropped.

Where the two paths split and join

PassRecompute (today)Replay (this PR)
Actor loss get_next_token_logprobs_from_logits with the filters sampler_support_logprobs (packed path: L712)
Old ("prev") log-probssame filter recompute same helper, on Megatron and Automodel; the head is fetched a second time for this pass
Reference KLfull vocabulary in both: the reference pass resets the sampling params, so it never replays
Setup checksnone new top_k set, top_logprobs ≥ top_k (config.py), processed_logprobs, no fused linear logprobs

They join at the loss: both hand ClippedPGLossFn one log-prob per token. After that the only difference is that replay also hands over the recorded slots, which score centering uses, and marks a token −inf when its captured slots look short (that rule is where the bug on page 2 lives). The PR also makes the vLLM HTTP server pin top_k and turn off min_p and the repetition penalty for every Gym run, since vLLM would otherwise fill them from the model's generation_config.json.

So what. Replay removes a real source of off-policy noise (tokens the trainer's own cut drops) and is what lets score centering run with top-k/top-p. Its costs: top_k is required (pure top-p cannot fit in a fixed number of recorded slots), vLLM must return top_logprobs ≥ top_k log-probs per token, and the head is fetched twice. The review asks for step-time numbers, replay vs recompute, since the guide's "not slower" has none yet.