In RL post-training a rollout engine generates the samples and the trainer recomputes them to take gradients. For an MoE, small differences between the two (different kernels, rollout weights one update behind) can change which experts a token goes through, so the trainer differentiates a path the sample never took. Measure that mismatch across layers and implement routing replay, where the trainer reuses the rollout's expert choices.
Routing in both engines: softmax over the selected logits of the top- experts (ties to the lower index), idx in descending logit order.
topk_route(logits, k): return (idx, w) for a (T, E) logit array, both (T, k).
routing_mismatch(train_logits, roll_logits, k)
(T, E) logit arrays for the same tokens. A router disagrees for token at layer when the two top- sets differ (order is ignored)."router_disagree_share": disagreeing (token, layer) pairs over ."token_disagree_share": tokens that disagree in at least one layer, over ."per_layer": list of the disagreeing share of each layer."expert_change_share": , the share of selected experts that changed.trainer_routing(train_logits, k, roll_idx=None, roll_w=None, mode="none") for one layer:
"none": the trainer's own topk_route(train_logits, k)."indices": use roll_idx, with weights recomputed as the softmax of the trainer's logits at those indices."full": use roll_idx and roll_w unchanged.
Return (idx, w).replay_gap(x, W1, W2, train_logits, roll_logits, k): experts are . Compute the rollout's output with its own routing, then the trainer's output under each mode. Return {"none": ..., "indices": ..., "full": ...}, each rounded to 4 decimals.