Saving and Loading Model Weights
Training a large language model is a long process, and a training run does not always finish in one sitting.
Training That Does Not Finish in One Sitting
Training a large language model is a long process, and a training run does not always finish in one sitting. Instead of treating each session as a fresh start, the work already done can be stored and picked up again later. That is the job of saving and loading model weights. This article follows the weights through that process and asks a simple question: when you stop training and come back later, what has to survive the break, and what has to be restored before training can carry on from where it left off?
Answering that question depends on being able to read a training run in the first place. Once an LLM has been trained, the natural first question is whether the training worked. One way to answer it is to look at the loss values recorded during training. The sections that follow start with those raw numbers, predict where the curves go, and then explain why they behave the way they do.
Reading Training and Validation Loss Together
Training loss measures fit on the training data. Validation loss measures fit on held-out data. Both are recorded at the same stages of training, which is what makes them comparable when plotted together.
The loss is a single number that summarizes how far the model's predictions are from the text it was supposed to produce. A lower number generally means the model is doing better on the data it was measured against. The trouble is that a model can look excellent on the data it practiced on while being poor at everything else. Reading two loss numbers side by side, instead of one, is how you tell these situations apart. The training loss tells you how well the model fits the material it sees. The validation loss tells you whether that fit carries over to material it has not practiced on.
What do you think happens?
In the source run, the training loss starts at 9.781 and the validation loss starts at 9.933. Based on the description so far, do you expect the validation loss to finish lower than the training loss, or higher?
Reveal answer
Validation loss finishes higher than training loss.
Both losses decrease over the run, but the validation loss never gets as small as the training loss. It sits at 6.452 after the 10th epoch, while the training loss falls to 0.391 by the end of training.
Notice how the model behaved at the start of that run. The source describes it as only able to append commas to the starting context or repeat a word, which is consistent with a very high loss. By the end, the same model produces grammatically correct text. The falling training loss tracks that improvement in language skill.
Where the Two Curves Split Apart
Early in the run, both losses fall sharply together. That shared drop is a healthy sign: the model is picking up patterns that help on the training text and on the held-out text alike. The picture changes after the second epoch. The training loss keeps going down, while the validation loss stagnates. The divergence is the signal to read carefully. The validation loss stays much larger than the training loss, and that gap is evidence that the model is fitting something specific to the training data rather than a general pattern.
Overfitting is what happens when a model memorizes its training data rather than generalizing from it. When the validation loss stagnates while the training loss keeps falling, the divergence between the two indicates overfitting.
The source does not leave the diagnosis to the loss curves alone. It checks memorization directly by searching the generated output for snippets that appear verbatim in the training text file, such as a passage about the irony in a story. Finding those exact passages in the generated text confirms that the model is reproducing what it saw rather than producing new language.
Why Memorization Happens in This Setup
The source explains why memorization occurs in this particular setup. The training dataset is very small and the model is trained for many epochs, which makes memorization expected. In practice, training is usually done on a much larger dataset for only one epoch, which leaves less room for verbatim recall. The source also notes that the overfitting does not occur when the model is trained on a much larger public domain corpus of 60,000 books, and it points readers to an appendix for details.
Reading the numbers from one run
Given the source run's recorded values, decide where the run stops generalizing and what the two losses say about the model at the end.
- 1Record the starting values
Training loss starts at 9.781 and validation loss starts at 9.933. The two losses begin close together and both are high, which matches a model that cannot yet produce coherent text.
- 2Watch the early shared drop
Both losses fall together during the first epochs. Because the held-out loss drops alongside the training loss, the pattern being learned helps on both sets of text.
- 3Find the divergence point
Past the second epoch, the training loss keeps falling while the validation loss stagnates. This is the point where the run stops generalizing and starts memorizing.
- 4Check the endpoints
At the end, the training loss is 0.391, while the validation loss sits at 6.452 after the 10th epoch. The validation loss never gets as small as the training loss.
- 5Confirm with the generated text
Verbatim passages from the training file appearing in the generated output confirm that the model is reproducing its training text rather than producing new language.
The run learned general language skill early on, then began memorizing its small training set after the second epoch. The growing gap between the two losses is the evidence for that conclusion.
Saving Weights to Storage
Saving model weights stores the learned values of a model so that they can be used later. Saving is the act of writing the current weights to storage.
Saving exists because training is not always a single continuous session. The purpose the source gives for saving and loading is the same: they are used to continue training an LLM rather than starting over. The work done so far is stored so that it can be picked up later. Saving on its own only stores that progress; it does not put the progress back to work.
Loading Weights to Resume Training
Loading model weights reads previously saved weights back in, so the model starts from that saved state rather than from scratch.
Loading is the reverse of saving. A load is only meaningful when there is a saved set of weights to restore. Saving and loading are therefore best understood as a pair: a save without a later load stores progress without putting it back to work, and a load without a prior save has nothing to restore. Together they let training continue from where it left off.
Mistakes That Make a Resumed Run Start Over
Common mistake Saving the weights but never loading them
What it looks likeA script writes the weights to storage at the end of a session, and the next session constructs a new model and begins training immediately.
Why it failsA save only stores progress. Without a load, the new session does not use the saved state, so the training behaves as if it started over.
Do this insteadAfter constructing the model, load the saved weights so the model starts from that stored state rather than from scratch.
Common mistake Loading before anything has been saved
What it looks likeA resume step tries to load weights from a location where no saved set of weights exists.
Why it failsA load only has meaning when there is a saved set of weights to restore. With nothing to read, there is no earlier state to return to.
Do this insteadConfirm that a saved set of weights exists before the load step runs, and treat a missing save as the start of a new run.
Common mistake Reading only one loss number when judging the run
What it looks likeA learner sees the training loss fall to 0.391 and concludes the model is doing well everywhere.
Why it failsThe training loss measures fit on the material the model sees. The validation loss, which was 6.452 after the 10th epoch in the source run, shows whether that fit carries over.
Do this insteadRead the training and validation losses together, and treat a widening gap after the point of divergence as a sign of overfitting.
Common mistake Assuming a resumed run is automatically identical to an uninterrupted one without checking what was saved
Trace the Weights Through a Save and a Load
A training session ends with the weights written to storage. The next session constructs a fresh model and begins training without loading anything. Trace the state of the weights: where they are before the save, where they are after the save, and what the new session is actually starting from. Then say what single step would fix the restart.
Hints
- Start by naming the place the learned values live during training.
- Ask whether writing to storage changes the model that is already in memory, and whether the new session reads anything from storage.
- The fix is the operation that reads previously saved weights back into the model.
Key Takeaways
- Training loss measures fit on training data, and validation loss measures fit on held-out data; reading both together reveals whether learning generalizes.
- In the source run, both losses fall together early on, then diverge after the second epoch as the validation loss stagnates and the training loss keeps falling. That divergence is the signal of overfitting and memorization.
- Saving writes the learned weights to storage so they can be used later, and loading reads them back so the model starts from that saved state rather than from scratch.
- Saving and loading work as a pair: a save alone stores progress, and a load is only meaningful when there is a saved set of weights to restore, which is how training continues instead of restarting.
- A resumed run that behaves as if it started over usually has a missing load step, a load with nothing saved, or incomplete assumptions about what was saved.