fix(nemo-gym): refresh final-token route across turns - #3485
Open
zpqiu wants to merge 2 commits into
Open
Conversation
Signed-off-by: alexchiu <7390474+zpqiu@users.noreply.github.com>
Contributor
Author
|
/ok to test e3ba8c2 |
Signed-off-by: alexchiu <7390474+zpqiu@users.noreply.github.com>
Contributor
Author
|
/ok to test 09a2e40 |
zpqiu
marked this pull request as ready for review
August 4, 2026 06:29
Contributor
Author
|
/ok to test 09a2e40 |
Contributor
Author
|
/ok to test 09a2e40 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Why
The final generated token in a request is not fed back through the model, so router replay pads its route with a valid dummy row. On the next model request that token is part of the prompt and receives a real prefill route, but NeMo Gym previously sliced only the unseen prompt suffix and left the historical dummy route in the training trajectory. Replaying that dummy route can change hidden states and inflate rollout-versus-training logprob error.
The fix updates only the routed-expert metadata for the last already-seen token. It does not modify
seen_token_idsor change token slicing.Concrete two-turn failure
Assume one MoE layer with top-k=2.
The first request has:
Token
3is sampled from the logits produced while processing token2. Because the request ends immediately afterward, token3is never itself processed by the model in this request, so no real route exists yet.After a tool result adds tokens
[4, 5], the second request sends the full history:At this point,
seen_token_ids == [1, 2, 3]. The existing suffix slicing correctly starts at index 3 and adds only the new prompt tokens[4, 5], but that also means token3is not appended again. Before this fix, its already-stored route was never updated:This is not a tokenization or sequence-offset change. The token history remains
[1, 2, 3, 4, 5, 6, 7]; only the route metadata for the previous turn final token is refreshed from:The stale dummy route is harmful even though it belongs to a historical token: R3 forces training replay through those dummy experts, changing that token's hidden state and therefore the logprobs of later tokens that attend to it.