Repository navigation
[RFC] Optional native-vs-replay route diagnostics for Megatron R3 #6805
Replies: 2 comments
|
I prepared a minimal draft implementation in verl-recipe for easier review: verl-project/verl-recipe#114 The draft only includes CPU-testable utilities, README, REQUIRED_VERL.txt, a synthetic demo, and unit tests. It does not modify verl core. Happy to rename the recipe or reduce the scope if maintainers prefer a different direction. |
|
Updated the RFC in place based on the feedback. I removed the Fisher/expert-adaptation and replay-policy scope. The proposal is now limited to a default-off Megatron R3 diagnostics hook that compares native and rollout top-k routes before replacement and reports exact-set match, top-k overlap, and replay coverage. The earlier verl-recipe draft PR #114 is superseded; I will close it and only open a small core PR after distributed validation if this scope looks reasonable. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
This RFC proposes an optional
collect_metricsswitch for Megatron R3 router replay:When enabled, the actor update compares the training-side native top-k experts with the rollout-captured top-k experts immediately before R3 applies the replay route. It reports exact-set match, top-k overlap, and replay coverage once per actor update.
The switch defaults to
false. It does not change the replay mask, selected experts, routing scores, loss, gradients, optimizer updates, or routed-experts schema.Motivation
R3 reduces rollout-training routing mismatch by reusing rollout-captured expert selections during the actor update. The current Megatron R3 path already has both values needed to observe the mismatch before replay:
build_r3_replay_maskidentifies the causal rows covered by replay.RouterReplay.get_replay_topkapplies rollout-captured expert IDs on masked rows and keeps native top-k IDs on fallback rows.However, the training logs do not expose how different the native route would have been before replacement. When inspecting an R3 run, this makes several cases difficult to separate:
The proposed metrics provide direct observability for these cases. They are diagnostic signals for replay execution and alignment; they do not establish model-quality improvements on their own.
Metric definitions
For each router invocation, the implementation accumulates five integer sufficient statistics:
exact_match_rows: replay-covered rows whose native and rollout top-k expert sets are equal, independent of expert order;overlap_slots: native expert IDs that also occur in the rollout top-k, summed over replay-covered rows;replay_rows: rows selected by the existing boolean R3 replay mask;total_rows: all valid route rows;replay_slots:replay_rows * topk.The emitted metrics are:
actor/router_replay/native_route_exact_set_match_rateexact_match_rows / replay_rowsactor/router_replay/native_route_topk_overlap_rateoverlap_slots / replay_slotsactor/router_replay/replay_coveragereplay_rows / total_rowsactor/router_replay/replay_token_countreplay_rowsactor/router_replay/total_token_counttotal_rowsThe two count metrics expose the numerator and denominator used for coverage. Their unit is a token-layer route row: one token contributes one row at each local MoE router invocation. They are not counts of unique sequence tokens. Duplicate replay IDs cannot inflate overlap because each native expert ID contributes at most once per row.
If no rows are replay-covered, the three rates are reported as finite zeros.
Collection semantics
The proposed collection point is the existing Megatron
REPLAY_FORWARDpath, before replay replaces the native indices.For distributed aggregation, expert-parallel replicas observe the same router rows, so only expert-parallel rank 0 contributes. Tensor-parallel ranks contribute separately only when sequence parallelism shards the rows; otherwise only tensor-parallel rank 0 contributes. Pipeline stages remain additive so that every local MoE layer is represented.
Why this belongs in
verlcoreA recipe-level utility cannot observe the native top-k indices at the point where the Megatron router replaces them with rollout-captured indices. Correct aggregation also depends on Megatron TP, PP, EP, and sequence-parallel topology.
The proposed core change is limited to:
router_replayconfig;No new replay policy, cache format, rollout backend interface, or training recipe is introduced.
Scope
The first PR would support only Megatron R3. It would include:
router_replay.collect_metricsconfig field, valid only whenmode=R3;REPLAY_FORWARD;examples/router_replay/README.md.The first PR would not include:
build_r3_replay_mask;Validation plan
A local prototype and focused CPU tests are available. The CPU tests cover:
Before opening the core PR, I will also provide:
Open question
Would this default-off, Megatron-only diagnostics hook fit the existing
actor.megatron.router_replayconfig in core, or would maintainers prefer a different integration point for these metrics?All reactions