Why a tied token at the top_k cut can stop a replay run with "the capture is corrupt"

NVIDIA-NeMo/RL #5006, head 77d3b094; vLLM 0.29.0.

Before
No replay, so no such check existed.
This PR
Adds check_sampler_support: a captured list that looks full but misses the sampled token raises and ends training.
Status
Open β€” not fixed in this PR. Raised in the review (comment C1), with a 4-line fix. Reproduced on CPU; how often a real run hits it is not measured (no GPU run).

Three pages on this PR, one question each. This one: when replay's own safety check kills a healthy run.

Background. For every token it generates, vLLM also returns a short list: the top_logprobs most likely tokens with their probabilities. Tokens its top-k filter removed get probability 0 (log-prob βˆ’inf). Replay treats the tokens in that list as "the tokens vLLM could have sampled" (page 1). So the list must contain the token vLLM actually sampled. If it does not, the code must decide between two explanations: the list was too short (normal, rare: drop the token from the loss) or the data is broken (a bug: stop the run). It decides with one test on the list's probabilities, shown below.

One generated token, step by step

Settings: top_k = 3 (vLLM may sample only the 3 most likely tokens) and top_logprobs = 3 (vLLM records 3 tokens). Setup allows this, since it only asks for top_logprobs β‰₯ top_k, and the guide's own example uses 64 and 64. Pretend the vocabulary has 5 tokens. Here are vLLM's numbers for one position:

ranktoken idlogit
(raw score)
probability after the top-k filtervLLM may sample it?in the recorded list of 3?
1172.0 0.6456yesyes
241.4 0.3543yesyes
39βˆ’8.0 0.0000293yesyes
3 (tie)23βˆ’8.0 0.0000293yes, tied with 9no, list is full
531βˆ’9.50 (cut)nono
  1. The tie. Tokens 9 and 23 have the same logit, so they share 3rd place. When fewer than 8 requests are decoding (the end of every rollout), vLLM's top-k keeps every token that ties with the 3rd. So it keeps 4 tokens, not 3, and can sample any of them. (With 8 or more requests, a different kernel keeps exactly 3.)
  2. The recorded list has room for 3. It holds 17, 4 and 9. Token 23 is left out.
  3. The test. The code adds up the probabilities in the list: 0.6456 + 0.3543 + 0.0000293 = 0.99997. If the sum is at least 0.9999, the list counts as complete (model_utils.py L739-L746). Here it does, because the missing token is so unlikely.
  4. The crash. vLLM samples token 23. That happens 0.0000293 of the time here, about 1 in 34,000. But a run generates millions of tokens. The list is "complete" and 23 is not in it, so the code concludes the data is broken and raises "the capture is corrupt". Training stops.

The same rule on three cases

casewhat happenedrecorded listsum of its probabilitiessampledtodayafter the fix
Athe example above: tie at 3rd place, tied tokens unlikely (0.0000293 each)17, 4, 90.99997 β†’ "complete"23run stopstoken dropped, counted
Bsame tie, but the tied tokens are likelier (logit βˆ’3.0, 0.0043 each)17, 4, 90.9957 β†’ "short"23token dropped, countedtoken dropped, counted
Cno tie; top_logprobs = 4, so the 4th slot holds a cut token at probability 0. A sampled token outside the list means broken data17, 4, 9, (23 at 0)1.0 β†’ "complete"23run stops (right)run stops (right)

A and B are the same event. Only the size of the left-out token differs, yet one is dropped quietly and the other ends training. "Dropped, counted" means the token is left out of the loss and added to the policy_support_excluded_tokens metric. C is how real corruption looks: the list has a slot at probability 0, so it already held every token vLLM could sample, and a token outside it cannot be explained by a tie.

The fix β€” proposed in review comment C1, not in the PR

Where the fix lands: RL only, one function, check_sampler_support. No vLLM change: keeping ties is vLLM's documented small-batch behaviour.

@@ nemo_rl/distributed/model_utils.py L739-L742 Β· check_sampler_support
-    head_mass = sampler_topk_logprobs.to(support.device).float().exp().sum(-1)
-    complete = head_mass >= 1.0 - 1e-4
-    sampled = input_ids.to(support.device).unsqueeze(-1)
-    if not (support == sampled).any(-1)[active & complete].all():
+    head_mass = sampler_topk_logprobs.to(support.device).float().exp().sum(-1)
+    sampled = input_ids.to(support.device).unsqueeze(-1)
+    in_support = (support == sampled).any(-1)
+    # vLLM keeps every token tied at the top_k-th logit on small batches, so a
+    # head with no -inf slot can miss the sampled token: drop it, don't raise.
+    tie_miss = (support >= 0).all(-1) & ~in_support
+    complete = (head_mass >= 1.0 - 1e-4) & ~tie_miss
+    if not in_support[active & complete].all():
         raise ValueError(
             "sampler replay: a sampled token is not in its captured sampler "

In case A the list has no slot at probability 0 and misses the sampled token, so tie_miss is true: the position counts as short, and the loss drops and counts the token, as in case B. In case C the list has a slot at probability 0, so tie_miss is false and the error still fires. That keeps the PR's broken-data test passing. The simpler idea, "any miss means short", would also drop case C and break that test. Raising top_logprobs above top_k only makes case A rarer, because a tie can be wider than the extra room.

πŸ”΄ review comment C1 β€” model_utils.py:739

So what. As written, replay can end a long run with an error that blames the capture when nothing is wrong. The fix is four lines in one function and keeps the real-corruption check. The review also asks for a unit test with a full list and a tied sampled token.