3.3.7 · D1Deep Learning Frameworks

Foundations — Saving and loading models (checkpoints)

1,821 words8 min readBack to topic

Before you can understand why a checkpoint saves weights, optimizer state, and an epoch number, you need to know what each of those words means as a picture. This page builds every symbol the parent note uses, starting from absolutely nothing.


1. What is a "parameter"? (the number you tune)

Imagine a machine with thousands of tiny knobs. Each knob is one number. Turn the knobs the right way and the machine's guesses get better. Those knobs are the parameters.

The two families of parameters you'll see:

  • Weight — written (bold, capital). It scales an input: "how strongly does this input matter?"
  • Bias — written (bold, lowercase). It shifts the result: "start from here regardless of input."

Look at the figure: each cell of the grid is one weight. The whole grid is . Saving a checkpoint means writing every one of these cell values to disk.


2. What does one layer compute? (the formula that uses W and b)

A layer takes an input list of numbers , multiplies by weights, adds the bias:

Read it in plain words:

  • — the input numbers coming in (e.g. the 784 pixel values of a small image).
  • — combine those inputs, each weighted by how much it matters.
  • — shift the total.
  • — the output numbers going to the next layer.

Why this is the atom of everything: the parent note's nn.Linear(784, 256) is exactly this formula with a weight grid and a length-256 bias . When we "save the model," we are saving all the and from every such layer.


3. What is "loss"? (the score we want to lower)

Picture a landscape where your horizontal position is set by the parameters and your height is the loss. Low ground = good model, high ground = bad model. Training is walking downhill.

The symbol (fancy curly L) is just a name for "the error score." We say depends on the parameters because moving the parameters moves you across the landscape and changes your height.


4. What is ? (all the knobs, bundled)

Why invent a bundling symbol? Writing "update " is exhausting. lets us say "update the whole model" in one letter. Your position on the loss landscape is ; your height is .


5. What is a gradient ? (which way is downhill)

You are standing on the loss hill. You want to step down. Which direction is down?

The upside-down triangle ("nabla") is just notation meaning "the slope-arrow of." The subscript says "slope with respect to the knobs."

In the figure the red arrow is (points uphill). We always step along the green arrow, its negative — downhill.


6. The learning rate (how big a step)

Knowing the downhill direction isn't enough — how far do you step?

One full downhill step is the core rule of training:

Plain reading: "new knobs = old knobs, moved a little () in the downhill direction ()." The learning rate can even change over training — that whole subject is Learning Rate Schedules.


7. Momentum and velocity (why the past matters)

Plain gradient descent forgets everything except the current slope. But a smart walker builds up speed in a consistently downhill direction — like a ball rolling into a valley.

Reading each piece:

  • (beta) — the momentum coefficient, usually . It says "keep 90% of my old velocity, mix in 10% of the new slope."
  • — the velocity from the previous step (the accumulated inertia).
  • The step now moves along , not the raw gradient — so a steady direction builds up speed.

How long to rebuild lost momentum? Roughly steps. For that is steps of wasted stumbling. Adam's and buffers in the parent note are the same idea — extra memory the optimizer carries.


8. Epoch and step (where you are in the journey)

Picture a bookshelf. Reading one page = one step. Finishing the whole book = one epoch. Re-reading the book = the next epoch.

Why save the epoch number? So "future you" knows to resume at epoch 8 instead of restarting at epoch 0. That's the parent note's start_epoch = checkpoint['epoch'] + 1.


9. Serialization: turning memory into a file

Everything above lives in your computer's RAM (temporary). A file on disk is permanent.

PyTorch's torch.save does this via Python's pickle; TensorFlow writes binary weight files. A state dict (parent note) is just a Python dictionary: {layer name → tensor of numbers}. Saving it = writing that dictionary to disk.


Prerequisite map

Parameter W and b

Layer output y = Wx + b

Loss L, the error score

Gradient, downhill direction

Learning rate alpha, step size

Gradient descent step

Momentum velocity v

Bundle theta, all knobs

Optimizer state

Step and Epoch counter

Serialization to disk

Checkpoint file

Saving and loading models

Each foundation feeds the next; together they explain why a checkpoint must hold parameters + optimizer state + epoch number, which is the heart of the parent topic. These same foundations power Transfer Learning (reload old weights) and Model Deployment (ship the best checkpoint).


Equipment checklist

Self-test: can you answer each before revealing?

What does a bold represent, as a picture?
A grid (tensor) of weight numbers for a layer — thousands of tunable knobs at once.
In , what does adding do geometrically?
It shifts the output up or down, independent of the input.
What is the loss in one sentence?
A single number measuring how wrong the model's predictions are; training minimizes it.
What does the symbol bundle together?
Every parameter (all 's and 's) of the whole model into one name.
Which direction does point, and which way do we step?
It points uphill (steepest increase); we step along , downhill.
What does the learning rate control?
The size of each downhill step.
What does the velocity store, and where does it live?
A running average of recent gradients (inertia); it lives inside the optimizer, not the model.
Why must the optimizer state be checkpointed, not just the weights?
Reloading without it resets to zero, losing accumulated momentum and slowing convergence.
Roughly how many steps to rebuild momentum for ?
About steps.
What is serialization?
Turning in-memory objects into bytes on disk so they can be reloaded exactly later.

Recall Quick self-check

A checkpoint stores parameters, optimizer state, and epoch. Which one, if omitted, still lets you deploy the model but not smoothly resume training? ::: The optimizer state — deployment only needs the parameters, but resuming training needs the momentum buffers too.