nanoGPT from Scratch
A character-level GPT built from scratch in PyTorch, following the core ideas behind the GPT architecture. The model is assembled from PyTorch primitives, without a transformer library.
- PyTorch
- Self-attention
- Multi-head attention
- Causal masking
- Positional embeddings
- Next-token prediction
Reaches 1.77 training and 1.90 validation loss on Shakespeare text. An early loss of 0.06 was too good to be true: it came from three bugs, one of them a missing causal mask.