Checkpoint management#
Checkpoints capture model state, optimizer state, and training progress (iteration or step counters, schedulers, and related metadata). They are essential for fault tolerance (resume after failure), experiment management (reproducibility and comparison), and hand-offs between pretraining, fine-tuning, and conversion workflows.
Primus is YAML-driven: checkpoint behavior is configured per backend. Megatron-LM, TorchTitan, and MaxText each expose their own checkpoint surfaces; this guide maps the knobs you set in Primus configs.
Primary sources in this repository
Area |
File |
|---|---|
Megatron trainer defaults |
|
Primus Megatron extensions |
|
TorchTitan defaults |
|
Megatron checkpoint benchmark |
|
1. Overview#
What is saved: Typically model parameters, optimizer state, RNG state, and iteration/step tracking—exact contents depend on flags such as
no_save_optim/no_save_rng(Megatron) orinitial_load_model_only(TorchTitan).Why it matters: Long runs on AMD GPU clusters benefit from periodic saves to durable storage; resuming or branching experiments requires consistent paths and formats.
Backend-specific systems: Each training backend integrates its own checkpoint pipeline; Primus wires YAML into those backends without forcing a single universal format across Megatron, TorchTitan, and MaxText.
2. Megatron checkpoint configuration#
Megatron-related options live on the trainer configuration merged from trainer_base.yaml and primus_megatron_module.yaml. Defaults below are taken from trainer_base.yaml unless noted.
Core paths and cadence#
Parameter |
Default ( |
Description |
|---|---|---|
|
|
Directory where new checkpoints are written. |
|
|
Directory to load from when resuming training. |
|
|
Save every N iterations. |
|
|
When |
Format and detection#
Parameter |
Default |
Description |
|---|---|---|
|
|
Checkpoint format: |
|
|
When loading, infer format automatically. |
|
|
Path to a pretrained checkpoint. |
|
|
Load a specific step from the pretrained checkpoint when applicable. |
Optimizer and RNG inclusion#
Parameter |
Default |
Description |
|---|---|---|
|
|
When set truthy, omit optimizer state from saves. |
|
|
When set truthy, omit RNG state from saves. |
|
|
When set truthy, do not restore optimizer from checkpoint. |
|
|
When set truthy, do not restore RNG from checkpoint. |
Performance and distributed I/O#
Parameter |
Default |
Description |
|---|---|---|
|
|
Asynchronous checkpoint saving to reduce time blocking the training loop. |
|
|
Parallel save path for distributed checkpoints. |
|
|
Parallel load for distributed checkpoints. |
|
|
Optimization when model structure is fixed across saves/loads. |
|
|
Save to fast local storage on a different cadence than persistent saves. |
Related keys in trainer_base.yaml for non-persistent checkpoints include non_persistent_ckpt_type, non_persistent_global_ckpt_dir, non_persistent_local_ckpt_dir, and non_persistent_local_ckpt_algo (default "fully_parallel").
Format conversion#
Parameter |
Default |
Description |
|---|---|---|
|
|
Target format for conversion ( |
|
|
Output directory for converted checkpoints. |
|
|
Update legacy distributed optimizer layout when converting. |
Primus extensions#
Defined in primus/configs/modules/megatron/primus_megatron_module.yaml and implemented in primus/backends/megatron/patches/checkpoint_patches.py and primus/backends/megatron/patches/args/checkpoint_path_patches.py.
Parameter |
Default |
Description |
|---|---|---|
|
|
When |
|
|
When |
3. TorchTitan checkpoint configuration#
TorchTitan checkpoint options are grouped under checkpoint in primus/configs/modules/torchtitan/pre_trainer.yaml.
Parameter |
Default ( |
Description |
|---|---|---|
|
|
Master switch for checkpointing. |
|
|
Output directory (relative to run layout unless given as absolute). |
|
|
Save every N steps. |
|
|
Path for initial load (cold start or migration). |
|
|
Load weights only, not optimizer state. |
|
|
Load initial weights from Hugging Face layout. |
|
|
On last save, write model only. |
|
|
Write final checkpoint in Hugging Face format. |
|
|
Dtype for exported checkpoints. |
|
|
Asynchronous checkpoint mode. |
|
|
Retain only the K most recent checkpoints. |
|
|
Load a specific step ( |
|
|
Glob or pattern list to exclude from restore. |
|
|
Optional checkpoint at step 0. |
|
|
Create a seed checkpoint when enabled. |
TorchTitan also defines activation_checkpoint (activation recomputation) separately from persistent training checkpoints—do not confuse the two sections in pre_trainer.yaml.
4. MaxText checkpoint configuration#
MaxText (JAX) uses configuration keys surfaced in Primus documentation and MaxText configs under third_party/maxtext. Primus overlay presets set the defaults shown below, while upstream MaxText base.yml is still loaded at runtime via base_config: "base.yml" and might define different upstream defaults. Typical training flags:
Parameter |
Typical default |
Description |
|---|---|---|
|
|
Enable Orbax (or configured) checkpoint saves. |
|
|
When checkpointing is enabled, use async checkpoint workers. |
See docs/03-configuration-reference/maxtext-parameters.md for the full MaxText parameter table and interaction with training runs.
5. Checkpoint formats (Megatron)#
Format |
Behavior |
Notes |
|---|---|---|
|
Classic PyTorch save/load; often one file per rank in distributed settings. |
Simple but less flexible for topology changes. |
|
Distributed checkpoint format with resharding support (e.g., changing tensor/pipeline parallel degree between save and load). |
Recommended for many production flows that might change parallelism. |
|
Zarr-backed checkpoint storage. |
Useful when the stack and storage backend support it. |
Recommendation: Prefer torch_dist for production when you need flexibility across parallel layouts and scalable I/O (see ckpt_fully_parallel_save / ckpt_fully_parallel_load in Megatron config).
6. Common workflows#
Resume training
Set
loadto the checkpoint directory produced by a previous run.Keep
savepointed at the directory for new checkpoints (often the same tree with a new run id, depending on your layout).Ensure
finetuneisfalsewhen you want to continue iteration counts.
Fine-tune from a pretrained checkpoint
Set
load(and optionallypretrained_checkpoint/ckpt_stepas appropriate).Set
finetune: trueso iteration counters reset while weights load.
Auto-resume (Primus Megatron extension)
Set
auto_continue_train: truein the Megatron module config.Primus searches for the latest checkpoint under
saveand aligns load/optimizer flags; seeprimus/backends/megatron/patches/checkpoint_patches.pyfor behavior details.
Convert checkpoint format
Set
ckpt_convert_format(for exampletorch_dist) andckpt_convert_saveto the output directory.
Import Hugging Face weights (TorchTitan)
Set
checkpoint.initial_load_in_hf: trueandcheckpoint.initial_load_pathto the HF model directory.
7. Benchmarking checkpoints#
The Megatron checkpoint benchmark lives in benchmark/megatron/checkpoint/.
Entry points
benchmark/megatron/checkpoint/ckpt_launch.py—main launcher (requires a Primus YAML config).benchmark/megatron/checkpoint/ckpt_report.py—reporting utility (can be run separately).
Example (from benchmark/megatron/checkpoint/README.md):
export DATA_PATH=/PATH/TO/DATA
python3 benchmark/megatron/checkpoint/ckpt_launch.py \
--yaml-config-path examples/megatron/configs/MI300X/mixtral_8x7B_v0.1-pretrain.yaml \
--nnodes 1
The tool reports save/load times, bandwidth, and configuration echoes (world size, ckpt_format, async_save, paths, and more). Truncate or clean leftover output directories between runs if permissions or stale outputs cause issues.
8. Best practices#
Enable
async_save(Megatron) for large models when supported, to limit training stalls during checkpoint windows.Set
save_intervalfrom economic criteria: frequent enough to limit lost work, infrequent enough to avoid storage and throughput bottlenecks (Megatron default intrainer_base.yamlis20000—override per job).Use
non_persistent_save_intervalwith fast local SSD for frequent snapshots and a slower interval to NFS or object storage for durability.Validate resume and fine-tune paths on short runs before multi-week jobs; confirm
finetuneandauto_continue_trainbehave as intended.For TorchTitan, enable
checkpoint.enableexplicitly and setcheckpoint.keep_latest_kto bound disk usage.