Unit 11 of 11 · about 5 hours · measure
Matched-parameter, matched-token and matched-compute comparisons and the decisive mechanism-risk experiment
Every unit in this section produces a variant that looks better or worse in one run. Whether that difference belongs to the mechanism depends on the contract you ran it under, and most published architecture gains are reported at one scale, one seed and one learning rate.
You'll be able to
- Write a comparison contract for an architecture variant: what is matched (parameters, tokens, compute, data order), what is tuned per arm, what is fixed, and what the claim may and may not say.
- Count parameters, active parameters and training FLOPs of both arms from the actual models, and say which budget each arm was matched on.
- Run a paired, multi-seed comparison, report the difference against the seed spread, and attribute it to architecture, parameter count, token budget, sequence length or optimizer retuning.
- Name the decisive mechanism-risk experiment for choosing among architectures under a stated context, data, compute and serving objective.
Covers
Read
In this order, only the parts listed
0 of 6 done
- Deep Learning Tuning PlaybookDeep Learning Tuning Playbook
Identifying scientific, nuisance and fixed hyperparameters, then Determining whether to adopt a training pipeline change or hyperparameter configuration (trial variance, study variance)
Skip the batch-norm and quasi-random-search material.
- CS336 Assignment 1 handoutCS336 2026 - Architectures and Attention Alternatives
Section 7.3, problems (
layer_norm_ablation), (pre_norm_ablation), (no_pos_emb) and (swiglu_ablation) (pp. 42 to 44); note the parameter-matching rule in the SwiGLU ablation (feed-forward width 4 times the model width against about 8/3)The handout asks for one learning curve per variant and a few sentences. It does not ask for seeds or a retuned learning rate; the card adds both. Its budgets are B200 hours; use the substitute described in the practice item.
- GLU Variants Improve Transformer (arXiv:2002.05202v1)GLU Variants Improve Transformer (Shazeer, 2020)
Section 3.1 and Table 1 as a worked comparison: parameters and operations matched by width, four runs at 65,536 steps for the variance, single runs at 524,288
- 2 OLMo 2 Furious (arXiv:2501.00656v3)OLMo 2 Open Model and Training Recipe
Section 3.3.2 (reordered norm and QK-norm, 'in isolation neither of these changes yield good results'), Figure 7, and Table 1 as an example of a package of changes
- DeepSeek-V2 (arXiv:2405.04434)DeepSeek-V2, Section 2.1 (Multi-head Latent Attention)
Appendix D.1 (MHA, GQA and MQA models aligned at about 7B parameters by changing the number of layers) and D.2 (MLA against MHA)
Read it as a design review: list what differs between arms besides the attention head layout.
- Roadmap-Final project: Decoder-Only Transformer StackDecoder-Only Transformer Stack
Measurement requirements ('No quality or speed target without baseline') and the design-defense questions
Focus on
- Write the contract before the run. The scientific variable is the mechanism. Nuisance variables that change with it, above all the learning rate and sometimes warmup, are tuned per arm or you must say that they were not. Everything else is fixed and becomes a caveat on the conclusion (Tuning Playbook). Fix the token budget and the data order, and record parameters, active parameters and FLOPs per token for each arm.
- Parameters, tokens and compute are three different matches. A gated feed-forward network or a head layout can be matched in parameters by changing a width, and GQA saves parameters that must go somewhere (deeper, wider, or left unmatched). A mixture of experts matches active parameters and FLOPs but not total parameters or memory. DeepSeek-V2's dense ablation aligned parameters by changing depth, so depth is a second difference between its arms.
- Compare the difference with the spread. Use the same seeds for data order in both arms, take paired differences, and report them next to the standard deviation across seeds. GLU Variants' Table 1 shows what that looks like: four runs at 65,536 steps have a standard deviation of 0.004 to 0.010, and a 0.003 gap at the longest run is a single value. One run per arm cannot support a ranking.
- Packages hide attributions, so test one mechanism with a negative control (the baseline with the knob at its null value) and the strongest simple alternative. OLMo 2 changed norm placement, QK-norm, initialization and z-loss together and says two of them 'in isolation' do not give good results. Then pick the decisive experiment from the risk: for a stated serving context, ask which single assumption would make the variant a bad choice (long-context recall for a mixer, drop rate and balance for MoE, quality lost to fewer KV heads at your scale) and design the smallest run that could falsify it.
Common mistakes · 3
- Comparing at one learning rate and calling it architecture. The best learning rate depends on the architecture, so a fixed value favors the arm it happens to suit. A fair statement is 'at this learning rate' or a per-arm sweep with the same budget for each arm.
- Letting parameters, depth and tokens drift together. A variant that saves parameters (GQA, MoE active parameters) looks worse unless you decide what happens to the saved budget, and one that adds layers looks better for reasons that are not the mechanism. State which budget was matched and show the arm that matches the other budgets.
- Reading a package result as a component result, or a scale-specific result as general. A change evaluated at a few million parameters on one corpus says little about a billion parameters. Say what scale, data and sequence length the claim covers and what experiment would extend it.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Two arms differ by a gated feed-forward network and are matched in parameters. What have you not matched, and which of those can change the outcome?Answer
Activation memory and elementwise work (the gated one stores more activations per token for the backward pass), possibly throughput, and the optimal learning rate. Any of them can change the result or the cost of achieving it, so state the matched budget and the unmatched ones.
2.Variant B beats baseline A by 0.02 in validation loss in one run each. List what you need before claiming B is better.Answer
Several seeds with paired data order and the spread of the difference, the same token budget, matched parameters or a stated reason for unequal ones, learning rate tuned (or a sweep) for both arms, and the same evaluation data, tokenizer and context length. Then compare the difference with the trial-to-trial standard deviation.
3.You save parameters with GQA and spend them on a wider feed-forward network. Why is the comparison with MHA still not a pure test of the head layout?Answer
The FFN width also changed, so a difference could come from the wider FFN. A fuller design adds the arm with GQA and the original FFN (fewer parameters) and the arm with MHA and the wider FFN, so each change is isolated.
4.An MoE with the same active parameters as a dense model trains at lower loss for the same tokens. What claims does that support and what claims does it not?Answer
It supports a quality gain per active parameter and per training token at that scale. It does not support equal memory or serving cost, since total parameters are larger, nor equal training throughput or wall-clock time, since routing and communication cost time, nor a claim at larger scale.
5.A source claims QK-norm lets a model train at a learning rate ten times higher. What runs does the claim need?Answer
The claim is about the range of learning rates that train stably, so both arms need the same learning-rate grid and the same seeds, and you compare where each diverges or degrades. A single high-rate run of each arm cannot separate the mechanism from one unlucky baseline run, and a single learning rate cannot show a range.
Practice
- CS336 Assignment 1: ablations with seeds and a retuned learning rate
Section 7.3: problems (
layer_norm_ablation), (pre_norm_ablation), (no_pos_emb) and (swiglu_ablation); Section 7.2.1 for the base configurationThe handout budgets 0.5 B200 hours per ablation and has no tests. Substitute its TinyStories setup at the 40,000,000-token low-resource budget, or your own smaller decoder, and run the one variant you chose for this section against your baseline: same tokens and data order, 3 seeds, a stated or swept learning rate for each arm, parameter and FLOP counts from the models. The section mini-project is this comparison.
You're done when
You have a written contract, parameter and FLOP counts for both arms, a paired multi-seed table with the difference next to the seed spread, and a one-paragraph claim that names what was matched, tuned and fixed, plus the experiment that would extend it.
Only when you can do this without notes.
Leads to
- Parameters, tokens and compute as separate variables, and fixed-token versus fixed-compute contractsExtend the contract to fixed-token and fixed-compute comparisons across scales.
- Strong baselines, mechanism ablations, negative controls and scale and system confoundsCarry the contract into ablations with negative controls.
Notes
Resources · 6 for this unit, 12 more in the section
- CS336 2026 - Architectures and Attention AlternativesStanford University · primary
Study the Lecture 3 slides (
lecture_03.pdf, architectures and hyperparameters) and Lecture 4 slides (lecture_04.pdf, attention alternatives and mixture of experts) instanford-cs336/lectures, then implement the Assignment 1 Section 3.3 to 3.5 pieces (RMSNorm, SwiGLU, RoPE, causal attention, the pre-norm block) against its tests. Reconstruct every parameter and state equation before you change one mechanism. Keep GPUs, kernels and parallelism (Lectures 5 to 8) for their own tracks. - OLMo 2 Open Model and Training RecipeAllen Institute for AI · required
Read Section 2.1 (architecture), Section 3.2 (initialization) and Sections 3.3.1 to 3.3.3 (non-parametric norm to RMSNorm, reordered norm with QK-norm, z-loss) and Table 1, then find the same settings in a released configuration. The changes were adopted as a package, so the report cannot attribute stability to any single one.
- GLU Variants Improve Transformer (Shazeer, 2020)Google · support
Read Section 2 (the GLU family and SwiGLU) and Section 3.1 (hidden width cut from 3072 to 2048 so parameters match), then Table 1, where GEGLU edges out SwiGLU on the longest run. Check the matching arithmetic yourself.
- Decoder-Only Transformer StackRoadmap-Final · support
Extend the already-tested decoder with the chosen mechanism. Preserve its slow oracle, causal and position tests, generation behavior and model arithmetic.
- DeepSeek-V2, Section 2.1 (Multi-head Latent Attention)DeepSeek-AI · optional
Read Sections 2.1.1 to 2.1.4: low-rank joint key-value compression, decoupled RoPE and the cache comparison. The 93.3% cache reduction is against their own 67B model, not a portable ratio.
- Deep Learning Tuning PlaybookGoogle Research · support
Read 'Identifying scientific, nuisance, and fixed hyperparameters' and 'Determining whether to adopt a training pipeline change or hyperparameter configuration' as the protocol for comparing architecture variants (per-arm learning rate, trial variance). Skip the batch-norm material. Last commit 2024; pin commit 7554a51.
Also in this section
- Build a Large Language Model (From Scratch), Chapters 3 and 4Sebastian Raschka / Manning · support
Use Chapter 3 (causal multi-head attention, pp. 50-91) and Chapter 4 (the GPT model, pp. 92-127) as the smallest runnable decoder, then the companion bonus folders
ch04/04_gqaandch04/07_moefor one bounded variant. The printed chapters use GPT-2 parts (LayerNorm, GELU, absolute positions); the modern pieces live only in the bonus folders. - On Layer Normalization in the Transformer Architecture (Xiong et al., 2020)Microsoft Research Asia · support
Read Figure 1 and Sections 3 and 4: why Post-LN gradients near the output are large at initialization and need warmup, and why Pre-LN does not. The analysis holds at initialization only and assumes uniform attention weights and Gaussian inputs there.
- GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints (Ainslie et al., 2023) with Fast Transformer Decoding: One Write-Head is All You Need (Shazeer, 2019)Google Research · support
Read MQA Sections 2 and 3 (one shared key and value head to cut decoding memory traffic), then GQA Section 2 (grouped heads as the interpolation, mean-pooled uptraining with 5% of pretraining compute) and Table 1. Both report encoder-decoder results. MQA is at https://arxiv.org/abs/1911.02150.
- RoFormer: Enhanced Transformer with Rotary Position Embedding (Su et al., 2021)Zhuiyi Technology · required
Read Section 3: the rotation-matrix form of RoPE, why the attention score depends only on relative position, and the long-distance decay property. Base 10000 is the original choice; later models raise it.
- Extending Context Window of Large Language Models via Positional Interpolation (Chen et al., 2023) and YaRN (Peng et al., 2023)Meta AI; Nous Research · support
Read Position Interpolation Sections 2 and 3 (scale positions by the length ratio instead of extrapolating), then YaRN Section 3 (frequency-dependent interpolation and the attention temperature). Both still fine-tune. YaRN is at https://arxiv.org/abs/2309.00071.
- Small-Scale Proxies for Large-Scale Transformer Training Instabilities (Wortsman et al., 2023)Google DeepMind · support
Read Section 3.1: attention-logit growth and output-logit divergence reproduced in small models at high learning rates, and the QK-layernorm and z-loss fixes (Figures 1 to 4). It explains two of the OLMo 2 choices; transfer to a specific large run is argued, not proven.
- Modern LLM Notebook - Architecture FrontiersWalking Labs · support
Use
notebooks-en/part2-training/08-gpt2-to-modern-models.ipynb,11-mla-kv-cache.ipynband13-moe.ipynb, andnotebooks-en/part4-frontiers/27-long-context.ipynband30-efficient-attention.ipynb. Implement only the one variant selected for the checkpoint. - TensorTonic - Architecture and Attention AlternativesTensorTonic · support
Solve RMSNorm Forward Pass (
cs336-l03-rmsnorm-forward), Parameter-Matched SwiGLU Block (cs336-l03-parameter-matched-swiglu), Rotary Query and Key Embeddings (cs336-l03-rotary-query-key-embeddings), Causal Grouped-Query Attention (cs336-l03-causal-grouped-query-attention), Top-k MoE Router with Load Statistics (cs336-l04-topk-moe-router) and one ofcs336-l04-linear-attention-dualityorcs336-l04-mamba2-gated-state-scan. Add capacity and token-drop cases the router tests lack. Public test cases check the listed edge cases, not gradients or the hidden grader, so keep your own tests beside each solution. - Switch TransformersGoogle Research · depth
Use Equations 4 to 6 (the load-balancing loss), Figure 3 (capacity factors), Table 3 (smaller initialization for stability) and the Appendix F pseudocode as the deeper MoE reference. Reproduce only a tiny router experiment; full sparse pretraining belongs to later systems work.
- ST-MoE: Designing Stable and Transferable Sparse Expert Models (Zoph et al., 2022)Google · depth
Read Section 3 and Appendix B: the router z-loss in Equation 5, its coefficient 0.001 and the load-balance weight in Equation 6, and why update clipping stabilizes runs at a quality cost. Its setting is encoder-decoder T5.
- Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality (Dao and Gu, 2024)Princeton and CMU · optional
Read Section 1 and Sections 5 and 6, including Listing 1 (the
segsumreference), for a state-space alternative. Skip the full duality theory; compare against a linear-attention baseline in your own harness. - Modern LLM Notebook, Appendix B: From Parameters to MemoryWalking Labs · support
Appendix B Section 1 (parameters per block and per model, GQA and SwiGLU) and Section 2 (activation memory). Recount the activation tables with autograd hooks; the notebook lists produced tensors, not saved ones. Pin commit 979eecf.