Skip to content

[train] feat: support opt-in asynchronous Megatron checkpoints - #2

Open
tongyx361 wants to merge 2 commits into
verl-project:mainfrom
tongyx361:tyx/async-checkpoint
Open

tongyx361 wants to merge 2 commits into
verl-project:mainfrom
tongyx361:tyx/async-checkpoint

Conversation

@tongyx361

@tongyx361 tongyx361 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add opt-in asynchronous Megatron checkpoints to the Laminar trainer. trainer.async_checkpoint=true stages a CPU snapshot and uses the shared verl writer to save it in a background thread. The trainer publishes the latest checkpoint after the actor and dispatcher saves complete and drains the final checkpoint at shutdown. Checkpoint frequency and Relay weight publication frequency are independent.

This branch pins a published Laminar hooks revision with the shared writer. The upstream writer is under review in verl #8823. HF initialization support is tracked separately in verl #8821.

Validation

  • 949 Laminar CPU tests passed across tests/*_on_cpu.py in the locked environment, including 73 focused checkpoint, actor bootstrap (WORLD process-group prewarming under EP > 1), and launch-script regressions, plus GitHub Actions Public source checks and Secrets scan.
  • The final pinned build passed fresh-process native saves and restores on one H100/NCCL and on CPU/Gloo with a tiny model and Adam, matching parameter, optimizer, scheduler, and RNG state plus the next optimizer update.
  • On 8 H100s (TP1/PP1/CP4/EP8/DP2) with a 12-layer 128-expert slice of Qwen3-Coder-30B-A3B-Instruct and mocked SWE trajectories, the final pinned build passed full AsyncRLTrainer + AsyncMegatronActorWorker + RelayManager + RolloutDispatcher execution with save_freq=1, weight_publish_interval=4, and max_actor_ckpt_to_keep=2: checkpoints saved every step (1..5) while Relay published only v0 and v4, retention kept global_step_4 and global_step_5, checkpoint:5 drained before Tracker.finish() at shutdown, and a fresh-process resume_mode=auto restart (steps 6..7) restored step 5 across all 8 ranks with exact sampled model/Adam/scheduler match, exact RolloutDispatcher prompt cursor continuity, Relay re-seeding at v5 plus v6 publication, and clean shutdown drain.
  • On a single matched 16-H100 allocation (TP1/PP1/CP8/EP8/DP2) running Qwen3-Coder-30B-A3B-Instruct with reconstructed historical sequence lengths and synthetic tokens (2 warm-up updates, 12 measured updates, 128 sequences per update, 73,385,108 non-padding tokens, and 1 save every 4 updates, each arm in a fresh Ray process group), no-save training compute averaged 243.41 s per update (2920.90 s total; 2937.28 s primary loop):
Final pinned mode (same 16xH100 allocation) Foreground blocking per save Foreground blocking per training update Share of no-save training compute Measured primary loop
No save 0.00 s 0.00 s 0.00% 2937.28 s
Sync 122.06 s 30.52 s 12.54% 3404.48 s
Async 22.21 s 5.55 s 2.28% 3120.81 s

Async saved 24.96 s of foreground checkpoint blocking per training update—an 81.81% reduction relative to sync—and shortened the measured training loop by 8.33% (3404.48 s to 3120.81 s, reducing loop overhead vs. no-save from +15.91% to +6.25%). Foreground time includes staging (47.44 s), save-boundary pending-write waits (5.84 s), and in-loop retention (13.34 s). The terminal async drain (3.74 s) and terminal retention (12.36 s) were recorded outside the measured loop.

On the same 16-H100 allocation and final pinned build, 16-rank cold restores passed in both directions in both directions—verl to Laminar (62.88 s) and Laminar to verl (62.47 s)— with sampled model, Adam, and scheduler state matching across all 16 ranks followed by a real optimizer update for each restore.

Usage

bash recipes/swe/train.sh \
  trainer.async_checkpoint=true \
  trainer.save_freq=1 \
  actor_rollout_ref.actor.megatron.use_dist_checkpointing=true

Before marking ready

  • Run the final pinned build with save_freq=1, independent Relay publication, shutdown drain, and trainer/dispatcher restart.
  • Repeat the 16-H100 performance measurement on the final pinned build.

OpenAI Codex assisted with implementation, testing, and drafting.

Let Laminar own checkpoint finalization and publication while verl writes a native snapshot in a thread.

Assisted-by: OpenAI Codex
@tongyx361
tongyx361 marked this pull request as ready for review November 25, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant