Natural Language Processing · free preview
The Transformer Block
The residual stream, position-wise feedforward layers, layer normalization, the full block equations, and the KV cache that speeds up generation.
1. The Transformer Block
The Transformer Block
2. Stacking, packing, caching
Stacking, packing, caching
3. One block in NumPy
One block in NumPy
4. Layer normalizing one token vector
A 3-dimensional token vector is . Compute the first component after layer normalization (no gain or offset), rounding to three decimals.
5. Where the parameters live
A transformer block has model dimension and feedforward hidden width . Counting the two feedforward matrices and the four attention projections (at head width ), how many times more parameters does the feedforward layer hold than the attention projections? Answer as a decimal.
6. What mixes tokens, and what does the residual stream carry?
Which statement about the components of a transformer block is correct?
7. Roughly twelve L d squared
Ignoring biases, embeddings, and the head, a stack of blocks at model dimension holds about parameters. Compute this estimate and answer in scientific notation like 1.2e9 or as a plain integer.
8. What the KV cache saves
During autoregressive generation without any cache, each new token triggers recomputation of key and value projections. What does the KV cache do instead, and what does it cost?
Practice this interactively
Free account · instant grading · spaced review that schedules itself.
Start this course for free