Skip to content

Replay Manager ​

Replay Manager lets Megatron reuse the MoE expert routes and frozen visual embeddings that SGLang produced during rollout. The two built-in replay kinds are moe (R3) and mm_embedding. The diagram follows online reference delivery from one generation request to the training microbatch that consumes it. For offline reproduction of a training step, see Trajectory Replay.

Architecture and ownership ​

SGLang captures expert IDs by token and layer, and captures visual embeddings after the vision merger. The producer publishes a reference once the body writes finish. A training sample carries its normal training fields and a compact replay manifest in rollout_replay_refs. Replay Manager tracks publisher ownership, partition holds and active readers so that retiring a training partition can reclaim bodies after the last holder releases them. Global recovery starts a new replay run.

Sample selection. Native rollout can export several training rows from a custom R3 generator. Rows from one request keep its sample index, and dropping one row releases only its share of a route. Default GRPO counts each request once and assigns its normalized reward to every row of that request. If those rows have different rewards, supply a --custom-reward-post-process-path to define how to process them. In Agentic rollout the Session determines which tokens were accepted and which branches enter training. Across turns or resumed requests it preserves the route spans for the accepted prefix. The manager transfers the selected route records and the lease for each selected image occurrence to the exported group. Rejected branches release their holdings.

Queue handoff. Both rollout paths use put_rollout_batch. Replay Manager attaches the selected bodies to the training partition before sending the samples. A failure known to precede dispatch releases the unsent holds. Once dispatch begins, a missing acknowledgement leaves the bodies available because a trainer may already see the samples. Acknowledged writes complete the handoff to the partition.

Training schedule. MegatronConsumer selects the queue fields and resolves the references. For R3, it maps the packed microbatch tokens to recorded rows for each local MoE layer. For MM, the input pipeline stage reads the frozen outputs and shares them within its tensor-parallel group.

ScheduleWhen the consumer binds replay
ColocatedPrepare the routes and visual inputs before training from the collected batch.
HybridPrepare R3 for the scheduled microbatches. After merging sub-batches, rebind the visual inputs to the merged batch.
Fully asyncWhen the schedule fetches the actual microbatch, bind the routes for the current model chunk and the visual inputs where needed. MM has the PP restrictions below.

How reference R3 differs from the original path ​

  1. What travels with the sample. The original SGLang rollout decoded the full route array into Sample.rollout_routed_experts and sent that field through the training queue. Reference R3 stores the immutable body separately. Multiple selected rows can refer to the same record, and each rank can read the rows for its own layers and token layout.
  2. Who decides when to replay and release. The original Megatron Actor reshaped the queued arrays and filled router replay state itself. The training schedule now chooses the binding point, while Replay Manager owns the readers and the lifetime of the underlying records. This also gives Agentic branch selection and uncertain queue writes explicit ownership rules. The full-tensor R3 delivery path remains available in compatible configurations.

Extension point for QSA and DSA indexer replay ​

The dotted edges show where a future indexer would capture its decisions and bind them to the consuming model. Register a ReplayKind with ReplayManager.register_kind before installing engine hooks. The definition names the replay field, producer and consumer adapters, and optional engine patch hooks. An indexer implementation must supply its capture format, token/layout validation and model-specific read and binding logic. QSA and DSA indexer reference replay are unimplemented in this PR. The separate draft explores the Qwen3.8 QSA and Keye DSA layouts. Draft PR #730

Enable R3 and MM replay ​

Add these flags to an online Megatron recipe:

bash
--use-rollout-routing-replay
--use-routing-replay
--optimize-routing-replay
--use-rollout-mm-embedding-replay
--freeze-vision-model
--freeze-vision-projection

The first three flags control rollout route capture, training replay, and routing optimizations. Supported online R3 recipes default to references. When rollout dumps are enabled, the producer copies MoE routes before sending the batch to training so the dump remains readable after partition cleanup. MM embedding references are local to the run. Baselines remove the four replay flags while keeping the vision encoder and projection frozen.

MM supports Qwen3.5 MoE and multimodal Qwen3.8 checkpoints with visual widths of 2048 and 2560 respectively, spatial merge size 2, and no DeepStack. It requires BF16, packed THD, CP1, and frozen vision encoder and merger/projection. Colocated, hybrid, and fully async modes support built-in SGLang and Agentic rollout. Asynchronous MM requires PP1 without interleaving; fully async additionally requires dynamic token batching and inline actor log-probabilities, without a separate reference policy. MM does not support Critic, partial rollout, MTP, speculative decoding, hierarchical cache, custom generation, Slime router, or OPD.

Capture occurs after the visual merger. Training loads BF16 outputs on the input PP stage and broadcasts within the TP group, without quantization. Reference R3 requires static CP and excludes combined 1F1B MoE overlap. Use an image with matching SGLang and Megatron patches; these experiments used SGLang 0.5.21.

Split-branch experiment record (2026-11-22) ​

Model: Qwen3.5-35B-A3B. Each experiment uses 8 × 280G Blackwell GPUs on one node. Replay is R3+MM reference, without QSA/DSA. Each run has 10 steps and saves no model checkpoint. Values below are arithmetic means over steps 1–9, excluding step 0. Rewards are omitted.

Task / modeBaseline s/stepReplay s/stepTime changeMismatch KL: baseline → replayStatus
DeepEyes fully async, TQ fixed70.9862.72−11.6%*0.003724 → 0.000825Both completed 10 steps
DeepEyes hybrid69.6168.55−1.5%0.004220 → 0.001261Both completed 10 steps
DeepEyes colocated124.03121.57−2.0%†0.003942 → 0.000634Replay completed 10 steps
OpenR1MM colocated129.71119.80−7.6%0.001488 → 0.000296Both completed 10 steps

* Fully async is a diagnostic comparison across two machines, each using eight GPUs independently, with an additional sealer change. Its timing difference cannot be attributed entirely to replay. The current-branch confirmation without that change or profiling also completed 10 steps: 59.09 s/step, mismatch KL 0.001119. It is recorded separately rather than mixed into this pair.

† DeepEyes colocated uses a historical baseline. Hybrid OFF/ON ran on the same machine. Trajectory lengths and token counts vary during these short runs.

Key configuration ​

SettingDeepEyes fully async / hybridDeepEyes / OpenR1MM colocated
GPU allocationActor 4 + Rollout 4, separate GPUsActor and Rollout time-share 8 GPUs
Training TP / PP / CP / EP / ETP2 / 1 / 1 / 4 / 12 / 1 / 1 / 8 / 1
Sequence parallelEnabledEnabled
Rollout engines2 engines, TP2 each4 engines, TP2 each
Staleness20
Prompt batch × samples per prompt16 × 816 × 8
Global batch size128128
Micro batch / dynamic token budgetmicro-batch-size=1; dynamic batching, max-tokens-per-gpu=16384Same
Prompt / response / context limits4096 / 2048 / 16384 tokensSame
SGLang context / max running / max total tokens16384 / 32 / 131072 per engineSame
SGLang static memory fraction0.750.75
Precision / attentionBF16 / FlashBF16 / Flash
Vision model / projectionBoth frozenBoth frozen
OptimizerAdam, lr=1e-6; CPU offload, D2H/H2D overlap, precision-aware optimizer enabledSame
AlgorithmGRPO + TIS, mismatch metrics enabledSame

DeepEyes uses agentic concurrency 8 and timeout 1200 seconds, with a separate CPU Qwen2.5-1.5B-Instruct judge on each node. OpenR1MM uses the built-in openr1mm reward path without agentic rollout. Communication uses Socket + IPv4 with IB, network plugins, and NVLS disabled; all experiments are single-node.

For a runnable colocated R3 example, see the OpenR1MM training script.

DAPO-Math 50k long-response stress test (2026-11-23) ​

This stress test compared R3 storage and training time for long responses. Every sample generated exactly 50,000 tokens. All three runs used the same model, dataset and parallel configuration, with MM replay disabled. Each run completed one optimizer step.

ParameterConfiguration
Model / datasetQwen3.5-35B-A3B / DAPO-Math-17k
Hardware / mode2 nodes, 16 Blackwell GPUs, colocated Actor and rollout
Training TP / PP / CP / EP / ETP2 / 1 / 2 / 8 / 1
Rollout8 TP2 engines, at most 16 requests per engine
Prompts × samples per prompt / GBS32 × 16 / 512
Micro-batch / dynamic token budget per GPU1 / 65,536
Response length / context limit50,000 / 65,536 tokens
MTPNEXTN, draft steps=2, draft tokens=3, top-k=1
Precision / optimizerBF16 / Adam, lr=1e-6, CPU offload
Total output per run25,600,000 tokens
ConfigurationEnd-to-end sTraining sEnd-to-end change vs baselineMismatch KLR3 foreground wait sStatus
R3 disabled1382501.16—0.000701—Completed
R3 uint81595674.42+15.4%0.000491117.76Completed
R3 uint8 + CPU cache reclamation and progressive prefetch1445522.06+4.6%0.0004940.048Completed

End-to-end time runs from rollout start through training data cleanup for that step, including checkpoint saving and final weight synchronization. Training time is perf/train_time, and R3 foreground wait is perf/replay_consumer_wait_time. Using the values in the table, the optimized R3 run took 4.2% longer to train than the replay-disabled run and had about 29.5% lower mismatch KL.

The table shows replay storage and memory for the uint8 run with CPU cache reclamation and progressive prefetch.

MetricSize
Actual uint8 route replay size7.65 GiB
Estimated int32 size for the same routes30.61 GiB
Route capture buffer2.50 GiB per process
Peak training CPU cache120.53 MiB per rank
Peak managed budget for training cache and prefetch256 MiB per rank

Storing each expert ID in one byte instead of four reduces route storage by 75% relative to int32. The 256 MiB per rank includes cached data and space reserved for prefetch.

Released under the Apache 2.0 License.