Repository navigation
[rl] MoE router replay: train on the experts the generator chose - #5255
felipemello1 wants to merge 1 commit into
Conversation
acisseJZhong
left a comment
There was a problem hiding this comment.
thanks for making this PR!!
| routed_x_TD, | ||
| routed_padding_mask_T, | ||
| ) = self._maybe_shard_routed_branch_inputs_across_tp(x_TD, padding_mask_T) | ||
| if routed_expert_ids_TK is not None: |
There was a problem hiding this comment.
nit: combine with previous sharding?
| input_ids = [10, 11, 20, 21, 0, 0, 0, 0] | ||
| labels = [11, 12, 21, 22, 0, 0, 0, 0] | ||
| positions = [ 0, 1, 0, 1, 0, 1, 2, 3] | ||
| # Routed expert ids follow input_ids; padding rows are 0, where the routers |
There was a problem hiding this comment.
update the doc string example above?
| for start, end in _trainable_token_spans(mask): | ||
| absolute_start = branch_offset + start | ||
| absolute_end = branch_offset + end | ||
| # TODO: router replay. Return Completion.routed_expert_ids through the |
There was a problem hiding this comment.
oh I assume the in agent RL we will only use the Verifier Rollouter not the native rollouter? so this is also very important to add?
| vLLM binds ``capture_fn`` on every module that has ``layer_id`` and ``capture_fn`` | ||
| attributes (``RoutedExpertsCaptureSource``) after its profile run, stores the ids | ||
| by KV slot, and returns them as ``CompletionOutput.routed_experts``. A prefix-cache | ||
| hit therefore returns the ids computed with that cached KV. |
There was a problem hiding this comment.
I guess less related to titan, but do you know if the expert ids are literally stored together with kv cache?
| step_timer.record("timing/step/forward_backward"), | ||
| ): | ||
| # TODO: every trainer rank receives the whole [num_microbatches][dp_degree] | ||
| # grid and keeps its own column. Routed expert ids make that 418 B/token |
There was a problem hiding this comment.
did you measure the comm time increase?
|
update by claude: addressed the review, then rebased on main and trimmed the PR to replay only (1290 -> 734 lines; the routing-mismatch metrics move to a follow-up).
|
a6a36c6 to
31ee9fe
Compare
The generator (vLLM) and the trainer run the same MoE, but bf16 noise near
the top-k boundary sends some tokens to different experts, which moves the
importance ratio for reasons unrelated to the policy update.
- VLLMGenerator.Config.return_routed_experts: a forward hook on every router
feeds vLLM's routed-experts capture; Completion.routed_expert_ids is
[prompt + completion - 1, num_layers, top_k].
- The rows ride like the prompt: RolloutTurn keeps a delta, TrainingSample
one row per trainer input, the batcher packs model_kwargs["routed_expert_ids"].
- Decoder.forward(routed_expert_ids=...) gives layer i its [:, i] slice; the
router routes real tokens there; gate weights still come from its scores.
- The Verifiers rollouter speaks Verifiers' routed_experts protocol.
- DAPOLoss logs bit_wise/{kl_k3,logprob_diff_abs,ratio_beyond_2x}/mean.
- Off by default; without ids every forward is unchanged.
31ee9fe to
40c12cd
Compare
TLDR: The trainer can now route each token to the experts the vLLM generator chose (router replay). On Qwen3-30B-A3B the trainer-generator k3 KL drops ~6x. One flag, off by default.
Problem
p_trainer / q_generatormoves for reasons unrelated to the policy update.Solution
VLLMGenerator.Config.return_routed_experts = True.Results
controller.py.You may ask:
NOTE:
Test plan
pytest tests/unit_tests/cpu/models/common/test_moe.py tests/rl/unit_tests/cpu pytest tests/unit_tests/gpu/test_router_replay.py # 1 GPUFollow up
routed_experts_prompt_start).