3.3.7 · D3Deep Learning Frameworks

Worked examples — Saving and loading models (checkpoints)

2,370 words11 min readBack to topic

This page is the "run every case" companion to the parent checkpoint note (its Hinglish twin). The parent told you what a checkpoint is and why the optimizer state matters. Here we do the opposite of theory: we hammer through every awkward situation a checkpoint can throw at you — resuming, exporting, momentum resets, disk-budget math, mismatched architectures — and we compute the actual numbers so you never get surprised at 3 a.m. when training crashes.

Before we start, one word we will use constantly, defined from zero:


The scenario matrix

Every checkpoint problem falls into one of these cells. The worked examples below are each tagged with the cell they cover, so by the end no cell is left dark.

Cell Situation What makes it tricky
A Resume mid-training (crash) Off-by-one on the epoch counter
B Momentum reset (save weights only) Velocity , slow rebuild
C Momentum preserved (full state) Training continues smoothly — the contrast case
D Export for inference (no optimizer) Smaller file, eval() mode, no state
E Degenerate: zero checkpoints on disk Fresh start, start_epoch = 0
F Limiting case: or How long momentum takes to rebuild
G Storage budget (word problem) Multiply out GB, does it fit the disk?
H Exam twist: architecture mismatch Shapes disagree → load fails, why

Cell E — the degenerate "nothing on disk yet" case

Start here because it is the boundary: what happens when there is nothing to resume from?


Cell A — resume after a crash (the off-by-one)


Cell B vs Cell C — the momentum reset, computed

This is the heart of the parent note's warning. We turn it into real numbers.

Figure — Saving and loading models (checkpoints)

Recall the momentum recurrence (every symbol defined below the formula):


Cell F — the limiting cases of


Cell G — the storage-budget word problem

Figure — Saving and loading models (checkpoints)

Cell D — export for inference (drop the optimizer)


Cell H — exam twist: architecture mismatch



Recall

Recall Why resume at

epoch + 1, not epoch? Because the stored counter is the epoch we finished; the next unfinished one is one higher. Resuming at epoch + 1 avoids repeating work ::: it starts the loop at the first epoch never run.

Recall After saving weights only, what is the first velocity vs cruising velocity (β=0.9, constant g=1)?

First velocity ::: , which is of the cruising velocity — momentum must rebuild over ~10 steps.

Recall 500M params, Adam, 4 bytes each, every epoch, 100 epochs — total storage?

::: (12 bytes = weight + + ).

Recall Why does inference-only export shrink an Adam checkpoint by 3×?

Adam stores 3 numbers per parameter (weight, , ) ::: inference keeps only the weight, so .

Recall Rebuild time for momentum when β = 0.99?

steps ::: heavier momentum is far more costly to lose.