[megatron] add opt-in async distributed checkpoint save#1838
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for asynchronous distributed checkpoint saving (async_dist_ckpt_save) in the Megatron strategy, allowing training to resume immediately while checkpoint writing occurs in the background. It adds mechanism to block on previous async saves, fall back to synchronous saving for cloud paths, and introduces finalize_pending_saves across trainers and workers to ensure pending writes are completed before teardown or reload. The review feedback highlights a potential issue in trainer.py and fully_async_trainer.py where finalize_pending_saves is only called if ckpt_interval > 0. It is recommended to call this method unconditionally on teardown to prevent potential checkpoint corruption if checkpoints are triggered via other means (such as callbacks) when the interval is disabled.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
e843001 to
abb2fd8
Compare
The torch_dist checkpoint save is fully parallel across ranks but synchronous, so training stalls for the entire shard-write duration on every ckpt_interval -- costly for large models saving frequently. Add MegatronConfig.async_dist_ckpt_save (default off, behavior unchanged). When enabled, dist_checkpointing.save stages shards to host memory and writes them in a background process, letting training resume immediately. The pending write is finalized before the next save, before any reload, and at end of training, so the on-disk format is identical to a sync save. Async falls back to synchronous for cloud destinations, where local_work_dir uploads on context exit and would otherwise race a partial checkpoint. Signed-off-by: Vu Dinh <vudinh@outlook.com>
abb2fd8 to
dbcea2e
Compare
Summary
The Megatron
torch_distcheckpoint save is fully parallel across ranks but synchronous — training blocks for the entire shard-write duration on everyckpt_interval. For large models checkpointing frequently, that stall is significant.This adds an opt-in
MegatronConfig.async_dist_ckpt_save(defaultFalse, so existing behavior is unchanged). When enabled,dist_checkpointing.savestages each rank's shards to host memory and writes them to disk in a background process, letting training resume immediately. This replaces the long-standingTODO(tgriggs): Support configurable async savesinmegatron_strategy.py.Changes
MegatronConfig.async_dist_ckpt_saveknob (off by default).MegatronStrategy.save_checkpoint: passesasync_sharded_savethrough and schedules the returned request on the existing persistentAsyncCallsQueueinstead of asserting it isNone. Blocks on the previous async save before issuing a new one.MegatronStrategy.finalize_pending_saves(): drains in-flight writes; called at the start ofload_checkpointand exposed up throughWorker→WorkerDispatch→ end-of-training in the sync, fully-async, and SFT trainers.Correctness
local_work_diruploads on context exit and would otherwise race a partial checkpoint. Only active for local/shared filesystems.Test plan
async_dist_ckpt_save=true: verify checkpoints are byte-identical to sync saves and reload correctly.