Overview
A hands-on guide to building a ChatGPT-like large language model from scratch in PyTorch. It breaks the transformer into small, understandable parts and explains each one step by step, starting from how an LLM predicts one token at a time and appends it to the context for the next prediction.
Each component lives in its own Jupyter notebook: tokenization, token and positional embeddings, self-attention, masked multi-head attention, feedforward networks, residual connections, layer normalization, the transformer block and full GPT model, cross-entropy loss, training and text generation, and finally quantization.