Skip to main content
What you'll learn
Builds on Modules 1–9
≈6.5 h · 2 h video · 20 min frontier outline · 2 h reading · 2 h coding
  • Implement patchify + linear embedding and explain ViT's data-versus-bias trade-off
  • Contrast BERT, T5, and GPT through their pretraining objectives and attention masks
  • Explain knowledge distillation and why a CNN teacher can lend useful inductive bias to ViT
  • Use scaling laws to reason jointly about parameters, training tokens, and compute
  • Compare KV retention, factorized sufficient statistics, and bounded online state in regression vocabulary; critique test-time planning under a compute-matched rematch
10.1 Vision Transformer (ViT)
10.2 Pretrained Transformer Models
10.3 Scaling of Decoder Transformer Models
10.4 – Test-time Regression and Test-time Control

A 20-minute research-frontier segment: start with the precise local-constant regression statement, compare three memory contracts, then ask what changes when a layer evaluates possible futures before predicting. The memory-versus-planning split is an architectural bet, not settled science; the System 1/System 2 language in the paper is only a loose metaphor.

20-minute lecture outline

  1. 0–3 min

    Precision before the slogan

    At a query qq, softmax attention solves a local-constant kernel fit: minimize 12τκ(q,kτ)cvτ2\frac12\sum_\tau \kappa(q,k_\tau)\lVert c-v_\tau\rVert^2 over one constant cc. An unrestricted function with w=1w=1 and no regularizer would not, by itself, produce this weighted average.

  2. 3–7 min

    One objective, four dials

    Read Mt=argminM  12τtwt,τM(kτ)vτ2+Ω(M)M_t=\arg\min_M\;\frac12\sum_{\tau\le t}w_{t,\tau}\lVert M(k_\tau)-v_\tau\rVert^2+\Omega(M). Track four choices: learned key/value/query views, history weights, regularization, and the solver. The solver is the new rung.

  3. 7–12 min

    The corrected memory spectrum

    Exact softmax keeps the prefix’s K/VK/V pairs as the nonparametric regressor’s dataset. A factorized kernel can instead keep the exact sufficient-statistic pair (St,zt)(S_t,z_t). An online linear update keeps a bounded matrix state, as in the Delta-rule view. These are different statistical contracts—no state compression versus fixed-size, lossy compression—not settled equivalences.

  4. 12–15 min

    What selection can learn

    Use Mamba-style selectivity only as an interpretive bridge: token-dependent state retention and input injection play roles analogous to a learned forgetting and update schedule. That analogy does not derive Mamba from the regression objective or cover selective-scan implementation details.

  5. 15–17 min

    Two minutes of scalar LQR

    Contrast fitting the prefix with evaluating a finite horizon. Step backward through Pqc+a2P(abP)2/(rc+b2P)P\leftarrow q_c+a^2P-(abP)^2/(r_c+b^2P), then inspect the first gain K1=(rc+b2P)1bPaK_1=-(r_c+b^2P)^{-1}bPa. Changing the horizon can change the first action before any new token is emitted.

  6. 17–20 min

    A rematch, not a referendum

    End with the discussion prompt below: separate parameter matching, generated-token matching, and total inference-compute matching before interpreting a frontier result.

Discussion-leading prompt

Read Table 2 and §E.2 of Wang et al. (2026). Which comparisons are approximately parameter-matched, which share the prompting and output-token protocol, and which are not matched for total inference compute? Design a horizon-TT rematch that fixes the backbone, data, prompt, sampling, hardware, and output cap; then equalizes measured FLOPs or wall-clock cost per item, including the planner’s internal work. What accuracy-versus-compute curve, uncertainty, and memory-only baseline would you report? Treat this as a rematch, not a referendum.

🧠 Test your understanding

Try each question before revealing the answer — these mirror the ideas the module quiz checks.

Q1.Why does ViT underperform ResNet on small datasets like Fashion-MNIST, but outperform ResNet on larger datasets like JFT-300M?Show answer ▾

Answer: Transformers lack some useful CNN inductive biases, especially locality and translation equivariance, which can help CNNs generalize with limited data. With enough data and compute, a Transformer's weaker spatial prior can instead offer useful flexibility.

CNN locality and translation equivariance can improve sample efficiency, while a weaker spatial prior can become flexible at scale. Dataset size is one important axis, but compute, augmentation, pretraining, architecture, and optimization recipe also affect the comparison; no single threshold determines the winner.

Q2.How do BERT and GPT differ in their pretraining objectives, and why does this difference affect what attention patterns they can use?Show answer ▾

Answer: BERT uses masked language modeling (predicting masked tokens with bidirectional context), allowing it to use bidirectional attention. GPT uses autoregressive language modeling (predicting the next token), requiring causal masking to prevent attending to future tokens.

The pretraining objective determines the permissible attention pattern. Masking creates a denoising problem where context can flow both directions, while autoregressive generation requires left-to-right causality. This architectural choice directly follows from the training objective.

Q3.What architectural role does the `<cls>` token play in both ViT and BERT, and why is this design useful?Show answer ▾

Answer: In both architectures, `<cls>` is prepended to the input (patches in ViT, tokens in BERT), and its representation after the Transformer is used for classification. Through self-attention, it aggregates information from all inputs and serves as a learnable global representation.

A dedicated pooling token gives the objective an explicit location whose representation can learn to aggregate the sequence. It has direct attention paths to all inputs, but it is a design choice rather than inherently superior: mean pooling, attention pooling, or a designated final token can also work when the architecture and objective support them.

Q4.How does T5 unify diverse NLP tasks (classification, summarization, translation) into a single framework, and what advantage does this provide?Show answer ▾

Answer: T5 converts all tasks to text-to-text format by adding task description prefixes (e.g., "Summarize:", "Translate English to German:") and generating the target as text. This enables a single model and objective to handle multiple task types and allows multitask learning.

The unified framework is powerful because it eliminates task-specific architectures and loss functions. The same encoder-decoder model with the same objective handles generation, classification, and structured prediction. This also enables zero-shot transfer and efficient multitask training.

Q5.According to the textbook, Transformer language models exhibit power-law scaling relationships. What does this mean, and why is it important?Show answer ▾

Answer: In controlled empirical studies, loss often follows an approximately linear trend on log-log plots as model size, data, or compute is varied. Because compute couples model size and training tokens rather than forming an independent multiplicative factor, fitted scaling laws can be used to estimate a compute-efficient frontier instead of simply maximizing one quantity.

These are empirical regularities over measured regimes, not a universal product formula. Their practical value is comparative: under an explicit compute budget and training recipe, they help estimate how to divide resources between parameters and data and where extrapolation becomes risky.

Q6.What does using separate classification and distillation tokens and heads provide in a distilled ViT?
  • It prevents all gradient interaction between the two objectives
  • It gives the label and teacher objectives separate readout pathways that can specialize, while both still train the shared trunk
  • It doubles the model's parameter count
  • It guarantees the student will outperform the teacher
Show answer ▾

Answer: It gives the label and teacher objectives separate readout pathways that can specialize, while both still train the shared trunk

The classification head reads a token trained toward ground-truth labels, while the distillation head reads a token trained toward teacher targets. Separate readouts reduce direct competition for one summary vector and let the two tokens specialize. They do not make the objectives independent: both losses backpropagate through shared Transformer parameters, where their gradients can still agree or conflict.

Q7.What practical principle did the Chinchilla study add to earlier language-model scaling practice?
  • Make models as large as possible regardless of training data
  • Scale parameters and training tokens together under a compute budget; its fitted regime suggested roughly 20 training tokens per parameter
  • Spend all compute on data and never increase model size
  • Use one universal token-to-parameter ratio for every architecture and dataset
Show answer ▾

Answer: Scale parameters and training tokens together under a compute budget; its fitted regime suggested roughly 20 training tokens per parameter

The study found that several earlier large models were undertrained for their size. In its measured regime, allocating compute to both model size and more training tokens produced a smaller, more thoroughly trained Chinchilla model that outperformed the larger Gopher on many evaluations. The roughly 20:1 figure is an empirical rule from that setup, not a universal constant.

Q8.Why must exact softmax attention keep a KV cache while a fixed-state SSM does not? Answer in regression vocabulary.
  • Attention is a query-local nonparametric regressor that retains its observed key/value pairs as the dataset; a fixed-state SSM compresses the prefix into bounded state
  • Attention stores optimizer gradients, while an SSM recomputes every past token
  • The KV cache stores model parameters, while an SSM has no parameters
  • An SSM always recalls every past value exactly, so it needs no dataset
Show answer ▾

Answer: Attention is a query-local nonparametric regressor that retains its observed key/value pairs as the dataset; a fixed-state SSM compresses the prefix into bounded state

For exact softmax attention, the projected keys and values are the data traversed by each new query. Caching them avoids recomputing earlier projections, but the dataset still grows with the prefix. A fixed-state SSM chooses a different statistical contract: it updates a bounded summary, gaining constant state size while generally accepting lossy compression. Keeping every K/V row does not by itself guarantee exact numeric recall; the query-dependent weighted average still matters.

Q9.Which dial of the shared regression objective does Mamba-style selectivity most naturally turn?
  • Token-dependent retention and input injection, interpretable as a learned forgetting and update schedule
  • The local-constant constraint that makes softmax a weighted average
  • The choice to retain every key/value pair losslessly
  • Only the output vocabulary and tokenizer
Show answer ▾

Answer: Token-dependent retention and input injection, interpretable as a learned forgetting and update schedule

Selectivity lets the recurrence retain or inject information differently for different tokens. In regression language, that plays a role analogous to learning which history to weight and how strongly to update. This is an interpretive bridge, not an exact derivation of Mamba from one least-squares objective, and it says nothing about selective-scan implementation details.

Q10.Which claim requires the local-constant qualification before we say ‘attention is regression,’ and why?
  • The claim that unrestricted MM with w=1w=1 and no regularizer directly yields the softmax weighted average, because such a function can interpolate the observed pairs instead
  • The claim that the softmax weights are nonnegative and sum to one, because softmax can produce negative weights
  • The claim that queries and keys are learned views, because they must always share one projection
  • The claim that attention uses values, because values are used only during training
Show answer ▾

Answer: The claim that unrestricted MM with w=1w=1 and no regularizer directly yields the softmax weighted average, because such a function can interpolate the observed pairs instead

The exact statement fixes one constant prediction cc at query qq and minimizes 12τκ(q,kτ)cvτ2\frac12\sum_\tau\kappa(q,k_\tau)\lVert c-v_\tau\rVert^2. Stationarity gives τκ(q,kτ)(cvτ)=0\sum_\tau\kappa(q,k_\tau)(c-v_\tau)=0, so cc is the normalized kernel-weighted average. The kernel supplies the weights; the local-constant fit supplies the average.

Q11.If a kernel factors as κ(q,k)=ϕ(q)ϕ(k)\kappa(q,k)=\phi(q)^\top\phi(k), which running state exactly reproduces the normalized kernel traversal?
  • StS_t alone
  • ztz_t alone
  • The pair (St,zt)(S_t,z_t), where St=τtϕ(kτ)vτS_t=\sum_{\tau\le t}\phi(k_\tau)v_\tau^\top and zt=τtϕ(kτ)z_t=\sum_{\tau\le t}\phi(k_\tau)
  • The final key/value pair only
Show answer ▾

Answer: The pair (St,zt)(S_t,z_t), where St=τtϕ(kτ)vτS_t=\sum_{\tau\le t}\phi(k_\tau)v_\tau^\top and zt=τtϕ(kτ)z_t=\sum_{\tau\le t}\phi(k_\tau)

StS_t supplies the weighted numerator and ztz_t supplies the normalizing denominator: ϕ(q)St/(ϕ(q)zt)\phi(q)^\top S_t/(\phi(q)^\top z_t). Both are sufficient statistics for that factorized kernel. This exact recurrence does not make ordinary softmax attention a fixed-state method unless its kernel is replaced by, or represented with, an appropriate factorization.

Q12.Wang et al. report comparable added parameters in Table 2 and a shared chain-of-thought protocol in §E.2. What matched-comparison conclusion is justified?
  • The comparison is automatically matched for total inference compute
  • Some architecture and prompting confounds are controlled, but horizon-dependent internal planning work is not matched by counting generated tokens alone
  • Parameter matching makes the choice of hardware irrelevant
  • The results establish a universal ranking of memory and control architectures
Show answer ▾

Answer: Some architecture and prompting confounds are controlled, but horizon-dependent internal planning work is not matched by counting generated tokens alone

Comparable added parameter counts and a shared prompting/sampling recipe are useful controls, but they do not equalize total per-example inference work. A compute-matched rematch would fix the backbone, data, prompt, sampling, hardware, and output cap; include the planner's internal horizon work; allocate equal measured FLOPs or wall time; and report accuracy versus compute with uncertainty and a memory-only baseline. That would be a rematch, not a referendum.