Two different "top-k"s: the K candidates score centering records, and the top-k/top-p filter that mask replay copies

NVIDIA-NeMo/RL #4818 (score centering) next to #3937 (sampling mask replay, draft) and vLLM 0.29.0's sampling-mask feature. Permalinks pin #4818 head f0d9860e and #3937 head 0d62c9a4.

Before
On the Gym/HTTP path, the top-k sampling filter is forced off and top-p is allowed. The trainer rebuilds the top-p cut from its own probabilities. No vLLM sampling mask is sent anywhere.
This PR
#4818 records vLLM's K most likely candidates per token. That is data for a loss term, not a filter. It requires both filters off.
Status
Pre-existing, untouched by #4818. Replaying the filter's exact support is a separate feature, in draft #3937. #4818 neither adds nor blocks it.

Six pages on this PR, one question each โ€” this one: which "top-k" is which.

Background. At each generated token vLLM has a probability for every token in the vocabulary. A sampling filter (top_k, top_p) cuts that list before sampling; the tokens that survive are the support. Separately, vLLM can report the probabilities of its K most likely tokens (top_logprobs=K) without cutting anything. #4818's "top-k" is the second kind. Dotted words have a short explanation: hover or tap them.

One generated token, three setups

Six-token vocabulary. vLLM's probabilities q and the trainer's p differ slightly, as they always do in practice. vLLM sampled token 9. Supports were computed with NeMo-RL's own apply_top_k_top_p, which copies vLLM's rule.

token id 174 931 250 โ˜… sampled 1 ยท #4818 score centering: top_logprobs=2, no filter vLLM q .45 .25 .15 .08 .05 .02 records 2 ids + logprobs: ids [17, 4], logprobs [-0.80, -1.39] Sampling uses all 6 tokens. The 2 recorded candidates are only read later by the loss: setup rejects any top_p < 1 or top_k with score centering (config.py L1419) 2 ยท Today, Gym/HTTP path: top_p=0.8 (top_k is forced off) vLLM q .45 .25 .15 .08 .05 .02 support {17, 4, 9} running sum .45 โ†’ .70 โ†’ .85 โ‰ฅ .8 trainer p .50 .32 .10 .05 .02 .01 rebuilt support {17, 4} running sum .50 โ†’ .82 โ‰ฅ .8 Sampled token 9 is outside the trainer's own cut โ†’ its log-prob is -inf โ†’ the token is dropped from the loss. server forces request.top_k = -1 policy_support_mask token_mask *= support (loss_functions.py L834) 3 ยท Mask replay (#3937, draft): top_k=4, top_p=0.8, vLLM returns its support vLLM q .45 .25 .15 .08 .05 .02 returns sampling_mask: [17, 4, 9] (padded to width 4) trainer p .50 .32 .10 .05 .02 .01 uses vLLM's support {17, 4, 9} renormalizes p over those 3 Token 9 stays in the loss, and both sides normalize over the same 3 tokens. #3937 configure_vllm_for_sampling_mask_replay: needs top_k > 0 vLLM 0.29: replay requires top_k > 0 kept by the filter cut by the filter recorded (score centering) sampled, but dropped by trainer K=2 recorded candidates ยท top_k=4 ยท top_p=0.8 ยท vocabulary of 6

So which filter is supported where?

top_k filtertop_p filterHow the trainer gets the support
Gym/HTTP path todayforced off (-1)allowedrebuilt from the trainer's own probabilities (row 2)
#4818 score centeringrejectedrejectedno filter, so no support. Its "K" is top_logprobs
#3937 mask replay (draft)required, > 0allowed with top_kvLLM's exact support, sent with the tokens (row 3)

The "top-p is not supported yet" you heard comes from mask replay, not from #4818. vLLM's replay requires top_k > 0: "pure top-p can produce vocab-sized masks". So top-p works only together with top-k, never alone. #4818 forbids both filters for a different reason. Its loss models vLLM's probabilities outside the K recorded tokens as a rescaled copy of the trainer's full softmax. A filter would set those probabilities to zero, which breaks that model.

So what. #4818 does not move a sampling mask, and it does not need Gym's help with one. Its K candidates would only meet mask replay if the two were combined later, and the loss would then need rework to model the tail inside the kept support. The real gap is row 2. Today, a sampled token that the trainer's own top-p cut excludes is dropped from the loss; the only trace is the policy_support_excluded_tokens count. The fix is mask replay (#3937), and the next page shows how its mask would have to travel once token capture is on.