What did Andrej Karpathy say about checkpointing and resuming training during GPT-2 reproduction?

Andrej Karpathy said checkpointing is useful because it lets you save the model and evaluate it later. If you want to resume training exactly, you also need the optimizer state, including Adam’s moment buffers, plus careful handling of RNG seeds and other training state. He framed it as an important practical detail for serious training workflows.

“Because remember that the optimizer has a few additional buffers because of ADAM, so it's got the m and v, and, uh, you need to also resume the optimizer properly. You have to be careful with your RNG seeds, uh, random number generators, and so on. So if you wanted to exactly be able to resume optimization, you have to think through the state of the training process. But if you just want to save the model, this is how you would do it. And one, one nice reason why you might want to do this is because you may want to evaluate the model a lot more carefully. So here we are only kind of like winging the hell swag eval, but you may want to use something, um, nicer like, for example, the Luther, uh, Luther evaluation hardness.”
— Andrej Karpathy, OpenAI / online talk, 2022-11 · at 3:54:20
Andrej Karpathy: Andrej Karpathy on GPT-2 Reproduction: Rebuilding 124M From Scratch

Key takeaways

  • Save the model if you want to evaluate it later or reuse it elsewhere.
  • To resume training exactly, save the optimizer state too.
  • Keep track of RNG and other training-state details if reproducibility matters.

Context

In his 2022 GPT-2 reproduction talk, he was showing how the training script logs validation loss and saves model checkpoints. The quote above is taken word for word from the recording's transcript.

In the transcript

…logging the validation loss every 5,000 steps, we're also going to save the checkpoint, which is really just the state dictionary of the model. And so checkpointing is nice just because, uh, you can save the model and later you can, uh, use it in some way. If you wanted to resume the optimization, then in addition to saving the model, we have to also save the optimizer state dict.

Because remember that the optimizer has a few additional buffers because of ADAM, so it's got the m and v, and, uh, you need to also resume the optimizer properly. You have to be careful with your RNG seeds, uh, random number generators, and so on. So if you wanted to exactly be able to resume optimization, you have to think through the state of the training process. But if you just want to save the model, this is how you would do it. And one, one nice reason why you might want to do this is because you may want to evaluate the model a lot more carefully. So here we are only kind of like winging the hell swag eval, but you may want to use something, um, nicer like, for example, the Luther, uh, Luther evaluation hardness.

Evaluation hardness, hardness. Um, so this is a way to also evaluate language models, and, um, so it's possible that, um, you may want to use basically different infrastructure to more thoroughly evaluate the models on different, um, evaluations and compare it to the opening GPT-2 model on many other, um, tasks like, for example, that involve math, code, or different languages and so on. So this is a nice…

Read the full transcript of OpenAI / online talk, 2022-11

Topics

More questions about Andrej Karpathy

All Andrej Karpathy answers · All Andrej Karpathy recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →