Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 08 · AI · Serve the GPT you built · about 17 min to read

Watch: Attention from scratch: the mechanism that ate the field
▶ VideoPlay it as a journeyTutor comes with a plan

Attention, grown up: RoPE, GQA, FlashAttention and Mamba

Attention and the Transformer
Attention and the Transformer · Open board

The attention board shows every word looking back at every earlier word. This lesson is what happened to that picture when people tried to feed it a whole book.

Before you start. From Mixture of Experts (a big brain with a cheap forward pass): a model has a bill in time, set by the numbers one word touches, and a rent in memory, set by every number it stores. From Serve 01: The KV Cache: the KV cache is the model’s saved notes on every earlier word, and for a 7-billion model it costs 512 KB per word. From The GPU (thousands of cores, and the memory that feeds them): a card has a huge slow store (HBM, high-bandwidth memory) and a tiny fast table (shared memory), and the road between them is the limit. From Attention & the Transformer: every word asks a question (a query), every earlier word shows a label (a key) and hands over content (a value), and a head is one such asking.

Lesson 71 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • November 2019: a paper titled like a complaint
  • The ledger: 512 KB a word
  • Grouped-query attention (GQA): the clerks share a ledger
  • FlashAttention: do the sums at the desk, not in the godown
  • Rotary position embedding (RoPE): a watch on every word
  • Sliding window: keep only the last pages on the desk
  • State space model: no ledger, one running total
  • The ledger under each design
  • RoPE: the score sees only the gap
  • FlashAttention: the softmax in tiles
  • Sliding window and its rolling shelf
  • State space model: a slate that fades
  • Where real systems sit

Terms it explains: grouped-query attention, FlashAttention, rotary position embedding, sliding window, state space model, Mamba, Common mistakes, attention matrix, causal mask, cross-attention, feed-forward (FFN/MLP), layer norm, multi-head, O(n²), positional encoding, Query/Key/Value, residual connection, scaled dot-product attention, self-attention, stack of N blocks, transformer block.

Related papers

Review AI