Building Large Language Models
- 29Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a language model at a high level?
A model of a probability distribution over sequences of tokens (words or subwords). It assigns a probability to each possible sequence, e.g., P(the mouse ate the cheese).
Or swipe the card
29 cards
What is a language model at a high level?
A model of a probability distribution over sequences of tokens (words or subwords). It assigns a probability to each possible sequence, e.g., P(the mouse ate the cheese).
What is the autoregressive decomposition for a language model?
P(x1,x2,…,xL)=P(x1)⋅P(x2∣x1)⋅P(x3∣x1,x2)⋯P(xL∣x1,…,xL−1)
What is the training objective for an autoregressive language model?
Minimize the cross-entropy loss between the predicted next-token distribution and the one-hot encoding of the actual next token. This is equivalent to maximizing the log-likelihood of the training text.
What are the two reasons why tokens (subwords) are used instead of words or characters?
- Generalization: Tokens handle typos, rare words, and languages without spaces (e.g., Thai) better than words. 2. Sequence length: Characters produce very long sequences, and Transformer complexity grows quadratically with length.
Describe how Byte Pair Encoding (BPE) tokenization works.
Start with a large corpus and assign each distinct character its own token. Then repeatedly find the most frequent adjacent pair of tokens and merge them into a new token. Stop when a desired vocabulary size is reached. The final token set includes both characters and merged subwords.
What is a major drawback of tokenization for math and code?
Numbers and code patterns (like spaces) are not tokenized as humans interpret them. For example, '327' might be a single token, preventing the model from generalizing arithmetic compositionally.
What is perplexity and how is it computed?
Perplexity is 2average negative log-likelihood per token. For a sequence with loss L, perplexity = exp(L1∑t=1L−logP(tokent∣context<t)).
What are the minimum and maximum possible perplexity values?
Minimum: 1 (when the model is perfectly certain). Maximum: the vocabulary size (when the model predicts uniformly over all tokens).
What do scaling laws for language models show?
Scaling laws show that increasing compute, data, or model size leads to predictable decreases in test loss, following a power law (linear on log-log scale). More data and larger models always improve performance monotonically.
According to the Chinchilla scaling law, what is the optimal number of training tokens per model parameter?
20 tokens per parameter for compute-optimal training (minimum loss given fixed compute).
How do scaling laws help choose between architectures (e.g., Transformers vs. LSTMs)?
Train both architectures at multiple smaller scales, fit scaling laws, and extrapolate to larger compute. The architecture with better extrapolated performance (lower loss at high compute) wins.
List the major steps in processing web-crawled data for LLM pre-training.
- Extract text from HTML. 2. Remove boilerplate (headers, footers). 3. Filter undesirable content (NSFW, hate, PII). 4. Deduplicate (near-duplicate documents, repeated paragraphs). 5. Heuristic filtering (outlier token distributions, short/long docs). 6. Model-based filtering (classifier trained on Wikipedia-linked pages). 7. Domain classification and up/down-weighting (e.g., boost code, reduce entertainment). 8. Final high-quality data overfitting (e.g., Wikipedia at end of training).
What is Common Crawl and why is it used?
Common Crawl is a publicly available web crawl that contains about 250 billion pages (~1 petabyte). It is the starting source for most LLM pre-training data.
How has the amount of pre-training data evolved from early models to current state-of-the-art?
From ~150 billion tokens (~800 GB) to ~15 trillion tokens today, an increase of about 100x.
Why is post-training (alignment) needed for LLMs?
Pre-trained language models model the distribution of internet text, which is not instruction-following. For example, a question may be followed by another question rather than an answer. Post-training teaches the model to behave as an AI assistant: follow instructions and avoid harmful outputs.
What is supervised fine-tuning (SFT) for LLMs?
Fine-tuning the pre-trained model on human-written instruction-response pairs using the same language modeling loss (next-token prediction) but only on the desired responses.
According to the LIMA paper, how much SFT data is sufficient?
As few as 2,000 high-quality examples, with little improvement beyond 32,000 examples. Scaling laws do not hold for SFT.
Describe the three-step RLHF pipeline used for models like ChatGPT.
- Supervised fine-tuning (SFT) on human demonstrations. 2. Train a reward model on human preferences (which of two outputs is better). 3. Fine-tune the SFT model using reinforcement learning (PPO) to maximize the reward model's score, with regularization to avoid over-optimization.
What is the reward model in RLHF and how is it trained?
A classifier (often another LLM) that takes an input-output pair and outputs a scalar reward. It is trained on human preference data using a Bradley-Terry model: P(output A≻output B)=exp(r(x,yA))+exp(r(x,yB))exp(r(x,yA)).
How does Direct Preference Optimization (DPO) simplify RLHF?
DPO directly optimizes the policy (LLM) to increase likelihood of preferred outputs and decrease likelihood of dispreferred outputs, without training a separate reward model. It uses a loss function that is equivalent to the RLHF objective under the Bradley-Terry model.
How was synthetic data used in the Alpaca model?
Starting from 175 human-written instruction-response pairs, the authors used a stronger LLM (GPT-3) to generate 52,000 additional examples. Then they fine-tuned Llama 7B with SFT on this synthetic dataset.
What are the main challenges of using human annotators for RLHF data?
- Slow and expensive. 2. Hard to focus on correctness (annotators often attend to length or style). 3. Annotator distribution shift (crowdsourced vs. target users). 4. Ethical concerns (low pay, exposure to toxic content).
How does using LLMs as judges for preference data compare to humans in cost and agreement?
LLMs are about 50x cheaper (e.g., 0.3vs300 per 1000 examples) and can achieve higher agreement with the majority human vote than humans themselves (e.g., 70% vs 66%).
What is Chatbot Arena and how does it rank LLMs?
Chatbot Arena is a platform where random users chat with two anonymous models and vote which response is better. Over hundreds of thousands of votes, a ranking is derived (e.g., Elo scores).
What is the length bias in LLM evaluation and how can it be mitigated?
Both humans and LLM judges prefer longer outputs. For LLM judges, this bias can be controlled using regression analysis (e.g., controlling for length) or calibration techniques. Without correction, verbose prompts can inflate a model's win rate by over 10%.
Why is perplexity not suitable for evaluating aligned models (post-RLHF)?
Aligned models are trained to maximize reward (preference) rather than likelihood, so they are not language models in the traditional sense. Their outputs are not calibrated to the true data distribution; perplexity may be artificially high or low and not reflect quality.
What is Model FLOP Utilization (MFU) and what is a typical good value?
MFU is the ratio of observed throughput (FLOPs per second) to the theoretical peak FLOPs of the hardware. A good MFU is around 50% (e.g., Llama 3 achieved ~45%).
Why is low-precision training used for LLMs?
Using 16-bit floats reduces memory usage and communication, speeding up training. Since deep learning is robust to noise, small weight updates in 16-bit are sufficient for forward/backward passes, while weights are stored and updated in 32-bit to preserve precision (mixed precision).
What is operator fusion and why does it improve performance?
Operator fusion combines multiple sequential operations (e.g., two consecutive cosines) into a single kernel, loading data from global memory once, executing all operations, and writing back once. This avoids repeated memory transfers that are a bottleneck.

Ask anything
We've read this whole study set, so questions about it get the best answers.