Language Models from Scratch
- 51Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why did the instructors create this course on building language models from scratch?
Why did the instructors create this course on building language models from scratch?
51 questions
- 1
Why did the instructors create this course on building language models from scratch?
- A
To enable fundamental research by ensuring researchers understand the full stack, because abstractions are leaky.
- B
To replace other NLP courses that focus only on prompting and fine-tuning.
- C
To compete with frontier labs by training a GPT-4 class model in class.
- D
To provide a simple way for students to prompt existing models more effectively.
Correct answer
ATo enable fundamental research by ensuring researchers understand the full stack, because abstractions are leaky.
Explanation
The lecture states that abstractions are leaky and that fundamental research requires co-designing across data, systems, and models. The course aims to enable that understanding.
- A
- 2
According to the lecture, what are the three types of knowledge the course can teach?
- A
Architecture, training, and deployment, with full coverage.
- B
Data curation, scaling laws, and alignment, each in depth.
- C
Mechanics, mindset, and intuitions, but intuitions can only be partially taught.
- D
Theory, programming, and evaluation, all fully covered.
Correct answer
CMechanics, mindset, and intuitions, but intuitions can only be partially taught.
Explanation
The lecture specifies mechanics (fully teachable), mindset (teachable), and intuitions (only partially teachable because small-scale results may not transfer to large scale).
- A
- 3
What does the plot showing attention vs. MLP flop fraction across model sizes illustrate?
- A
The ratio is constant for all transformer models.
- B
MLPs become less important as models scale up.
- C
Small models are not representative of large models in terms of where compute is spent.
- D
Attention always dominates compute regardless of model size.
Correct answer
CSmall models are not representative of large models in terms of where compute is spent.
Explanation
The lecture uses this plot as an example of how small-scale observations (attention and MLP flops comparable) differ from large-scale (MLPs dominate), showing that small models may mislead.
- A
- 4
What is the correct interpretation of the 'bitter lesson' according to the lecture?
- A
Hardware improvements are the only driver of progress.
- B
Scale alone is all that matters; algorithms are irrelevant.
- C
The lesson is that research is futile because scale always wins.
- D
Algorithms at scale matter; efficiency is crucial because it compounds with large compute budgets.
Correct answer
DAlgorithms at scale matter; efficiency is crucial because it compounds with large compute budgets.
Explanation
The lecture refutes the misconception that scale is all that matters, arguing that algorithmic efficiency is more important at larger scales due to cost constraints.
- A
- 5
What was a key limitation of Google's 2007 n-gram models compared to modern language models?
- A
They were trained on fewer tokens than GPT-3.
- B
They did not exhibit emergent behaviors like in-context learning.
- C
They used tokenization that was not reversible.
- D
They could only handle English text.
Correct answer
BThey did not exhibit emergent behaviors like in-context learning.
Explanation
The lecture notes that despite having more tokens than GPT-3, n-gram models lacked the interesting phenomena (like in-context learning) seen in modern LMs.
- A
- 6
Which of the following best describes the role of OpenAI in the development of language models?
- A
They were the first to train neural language models in 2003.
- B
They applied a scaling mindset and skilled engineering to create GPT-2 and GPT-3.
- C
They invented the transformer architecture in 2017.
- D
They released the first open-source language model with full weights and data.
Correct answer
BThey applied a scaling mindset and skilled engineering to create GPT-2 and GPT-3.
Explanation
The lecture credits OpenAI with taking existing ingredients and pushing scaling laws and engineering, leading to GPT-2 and GPT-3.
- A
- 7
What distinguishes an 'open source' language model from an 'open weight' model?
- A
Open source models are trained on public data, while open weight models use proprietary data.
- B
Open source models release both weights and data, while open weight models only release weights.
- C
Open source models are free to use, while open weight models require a license.
- D
Open source models have a smaller parameter count than open weight models.
Correct answer
BOpen source models release both weights and data, while open weight models only release weights.
Explanation
The lecture defines three levels: closed (no details), open weight (weights available, but lacking data details), and open source (both weights and data are released).
- A
- 8
What is the primary reason character-based tokenization is inefficient?
- A
The vocabulary size is large and many rare characters waste vocabulary slots.
- B
It produces sequences that are too short for effective training.
- C
It requires pre-tokenization with regular expressions.
- D
It cannot handle Unicode characters.
Correct answer
AThe vocabulary size is large and many rare characters waste vocabulary slots.
Explanation
The lecture explains that character-based tokenization assigns one token per code point, leading to a large vocabulary where rare characters are inefficiently allocated.
- A
- 9
What is the compression ratio of byte-based tokenization?
- A
It is variable depending on the text.
- B
1 byte per token, leading to long sequences.
- C
1.6 bytes per token, optimal for modern GPUs.
- D
1.5 bytes per token, similar to character-based.
Correct answer
B1 byte per token, leading to long sequences.
Explanation
The lecture states that byte-based tokenization has a compression ratio of 1 byte per token, which results in very long sequences.
- A
- 10
What is a key drawback of word-based tokenization?
- A
It produces an unbounded vocabulary and introduces UNK tokens for unseen words.
- B
It requires a large corpus to define the vocabulary.
- C
It cannot handle punctuation and spaces.
- D
It has poor compression ratio because words are often multi-byte.
Correct answer
AIt produces an unbounded vocabulary and introduces UNK tokens for unseen words.
Explanation
The lecture notes that word-based tokenization suffers from unseen words requiring an UNK token, making it problematic.
- A
- 11
In BPE tokenization, how is the vocabulary expanded?
- A
By repeatedly merging the most frequent adjacent pair of tokens and adding a new token to the vocabulary.
- B
By randomly splitting words into subwords.
- C
By appending tokens from a pre-defined list of common words.
- D
By adding all character n-grams from the corpus.
Correct answer
ABy repeatedly merging the most frequent adjacent pair of tokens and adding a new token to the vocabulary.
Explanation
The lecture describes BPE as starting with bytes and iteratively merging the most common pair, adding a new token ID for each merge.
- A
- 12
What is the initial vocabulary in the BPE algorithm described?
- A
An empty set that grows during training.
- B
All words from the corpus.
- C
All 256 byte values (0-255).
- D
All Unicode code points.
Correct answer
CAll 256 byte values (0-255).
Explanation
The lecture explains that BPE begins with each byte as a token, so the initial vocabulary consists of integers 0-255.
- A
- 13
What is the purpose of pre-tokenization in the GPT-2 tokenizer?
- A
To convert text to lowercase before applying BPE.
- B
To remove punctuation and spaces to reduce vocabulary size.
- C
To split text into segments using a regular expression, then run BPE within each segment.
- D
To encode the text as bytes before merging.
Correct answer
CTo split text into segments using a regular expression, then run BPE within each segment.
Explanation
The lecture mentions that GPT-2 uses a regex to break text into segments (like words and spaces) and then applies BPE on each segment for efficiency.
- A
- 14
What compression ratio does the GPT-2 tokenizer achieve according to the lecture?
- A
0.6 bytes per token.
- B
1.0 bytes per token.
- C
1.6 bytes per token.
- D
2.5 bytes per token.
Correct answer
C1.6 bytes per token.
Explanation
The lecture shows that for a sample string, the GPT-2 tokenizer yields approximately 1.6 bytes per token.
- A
- 15
How does encoding work in a trained BPE tokenizer?
- A
The input is converted to bytes and then compressed using Huffman coding.
- B
The input is processed through a neural network that predicts tokens.
- C
The merges are replayed in the order they were learned during training.
- D
The input is split by spaces and each word is mapped to its ID.
Correct answer
CThe merges are replayed in the order they were learned during training.
Explanation
The lecture describes encoding as replaying the learned merges in order on the byte sequence to produce token IDs.
- A
- 16
Why is the basic BPE encoding algorithm considered inefficient?
- A
It requires training a neural network for each tokenizer.
- B
It loops over all merges for each encoding, even those that are no longer relevant.
- C
It uses a recursive process that consumes too much memory.
- D
It cannot handle texts longer than a few hundred bytes.
Correct answer
BIt loops over all merges for each encoding, even those that are no longer relevant.
Explanation
The lecture notes that the naïve implementation loops over every merge, but optimization can skip merges that don't apply to the current sequence.
- A
- 17
What is the backbone architecture of most frontier language models today?
- A
A mixture of experts (MoE) without attention.
- B
The original transformer, with various improvements.
- C
A recurrent neural network (RNN) with attention.
- D
A state space model like Hyena.
Correct answer
BThe original transformer, with various improvements.
Explanation
The lecture states that the transformer is the backbone of essentially all frontier models, with many incremental improvements.
- A
- 18
Which activation function is mentioned as an improvement over ReLU in transformers?
- A
Tanh.
- B
SwiGLU.
- C
Sigmoid.
- D
GeLU.
Correct answer
BSwiGLU.
Explanation
The lecture specifically mentions SwiGLU as a non-linearity that was adopted after the Noam paper, noting it works well without a clear explanation.
- A
- 19
What type of positional embedding is commonly used in modern transformers?
- A
Learned absolute positional embeddings.
- B
Relative positional embeddings based on attention bias.
- C
Sinusoidal positional embeddings.
- D
Rotary positional embeddings (RoPE).
Correct answer
DRotary positional embeddings (RoPE).
Explanation
The lecture lists RoPE as one of the newer positional embeddings used in recent models.
- A
- 20
How does RMSNorm differ from LayerNorm?
- A
RMSNorm applies a learnable scale and bias, while LayerNorm does not.
- B
RMSNorm uses only the root mean square for normalization, without mean subtraction.
- C
RMSNorm is computationally more expensive but yields better performance.
- D
RMSNorm normalizes across the batch dimension instead of the feature dimension.
Correct answer
BRMSNorm uses only the root mean square for normalization, without mean subtraction.
Explanation
The lecture describes RMSNorm as similar to LayerNorm but simpler because it does not subtract the mean.
- A
- 21
What is a common approach to reduce the quadratic complexity of full attention?
- A
Use sliding window attention or linear attention variants.
- B
Train the model with fewer tokens.
- C
Replace attention with convolutional layers.
- D
Use a smaller model with fewer parameters.
Correct answer
AUse sliding window attention or linear attention variants.
Explanation
The lecture mentions that sliding window attention and linear attention are ways to avoid the quadratic blow-up.
- A
- 22
Which optimizer is most commonly used for training language models according to the lecture?
- A
SGD with momentum.
- B
Shampoo.
- C
RMSProp.
- D
AdamW.
Correct answer
DAdamW.
Explanation
The lecture states that AdamW (a variant of Adam) is still very prominent for training LMs.
- A
- 23
In assignment 1, what are students allowed to use for building the transformer?
- A
Only numpy and custom CUDA kernels.
- B
PyTorch, but not the built-in transformer module; only a specific set of allowed functions.
- C
Pre-built transformer layers from Hugging Face.
- D
Any deep learning framework including JAX and TensorFlow.
Correct answer
BPyTorch, but not the built-in transformer module; only a specific set of allowed functions.
Explanation
The lecture specifies that students can use PyTorch but cannot use the transformer implementation; there is a small list of allowed functions.
- A
- 24
What is the primary bottleneck in GPU computation according to the systems unit?
- A
The number of floating-point operations per second.
- B
The clock speed of the GPU cores.
- C
Data movement between memory and compute units.
- D
The size of the L2 cache.
Correct answer
CData movement between memory and compute units.
Explanation
The lecture uses the warehouse/factory analogy to emphasize that data movement is the main bottleneck.
- A
- 25
What programming framework does the course use for writing custom GPU kernels?
- A
Triton.
- B
CUDA C.
- C
OpenCL.
- D
PyTorch's built-in kernel compiler.
Correct answer
ATriton.
Explanation
The lecture explicitly states they will use Triton, developed by OpenAI, for kernel implementation.
- A
- 26
Why is autoregressive decoding memory-bound?
- A
Because the attention mechanism requires storing all previous keys and values.
- B
Because generating one token at a time does not saturate the GPU's compute, and data movement dominates.
- C
Because the model is too large to fit in GPU memory.
- D
Because the decoding process involves many matrix multiplications.
Correct answer
BBecause generating one token at a time does not saturate the GPU's compute, and data movement dominates.
Explanation
The lecture explains that during decode, the GPU is underutilized and constantly moving data, making it memory-bound.
- A
- 27
What is speculative decoding?
- A
Training a model to predict multiple future tokens at once.
- B
Using a smaller, cheaper model to generate candidate tokens that are then verified by the full model in parallel.
- C
Using beam search to explore multiple decoding paths.
- D
Skipping layers during inference to reduce computation.
Correct answer
BUsing a smaller, cheaper model to generate candidate tokens that are then verified by the full model in parallel.
Explanation
The lecture describes speculative decoding as a technique where a cheap model scouts ahead, and the full model accepts or rejects candidates in parallel.
- A
- 28
What is the difference between data parallelism and tensor parallelism?
- A
Data parallelism splits the model; tensor parallelism splits the data.
- B
Data parallelism splits data across GPUs; tensor parallelism splits the model parameters.
- C
Data parallelism is used for inference; tensor parallelism is for training.
- D
Data parallelism requires model duplication; tensor parallelism requires data duplication.
Correct answer
BData parallelism splits data across GPUs; tensor parallelism splits the model parameters.
Explanation
The lecture distinguishes data parallelism (data split) from model parallelism types like tensor parallelism (model split).
- A
- 29
What is an important practice emphasized in the systems unit?
- A
Fusing all operations into a single kernel.
- B
Benchmarking and profiling to identify bottlenecks.
- C
Training models with FP32 precision for accuracy.
- D
Always using the largest possible batch size.
Correct answer
BBenchmarking and profiling to identify bottlenecks.
Explanation
The lecture stresses the habit of benchmarking and profiling to understand performance.
- A
- 30
What is the prefill phase in inference?
- A
Generating the first token using a greedy search.
- B
Processing the entire prompt in parallel, similar to training.
- C
Warming up the GPU kernels before actual decoding.
- D
Prefetching the next batch of data from memory.
Correct answer
BProcessing the entire prompt in parallel, similar to training.
Explanation
The lecture defines prefill as taking the prompt and running it through the model in parallel, like training time.
- A
- 31
In assignment 2, what type of model parallelism will students implement?
- A
A baby version of model parallelism, not the full FSDP.
- B
Fully sharded data parallelism (FSDP) from scratch.
- C
No model parallelism; only data parallelism is required.
- D
Pipeline parallelism across multiple nodes.
Correct answer
AA baby version of model parallelism, not the full FSDP.
Explanation
The lecture says they will implement a baby version of model parallelism because full FSDP is too complicated.
- A
- 32
What is the fundamental trade-off captured by scaling laws?
- A
Training time versus inference time.
- B
Number of layers versus hidden dimension.
- C
Model size versus amount of training data given a fixed compute budget.
- D
Data quality versus data quantity.
Correct answer
CModel size versus amount of training data given a fixed compute budget.
Explanation
The lecture frames scaling laws as determining the optimal model size for a given compute budget, balancing params and tokens.
- A
- 33
What does 'chinchilla optimal' refer to?
- A
The optimal learning rate schedule for training large models.
- B
The ideal number of GPUs for distributed training.
- C
The optimal model size for a given compute budget, balancing parameters and training tokens.
- D
The best tokenization strategy for a given dataset.
Correct answer
CThe optimal model size for a given compute budget, balancing parameters and training tokens.
Explanation
The lecture mentions chimpanzee (chinchilla) optimal as referring to the compute-optimal training setup.
- A
- 34
According to the rule of thumb derived from scaling laws, how many tokens should a model of size N be trained on?
- A
20 times N tokens.
- B
0.05 times N tokens.
- C
N tokens.
- D
N squared tokens.
Correct answer
A20 times N tokens.
Explanation
The lecture states the rule: model size times 20 gives the approximate number of training tokens.
- A
- 35
What does scaling law optimization ignore according to the lecture?
- A
Memory requirements.
- B
Communication overhead.
- C
Data preprocessing time.
- D
Inference cost.
Correct answer
DInference cost.
Explanation
The lecture explicitly mentions that scaling laws only consider training compute, not inference cost.
- A
- 36
In assignment 3, what is the student's primary objective?
- A
Train a model to achieve the lowest perplexity on a fixed dataset.
- B
Propose a new architecture that breaks the scaling law.
- C
Implement a custom optimizer that improves scaling efficiency.
- D
Given a flops budget, gather data from a training API, fit a scaling law, and predict hyperparameters for larger scale.
Correct answer
DGiven a flops budget, gather data from a training API, fit a scaling law, and predict hyperparameters for larger scale.
Explanation
The lecture describes assignment 3 as using a training API to collect results, fit a scaling law, and submit predictions for a larger compute budget.
- A
- 37
What largely determines a language model's capabilities according to the data unit?
- A
The training data it is trained on.
- B
The number of GPUs used.
- C
The optimizer and learning rate schedule.
- D
The model architecture.
Correct answer
AThe training data it is trained on.
Explanation
The lecture states that what the model does is mostly determined by the data.
- A
- 38
What is a major challenge with raw Common Crawl data?
- A
Much of it is low-quality or spam.
- B
It is entirely in non-English languages.
- C
It comes in binary format that cannot be parsed.
- D
It is not publicly available.
Correct answer
AMuch of it is low-quality or spam.
Explanation
The lecture shows examples of Common Crawl being full of trash and spammy sites, requiring extensive processing.
- A
- 39
What is a common step in transforming raw HTML to usable text for training?
- A
Directly feeding HTML into the model after tokenization.
- B
Extracting text from HTML, which is a lossy process.
- C
Converting HTML to Markdown to preserve formatting.
- D
Using HTML tags as additional tokens in the vocabulary.
Correct answer
BExtracting text from HTML, which is a lossy process.
Explanation
The lecture explains that data must be extracted from HTML or PDFs, and the process is lossy, aiming to preserve content and some structure.
- A
- 40
How is data filtering typically performed?
- A
By using perplexity thresholds from a reference model.
- B
Using classifiers trained to identify high-quality or harmful content.
- C
By removing all documents shorter than 100 tokens.
- D
By manually reviewing every document.
Correct answer
BUsing classifiers trained to identify high-quality or harmful content.
Explanation
The lecture mentions that people train classifiers to filter data for quality and safety.
- A
- 41
Why is data deduplication important?
- A
To reduce the storage size of the dataset.
- B
To avoid overfitting and improve generalization by removing duplicate examples.
- C
To ensure that every document appears exactly once.
- D
To prevent the model from memorizing exact strings.
Correct answer
BTo avoid overfitting and improve generalization by removing duplicate examples.
Explanation
The lecture states that deduplication is an important step, implying it prevents over-repetition.
- A
- 42
Which evaluation metric is mentioned for assessing language models in the lecture?
- A
Perplexity and MMLU.
- B
BLEU and ROUGE.
- C
Human evaluation only.
- D
Accuracy and F1 score.
Correct answer
APerplexity and MMLU.
Explanation
The lecture lists perplexity as a measure and MMLU as a standardized test.
- A
- 43
In assignment 4, what raw data will students work with?
- A
A raw Common Crawl dump.
- B
A curated set of Wikipedia articles.
- C
A cleaned version of the Pile dataset.
- D
A synthetic dataset generated by GPT-4.
Correct answer
AA raw Common Crawl dump.
Explanation
The lecture specifies that assignment 4 gives students raw Common Crawl so they can see how bad it is.
- A
- 44
What is the leaderboard metric for assignment 4?
- A
Minimizing training time on a fixed dataset.
- B
Minimizing perplexity given a token budget.
- C
Maximizing the diversity of generated text.
- D
Maximizing accuracy on MMLU.
Correct answer
BMinimizing perplexity given a token budget.
Explanation
The lecture says the leaderboard will be about minimizing perplexity given a token budget.
- A
- 45
What is the purpose of supervised fine-tuning (SFT)?
- A
To compress the model size while retaining performance.
- B
To train a model from scratch on a small dataset.
- C
To teach a base model to follow instructions by training on prompt-response pairs.
- D
To evaluate the model's performance on standard benchmarks.
Correct answer
CTo teach a base model to follow instructions by training on prompt-response pairs.
Explanation
The lecture describes SFT as gathering prompt-response pairs and doing supervised learning to get instruction-following abilities.
- A
- 46
Why is learning from feedback preferred over collecting more SFT data?
- A
It always yields better performance than SFT.
- B
It can be done without any base model.
- C
It uses lighter forms of annotation such as preferences or verifiers, which are cheaper to obtain.
- D
It requires no human annotation at all.
Correct answer
CIt uses lighter forms of annotation such as preferences or verifiers, which are cheaper to obtain.
Explanation
The lecture explains that SFT data is expensive, so learning from feedback (preferences, verifiers) uses lighter annotation and algorithms do more work.
- A
- 47
What is preference data in the context of alignment?
- A
Multiple candidate responses to a prompt, with a human rating of which is better.
- B
A set of numerical rewards for each generated token.
- C
A dataset of human-written instructions.
- D
A single correct response for each prompt.
Correct answer
AMultiple candidate responses to a prompt, with a human rating of which is better.
Explanation
The lecture defines preference data as generating multiple responses and having a user rate A vs B.
- A
- 48
Which algorithm is mentioned as simpler than PPO for learning from preferences?
- A
A2C (Advantage Actor-Critic).
- B
DPO (Direct Preference Optimization).
- C
GRPO (Group Relative Preference Optimization).
- D
Q-learning.
Correct answer
BDPO (Direct Preference Optimization).
Explanation
The lecture says DPO is much simpler than PPO when only preference data is available.
- A
- 49
What is GRPO?
- A
A method for generating preference data from humans.
- B
A reward model that scores responses without human input.
- C
An optimization technique for training tokenizers.
- D
A simpler alternative to PPO developed by DeepSeek that removes the value function.
Correct answer
DA simpler alternative to PPO developed by DeepSeek that removes the value function.
Explanation
The lecture describes GRPO as a simplification of PPO (no value function) developed by DeepSeek that works well.
- A
- 50
In assignment 5, which methods will students implement?
- A
Only PPO and reward modeling.
- B
Only SFT and DPO.
- C
Supervised fine-tuning, DPO, and GRPO.
- D
SFT and RLHF with a learned reward model.
Correct answer
CSupervised fine-tuning, DPO, and GRPO.
Explanation
The lecture states that assignment 5 implements supervised tuning, DPO, and GRPO.
- A
- 51
According to the lecture, what are three goals of alignment?
- A
Larger vocabulary, higher compression, and more parameters.
- B
Better perplexity, faster inference, and lower memory usage.
- C
Reduced training time, improved accuracy, and easier deployment.
- D
Instruction following, style control, and safety.
Correct answer
DInstruction following, style control, and safety.
Explanation
The lecture lists these three: getting the model to follow instructions, specify output style, and refuse harmful answers.
- A

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