LLM Library
How large language models work, and what is inside the famous ones
32 short lessons, from tokenisation and attention to mixture of experts, KV caches and reasoning models, each with an animation. Then 28 models from BERT to the latest open and closed families, with their architecture drawn out layer by layer.
Specifications come from each model's paper or model card. When a lab has not published a detail, the page says so. New models arrive quickly, so check the official model card for the newest numbers.
01Foundations
What a language model is and how text becomes numbers.
- What is a Large Language Model?AnimatedA neural network trained to predict the next piece of text.
- Tokens and TokenizersAnimatedText is cut into sub-word pieces before the model sees it.
- EmbeddingsAnimatedEach token becomes a vector of numbers that captures meaning.
- Positional Encoding and RoPEAnimatedTelling the model the order of the tokens.
02Inside the Transformer
Attention, experts and the layers every modern model is built from.
- Self-AttentionAnimatedEach token gathers information from the other tokens.
- Causal MaskingAnimatedA mask that hides future tokens during training and generation.
- Multi-Head AttentionAnimatedSeveral attention patterns computed in parallel.
- Sharing Keys and Values: MQA, GQA and MLAAnimatedCut the KV cache by sharing keys and values between heads.
- The Transformer BlockAnimatedAttention plus a feed-forward network, wrapped in norms and shortcuts.
- Feed-Forward Layers and ResidualsAnimatedThe per-token network and the shortcuts that make deep stacks train.
- Mixture of ExpertsAnimatedMany expert networks, but only a few run for each token.
- Sliding Window and Local-Global AttentionAnimatedLet most layers look only nearby to save memory.
- State-Space Models and HybridsAnimatedA different way to read sequences with linear cost.
- Encoder, Decoder and Encoder-Decoder ModelsAnimatedThree ways to arrange a transformer.
03Training
How a pile of random weights becomes a useful assistant.
- Pretraining: Predicting the Next TokenAnimatedThe first and most expensive training stage.
- Scaling LawsPerformance improves predictably with more parameters, data and compute.
- Post-Training: SFT, RLHF and DPOTurning a base model into an assistant.
- Reasoning Models and RL with Verifiable RewardsModels trained to think before answering.
- Fine-Tuning with LoRAAdapting a big model by training a few small matrices.
- QuantisationStoring weights with fewer bits.
04Running and Using LLMs
Decoding, serving, retrieval, agents and the limits of the technology.
- Decoding and SamplingAnimatedHow the next token is chosen from the probabilities.
- Prefill and DecodeAnimatedThe two phases of answering a prompt.
- The KV CacheAnimatedRemembering the keys and values of earlier tokens.
- Continuous BatchingAnimatedKeeping the GPU busy by swapping requests in and out every step.
- Speculative DecodingAnimatedA small model guesses ahead and a big model checks.
- Retrieval-Augmented GenerationAnimatedGive the model relevant documents before it answers.
- Tool Use and AgentsAnimatedModels that call functions and act in steps.
- Context Windows and Long ContextAnimatedHow much text the model can consider at once.
- Multimodal ModelsAnimatedModels that understand images, audio and video as well as text.
- Evaluating LLMsAnimatedHow we measure whether a model is any good.
- Hallucinations and SafetyAnimatedWhy models make things up and how they are made safer.
- Open-Weight and Closed ModelsWho can download and run the model.