Skip to content

feat: add router replay (R3) support - #2590

Merged
terrykong merged 30 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:r3-router-replay-main-refresh
Jun 16, 2026
Merged

terrykong merged 30 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:r3-router-replay-main-refresh

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds Router Replay (R3) support for Megatron MoE policy training with vLLM
rollout generation.

R3 records MoE router choices from rollout generation and replays them during
Megatron prev-logprob and train forward passes. This keeps generated tokens on
the same expert routes used during rollout and avoids train-vs-rollout
expert-routing mismatch that is unrelated to the policy update.

The current NeMo RL integration is wired and tested for vLLM rollout
generation. Other inference/generation backends are not wired into this path
and have not been tested with Router Replay.

Configuration

policy:
  router_replay:
    enabled: true

When Router Replay is enabled, NeMo RL configures vLLM rollout generation with
enable_return_routed_experts=True and carries the returned routes through the
normal rollout and policy data path as routed_experts.

Example recipe:
examples/configs/recipes/llm/grpo-qwen3-30ba3b-8n8g-megatron-cp2-r3.yaml

Documentation

See docs/guides/router-replay.md for
configuration details, trace debugging, fallback behavior, and validation notes.

Validation

Effectiveness validation report:
https://api.wandb.ai/links/nvidia-nemo-fw-public/m4onwlx8

@zyzhou5
zyzhou5 requested review from a team as code owners May 27, 2026 21:45
@copy-pr-bot

copy-pr-bot Bot commented May 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@zyzhou5
zyzhou5 force-pushed the r3-router-replay-main-refresh branch 3 times, most recently from 062e262 to e996d94 Compare May 29, 2026 23:24

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Router Replay (R3) — PR #2590

Reviewed by a 5-agent team (rl-expert, test-agent, bug-finder, comment-reviewer, devil-advocate).

⚠ Merge conflicts — this PR is CONFLICTING against main. Please rebase and resolve conflicts before further review.

No high-confidence correctness bugs found — the implementation is careful with extensive shape validation, sentinel/fallback handling, and good test coverage. The core concern is the missing convergence/throughput evidence for the unconditional CP partitioning refactor (see inline comment on data.py).

Devil's advocate summary: 6 confirmed, 1 disputed, 3 downgraded. PR is clearly warranted (4,059 insertions for MoE router replay).

Generated by Claude Code

Comment thread nemo_rl/models/megatron/data.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
Comment thread nemo_rl/models/generation/vllm/utils.py Resolved
Comment thread nemo_rl/models/generation/vllm/utils.py Resolved
Comment thread nemo_rl/models/generation/vllm/utils.py Resolved
Comment thread nemo_rl/utils/r3_trace.py Resolved
@terrykong

Copy link
Copy Markdown
Collaborator

great work @zyzhou5 and @pjin-nvidia !

@zyzhou5 can you add some docs on this?

@zyzhou5 zyzhou5 changed the title Add Router Replay (R3) support feat: add router replay (R3) support Jun 4, 2026
@zyzhou5
zyzhou5 force-pushed the r3-router-replay-main-refresh branch from f6859bb to a1e223a Compare June 4, 2026 21:29
Comment thread nemo_rl/data_plane/codec.py Resolved
@zyzhou5
zyzhou5 force-pushed the r3-router-replay-main-refresh branch from a1e223a to f2110e3 Compare June 5, 2026 01:40
@zyzhou5
zyzhou5 requested a review from a team as a code owner June 5, 2026 01:40
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Jun 5, 2026
@zyzhou5

zyzhou5 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f2110e3

1 similar comment
@zyzhou5

zyzhou5 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f2110e3

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added CI Relating to CI CI:L1 Run doctests, unit tests, and functional tests labels Jun 5, 2026
@zyzhou5

zyzhou5 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f2110e3

@github-actions github-actions Bot removed the CI Relating to CI label Jun 5, 2026
@zyzhou5

zyzhou5 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0e69818

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test 0e69818

@zyzhou5

zyzhou5 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b1a9651

@zyzhou5

zyzhou5 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c37acfd

@zyzhou5

zyzhou5 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 42ad01e

@zyzhou5

zyzhou5 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3dd7c86

Comment thread nemo_rl/models/generation/vllm/utils.py Resolved
Comment thread nemo_rl/models/generation/vllm/utils.py Resolved
@zyzhou5

zyzhou5 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3dd7c86

Comment thread nemo_rl/utils/r3_trace.py Resolved
@zyzhou5

zyzhou5 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 21526ea

Comment thread tests/test_suites/disabled.txt Resolved
Trim the context-parallel changes from this PR: drop the
Transformer-Engine THD packed-sequence CP rewrite and keep NeMo-RL's
existing per-sequence CP sharding unchanged (byte-identical to main).
routed_experts and the R3 forward-trace token identities ride the same
_get_tokens_on_this_cp_rank sharding via a small additive helper
(_shard_routed_experts_for_cp). This commit also merges current main
and resolves the resulting conflicts.

Signed-off-by: Zeyu Zhou <[email protected]>
@zyzhou5

zyzhou5 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1565fe0

@zyzhou5

zyzhou5 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1e7bb71

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @zyzhou5. Awesome and thank you for the PR, changes for all the comments.

LGTM!

@terrykong

Copy link
Copy Markdown
Collaborator

@qiaochuz-nv

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

This branch was previously deployed

2 inactive deployments
test — 1e7bb718 Deployed Jun 15, 2026 by copy-pr-bot[bot] via Wait in test approval queue #12377
public — 1e7bb718 Deployed Jun 15, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #1117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests Documentation Improvements or additions to documentation Ready for QA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants