How a replayed sampling mask would reach the trainer once token capture is on

#3937 (sampling mask replay, draft, head 0d62c9a4) next to #4818 (score centering, head f0d9860e). Gym checked at bbf3cff4 (#4818's pin) and d8f4db46 (Gym#4930 merged).

Before
#3937 carries vLLM's mask inside Gym's HTTP response. That works only when token capture is off. Gym has no code for the field yet.
This PR
#4818 builds a second route: per-token tensors staged by the vLLM worker into the data plane, never passing through Gym. A mask has the same shape.
Status
Proposed โ€” not implemented. No PR moves a mask through token capture today. This page shows where it would go.

Six pages on this PR, one question each โ€” this one: which route a sampling mask can take.

Background. A sampling mask is one short list of token ids per generated token. In token capture mode, the driver no longer reads per-token data out of Gym's reply: it switches to receipt mode and skips the function #3937 reads the mask in. Dotted words have a short explanation: hover or tap them.

Same 3 generated tokens, both routes

Example: top_k=4, top_p=0.8. Supports of size 3, 2 and 1 for the 3 tokens. #4818's lane uses K=2 recorded candidates.

#3937 route: inside Gym's reply #4818 route: staged by the vLLM worker 1 ยท vLLM WORKER attach_sampling_masks_to_chat_response_choices message.sampling_mask = [[17,4,9], [8,23], [5]] (JSON lists) _finish_request_capture โ†’ attachments sampler_topk_token_ids [3,2] int32, logprobs [3,2] f32 TQTokenSink.stage: one put with tokens + images 2 ยท GYM reply JSON must keep "sampling_mask" Gym has no code for it (bbf3cff4, d8f4db46) โ†’ this is the "ask Gym" part Gym gets only a receipt (capture acknowledged) tensors never pass through Gym no Gym change needed 3 ยท RL DRIVER / FINALIZER _postprocess_nemo_gym_to_nemo_rl_result pops it _tensorize_sampling_mask โ†’ ids [3,4], sizes [3,2,1] with token capture ON this function never runs: the mask is lost CPU finalizer builds row columns [8,2] 5 prompt rows zero-filled; shape checked rejects topk_length_mismatch 4 ยท TRAINER logits outside the mask โ†’ -inf, then log_softmax same support as vLLM gathers trainer log-probs at the 2 ids score-centering loss term Both end as a per-token [tokens, width] int32 id column in the training batch. gap / needs work #4818's route works as is

What replay on the token-capture route needs โ€” proposed, not in any PR

Where it would land: RL only. Copy #4818's pattern for its two columns. No Gym change in token-capture mode: the tensors skip Gym, and top_k is pinned on the vLLM server (#3937 does this, because Gym's Responses API cannot send top_k). Gym needs work only for the token-capture-off route.

Nothing below is implemented. It is a sketch of where each piece would go.

@@ vllm_worker_async.py ยท _finish_request_capture, next to #4818's sampler_topk attach (L968-L973)
+        if self._return_sampling_mask_enabled():  # helper from #3937
+            # vLLM's per-token support, padded to top_k; sizes mark the real length.
+            attachments.update(
+                sampling_mask_token_ids=mask_ids,   # int32 [3, 4] = [[17,4,9,0],[8,23,0,0],[5,0,0,0]]
+                sampling_mask_sizes=mask_sizes,     # int32 [3]    = [3, 2, 1]
+            )
@@ setup.py ยท partition fields, as #4818 adds SAMPLER_TOPK_FIELDS (L341-L342, L371)
+    + (list(SAMPLING_MASK_FIELDS) if sampling_mask_replay else [])
@@ rollout_reassembler.py ยท finalizer, as #4818 zero-fills top-K rows
+    # prompt/tool rows get size 0; generated rows must equal the call's token count

A possible shortcut, not tested. With logprobs_mode=processed_logprobs, vLLM computes the reported log-probs over the filtered logits, so tokens the filter cut come back as -inf (model.py L255, sampling_mask.md). So #4818's own columns with top_logprobs = top_k would already hold the support: the ids whose log-prob is finite. Two things stop that today: #4818's extraction rejects any non-finite log-prob (extract_score_centering_samples), and setup forbids filters with score centering. Ties at the top-k edge would also need checking.

So what. Asking Gym to carry the mask only helps runs with token capture off. For token-capture runs, the mask should ride the route #4818 just built, and Gym needs no change. #3937 is a draft from August, written against an older main, so it needs a rebase either way. #4818 is not the place to add this, but its staging slot for per-token columns is the piece mask replay would reuse.