Let's Reproduce GPT-2 (124M): Distributed PyTorch, FlashAttention & FineWeb
Four-hour systems-and-ML tour de force: reproduces OpenAI's GPT-2 (124M) from an empty file, optimizing throughput 10x via BF16 tensor cores, torch.compile, FlashAttention, cosine decay, and multi-GPU DDP.
We reproduce the GPT-2 (124M) from scratch. This video covers the whole process: First we build the GPT-2 network, then we optimize its training to be really fast, then we set up the training run following the GPT-2 and GPT-3 paper and their hyperparameters, then we hit run, and come back the next morning to see our results, and enjoy some amusing model generations. Keep in mind that in some places this video builds on the knowledge from earlier videos in the Zero to Hero Playlist (see my channel). You could also see this video as building my nanoGPT repo, which by the end is about 90% similar.
Links:
- build-nanogpt GitHub repo, with all the changes in this video as individual commits: https://github.com/karpathy/build-nanogpt
Let's Build the GPT Tokenizer: Byte Pair Encoding & Unicode Internals
Next · Lecture 11Introduction to Large Language Models
