Wiki
Extending a context window from 4K to 128K takes three fixes: RoPE extensions (PI, NTK-aware scaling, YaRN) for unseen positions, staged continued training on long text, and a budget for attention compute and KV cache. This page covers all three with formulas, code and two interactive tools.
Advanced 40 min read
Entropy measures how surprising a distribution is on average, cross-entropy is the cost of coding data from p with a code built for q, and KL divergence is the excess over the optimum. A language model's training loss is cross-entropy; perplexity is its exponential.
Intermediate 11 min read
Language modeling estimates the probability of a text and uses the chain rule to split it into a product of "predict the next token given the prefix"; training uses cross-entropy, evaluation uses perplexity, and the causal mask hides future tokens.
Beginner 13 min read
Large-model pretraining almost always uses AdamW with linear warmup plus cosine (or WSD) decay, gradient clipping and mixed precision. This page explains what each hyperparameter is for and gives a checklist for loss spikes and NaNs.
Intermediate 15 min read
How many FLOPs, GPU hours and bytes of memory does training a model need? This page works out where 6ND comes from, what MFU measures, why model states cost 16 bytes per parameter, how activation memory scales, and how to sanity-check reported GPU hours.
Intermediate 29 min read
A pretraining corpus is filtered, deduplicated and mixed step by step, and every step throws data away. This page shows what FineWeb, Gopher, DCLM and Llama 3 drop and why, then runs MinHash near-duplicate removal on a demo corpus: how many words may change before a copy stops counting.
Intermediate 52 min read
Data parallelism splits the batch, tensor parallelism the matrices inside a layer, pipeline parallelism the stack of layers; ZeRO and FSDP shard optimizer state, gradients and parameters. Runnable checks verify gradient averaging, ring all-reduce traffic, the Megatron split and the bubble formula.
Advanced 42 min read
From Kaplan to Chinchilla: why loss falls as a power law in parameters, data and compute, how to split a compute budget between parameters and tokens, and why today's models are trained on far more data than the compute-optimal amount.
Intermediate 20 min read
A map of the pipeline from data preparation, pretraining, SFT and preference alignment to evaluation and release, with the public data scale of each stage, plus a 0.86M-parameter byte-level GPT that trains on a laptop CPU to test data mixture, resuming and leakage.
Intermediate 34 min read
A large language model (LLM) is a neural network, usually a Transformer, trained on huge amounts of text to predict the next token; pre-training, post-training and inference decoding turn it into an assistant that can chat, write code and reason.
Beginner 13 min read
A GPU is limited by two walls: how many operations it can do per second (compute) and how many bytes it can move per second (memory bandwidth). The roofline model uses arithmetic intensity to tell which wall an operator hits first. This page derives it and measures it on a CPU.
Intermediate 41 min read
GPU kernel tuning combines thread-level memory access, on-chip reuse, and output stores. Derive the logical traffic of tiled matrix multiplication with edge masks, check it with a CPU experiment, and trace practical limits from staging buffers to register spills.
Intermediate 9 min read
Floating-point formats split a few bits between exponent (range) and mantissa (precision). Low-precision training fails in three ways: overflow, underflow (small gradients become 0) and swamping (small terms vanish in sums). Real Qwen2.5-0.5B data shows how large each is and what fixes it.
Intermediate 31 min read