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 [4,2,5][4, 2, 5]. 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 d=1024d = 1024 and feedforward hidden width dff=4d=4096d_{ff} = 4d = 4096. Counting the two feedforward matrices and the four attention projections (at head width dd), 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 L=96L = 96 blocks at model dimension d=1024d = 1024 holds about 12Ld212Ld^2 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