Checkpoints
What each stage saves and how big it is, how to resume pretraining and RL, how to make a weights-only copy with Megatron's checkpoint conversion, and how to check copies and saved weights.
What you will do
- Know what each stage saves, how often, and how much disk it takes.
- Resume a stopped run: pretraining, and RL with its curriculum state.
- Make a weights-only copy of a full checkpoint.
- Check a copy by checksum, and check that saved weights are the model you evaluated.
Hardware
The saves and the weights-only copies run on the training machine: 8×H100 for our model, one H100 for the rehearsal and the control run. The checksum checks run anywhere.
What each stage saves
| Stage | What is saved | How often | Our size |
|---|---|---|---|
| Pretraining | the full checkpoint: bf16 weights, fp32 main weights, Adam’s state, random-number state; plus the expert counts | every 200 steps, and at the time limit | 89.46 GiB per save |
| Router-study arms | weights only, at the exit | once | about 14 GB |
| SFT | weights only | every 35 steps | 13.7 GB per save |
| GSPO | the full checkpoint, with the optimizer state; the curriculum state | every 50 GSPO steps; the curriculum every step | not recorded |
| Control-run GSPO | Megatron’s single-file format | updates 50 and 100 | 3.09 GB of weights; 18.5 GB of optimizer state each |
Sizes, before you run out of disk
where \(P\) is the number of parameters, 2 bytes the bf16 weight, and 12 bytes the fp32 main weight and Adam’s two moments.
In words: a full checkpoint takes about 14 bytes per parameter, and a weights-only copy about 2.
For our 6.86B parameters this gives about 96 GB and 13.7 GB. The measured sizes: 96.1 GB for the full pretraining checkpoint in 23 files, and 13,743,073,344 bytes for its weights-only copy. Treat the formula as a rule of thumb that matched our sizes, and plan the disk with it, as in the setup guide.
How often to save
where \(I\) is the save interval in steps and \(t_{\text{step}}\) the time of one step.
In words: a crash loses at most one save interval of work.
For our pretraining: \(200 \times 10.93\) s, about 36 minutes at most. Each save took 44.6–54.3 s, about 1.8 GB/s to our network volume, so 7 saves took about 6 minutes in all.
The time limit is a second safety net: at --exit-duration-in-mins, Megatron saves and exits.
On the rehearsal, a two-minute limit printed “exiting program after 2.003 minutes” at iteration 90, after saving it.
Resume a run
Pretraining
Relaunch the same command with the same CKPT_DIR: --load and --save point at the same folder, so Megatron loads
the latest save.
The rehearsal tested it on the shrunk model, appending to the rehearsal’s EXTRA_ARGS:
EXTRA_ARGS+=" --save-interval 20 --exit-interval 40"
run r_pre bash $M/moe_pretrain.sh # saves at 20 and 40, stops at 40
run r_pre bash $M/moe_pretrain.sh # the same again: it resumes
Expect: the second launch logs “loaded … at iteration 40” and logs iteration 41 first. Ours then saved at 60 and
80 and stopped at 80.
To shorten a run partway, restart from a checkpoint with a lower TRAIN_SAMPLES and --override-opt_param-scheduler.
With WSD, only the final decay moves.
RL
Stop the run and relaunch it with the same settings and the same RUN_DIR. It resumes from its checkpoint and from
curriculum_state.json, which the agent writes every step.
gspo.sh has no --finetune on purpose. On the first launch --load is empty, so Megatron starts from the SFT
checkpoint by itself; after that, it resumes the iteration, optimizer and random-number state.
An RL checkpoint must hold everything a restart needs:
- the weights in fp32: an fp16 step near a weight of 0.02 is about 1.5e-5, larger than a typical RL weight change, so an fp16 save can round most of the RL update away;
- the optimizer state, or a restart behaves like a fresh start;
- the curriculum state, and the random-number state with the data cursor.
Test the restart once. Run GSPO twice from the same SFT weights and seed: A straight through, and B stopped at a save and relaunched. Then compare them after the restart:
python -I code/scripts/restart_check.py /workspace/runs/r_rs_a /workspace/runs/r_rs_b --resume-at 8
On the rehearsal, B resumed at iteration 8 and logged iterations 9–12. The largest loss difference was 6.33e-6 and the largest gradient-norm difference 0.447. The rollouts after the restart differed, so only the resume itself is judged; the statistics are reported.
Make a weights-only copy
Megatron’s checkpoint conversion loads a checkpoint, saves it in the format you ask for, and exits without training.
# --no-load-optim/--no-load-rng too: without them Megatron still restores the optimizer from the source checkpoint,
# and the state dict built under --no-save-optim has none (KeyError 'optimizer').
EXP="--ckpt-convert-format torch_dist --no-save-optim --no-save-rng --no-load-optim --no-load-rng --ckpt-convert-save"
EXTRA_ARGS="$EXP /workspace/weights/pretrain" CKPT_DIR=/workspace/ckpt/pretrain run export_pretrain bash $M/moe_pretrain.sh
EXTRA_ARGS="$EXP /workspace/weights/gspo" GSPO_LR=1e-6 SFT_CKPT=/workspace/ckpt/sft CKPT_DIR=/workspace/ckpt/gspo \
run export_gspo bash $M/gspo.sh
unset EXTRA_ARGS
SFT needs no copy: sft.sh already saves weights only. The GSPO copy holds the bf16 weights every forward pass used;
its fp32 main weights are not kept.
eval.sh loads such a copy directly.
Expect: our pretrained copy had 15 files and 13,743,073,344 bytes; the GSPO copy 16 files and 13,743,074,481 bytes, written in 100 s. On the shrunk rehearsal model, the copy was 165 MB against the full checkpoint’s 1,000 MB.
Before you delete old full checkpoints, save what lives only in them: the router’s bias at each save, and the expert counts. The pretraining guide has the two commands.
Check a copy by checksum
Write the SHA-256 of every file you keep, on the machine that made them:
find /workspace/weights /workspace/ckpt/sft -type f -exec sha256sum {} + > /workspace/runs/weights_sha256.txt
Then check every copy against that list before the originals go: on the destination, sha256sum -c with the paths
adjusted. Compare the file count and the total bytes as well.
What I checked at the end of our runs:
-
The main run: the SHA-256 of all 166 weights files; every model folder on Hugging Face file by file, the large files by SHA-256 and the small ones by git blob hash; the local copy against the machine’s file listing.
-
The control run: every file of the copy by checksum, with a dry-run rsync that compares content (
-c -n -i), and the final weights by SHA-256 on both ends.
A slow link changes the plan, not the check. The control run’s copy ran at 3.2 MB/s, so the update-100 weights were copied while the last evaluations ran.
Check that the saved weights are the model you evaluated
An evaluation inside a run uses the weights in memory. Evaluate the saved files on their own and compare, on the same problems:
python3 code/scripts/analyze_control.py eval <runs>/control_gspo/eval_results.jsonl \
<runs>/control_final_sets/eval_results.jsonl --before-eval 2
| Comparison (dev split, greedy, 166 problems) | Accuracy | Answers changed | Identical texts |
|---|---|---|---|
| the saved update-100 weights against the run’s own evaluation | 67.47% against 66.87% | 9 | 75 |
| the run’s evaluation against its repeat, the same weights in memory | 66.87% against 67.47% | 5 | 63 |
The saved checkpoint agreed with the run as closely as two evaluations of the same weights did, so it is the model the run evaluated. Expect some differences even then: greedy answers depend on how the batches are composed. On the laptop, with fp32 weights and a fixed evaluation seed, a saved model reproduced its in-run evaluation exactly: 0 of 200 problems differed.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| the RL restart loads its own checkpoint “at iteration 0” and overwrites the tracker (61 → 13) | --finetune on every launch |
no --finetune; check_flags.py refuses it with --load equal to --save |
KeyError: 'optimizer' in the weights-only copy |
Megatron restores the optimizer unless told not to | --no-load-optim --no-load-rng |
| an evaluation of a wrong path reports loss 11.85 and exits 0 | Megatron started from random weights | --exit-on-missing-checkpoint on every load |
| each 40-step study arm would write ~110 GB and the next arm would start from its weights (found in the code, before any run) | Megatron also saves at the exit interval, and the arms shared --load |
weights-only saves in each arm’s own folder |
| a calibration run would write a full checkpoint at its exit (found in the code) | Megatron saves at the exit when --save is set |
calibration mode sets no --save |
| the run stops after a save on 8 GPUs: “Path is not a file” | Megatron’s W&B checkpoint hook raced the tracker file | our patch waits for the file and never stops training |
| a reloaded RL model would score like the pre-RL model (a prediction, never measured) | an fp16 save rounds away an update smaller than half an fp16 step | save fp32 |
Read more
- Part 5: numerics and reproducibility explains the fp16, bf16 and fp32 traps behind these rules.
- Code: code/scripts/megatron/common.sh, code/scripts/megatron/gspo.sh, code/scripts/restart_check.py, code/scripts/checkpoint_router_bias.py, code/scripts/analyze_control.py.