Bitpath

Boss lesson · Unit 02

One transformer block

Attention, an MLP, and the wiring between them

13 exercisesabout 3 min

What you practise

  • Attention, then an MLP, each wrapped in a residual connection and layer norm
  • Shapes at every step
  • Stacking blocks
  • Counting the parameters of a small GPT

Try a question from this lesson

Pick one

A layer computes f(x) from a token vector x, and 12 such layers are stacked. Which output makes it easiest for layer 12 to still use what layer 1 found?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The block

A transformer block has two steps with the same wiring: normalise, compute, add the result to the input.

First attention, which moves information between tokens. Then a small MLP, which works on each token on its own. This "norm first" layout is the common one in GPT-style models.

x = x + attention(norm(x))
x = x + mlp(norm(x))

in:  [tokens, d_model]
out: [tokens, d_model]

Concept

Stack them: a GPT

A block returns the same shape it was given, so blocks can be stacked as deep as you like.

After the last block, a final norm and one linear layer turn each token's vector into a score for every token in the vocabulary. Those scores are called logits.

ids
 -> token emb + position emb
 -> block x N
 -> final norm
 -> linear: d_model -> vocab size
logits    [tokens, vocab]

10 more exercises in the app

  • 1× order the lines
  • 1× fill the blanks
  • 4× type the answer
  • 2× multiple choice
  • 1× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy