# Transformer parallels: the flow

Status: **first full draft, 2026-10-25, for slide-by-slide review.** The order and the
cards are open to change; `tools/make_figs.py` redraws the maps and the point-cloud
figures after any change, `build.py` rebuilds the pages.

## The goal

By the end, you can take any step of the GPT model built in the course notebooks and say
exactly what the same step is in Point Transformer V3, what changes, and why the change
is forced by the data (a set of points instead of a sequence of words).

![The five lessons](fig/gen/roadmap_00.svg)

The rule for the order: **every lesson answers the question the previous lesson raised**,
and inside a lesson every card answers the question the previous card left open (the
italic bridge line between cards). If a card does not answer an open question, it does
not belong.

## Lesson 01 · Tokens and serialization

*Question: how does the input become a sequence of integers?*

| Card | Question | Why we need it (what we could not do without it) | What we build | Hands on to the next card |
|---|---|---|---|---|
| **unit** | What is the smallest piece the model handles? | The first layer multiplies numbers; a word or a float triple cannot be counted or named | regex split of the story · `floor(coords / 0.05)` on the car (6 485 cells) | A unit is a name; the network needs an integer |
| **id** | How does a unit get an integer? | Integers index tables and sort. A vocab id is arbitrary; a curve code is ordered in space | sorted vocabulary of 1 130 words · Z-order bit interleave of one cell, Hilbert code | We can encode; we need the way back |
| **encode / decode** | How do we get from input to ids and back? | Outputs come back as ids; without the inverse there is no text and no label on the original points | `SimpleTokenizerV1` · `order = argsort(codes)`, `inverse = argsort(order)` | Encode assumes every unit has an id |
| **unknown input** | What if a unit was never seen? | A model that crashes on a new word is useless; mapping all to one id loses information | `<\|unk\|>`, `<\|endoftext\|>`, BPE via tiktoken · nothing: quantization is a formula | One long sequence; attention cannot take all of it |
| **group** | How is the sequence cut for attention? | Cost is quadratic in the group; the LLM window also defines the next-token target | sliding windows (`GPTDatasetV1`) · patches of 64, padding, neighbour retention measured (6 of 8) | Integers are labels, not vectors → lesson 02 |

Measured along the way: consecutive points are 1.54 m apart in file order and 0.04 m after
serialization; 7 of 8 true neighbours are reachable through at least one of the four orders.

## Lesson 02 · Embedding and position

*Question: how does an integer or a point become a vector, and where is position?*

| Card | Question | Why we need it | What we build | Hands on to the next card |
|---|---|---|---|---|
| **embedding** | How does a unit become a vector? | Later layers add, multiply and compare vectors; similar units must be able to become similar vectors | `nn.Embedding(6, 3)` lookup (seed 123) · `nn.Linear(4, 32)` on one real point, drawn | The same lookup wherever the id appears |
| **order blindness** | Does the embedding know where the unit is? | No, and attention will not either; so position must be injected now or never | permutation checks on both sides (exact) | Position must be added, differently on each side |
| **position** | How is position added? | LLM: fixed integer axis, so a table (1 024 rows) works. Point cloud: no fixed length, continuous coordinates; attention needs *relative* geometry | token + position embedding (book Fig 3.0) · toy 3×3×3 sparse conv (xCPE): 11.6 of 27 neighbours occupied, translation-invariant | Vectors that know their position → lesson 03 |

## Lesson 03 · Attention

*Question: how does one vector absorb its context?* (book Figure 3.2, stages 1 and 2)

| Card | Question | Why we need it | What we build | Hands on to the next card |
|---|---|---|---|---|
| **context vector** | How can a vector carry information about others? | Meaning is relational: the word needs its sentence, the point its neighbourhood | the six-word example · patch 150 of the car (64 points, 4 features) | An average needs weights |
| **score** | One number per pair, before training? | The dot product is that number; for raw coordinates it depends on the origin | `inputs @ inputs.T` · raw scores change by up to 0.2 when the car is moved 100 m | Scores are unbounded |
| **weights** | How do scores become weights? | Softmax: positive, sum to 1, so the output stays on the input's scale (needed for residuals) | book Figs 3.9 to 3.11 · 64×64 row sums = 1 | No parameters, symmetric |
| **q, k, v** | How does the model learn what to look for? | Projections break symmetry (1.27 vs 1.35), add parameters, change dimension, and make the score a function of learned features | `W_q, W_k, W_v` (3→2, seed 123) · the same on 3 points (4→2, seed 7), drawn | Projected scores can be large |
| **scaling** | Why divide by √d_k? | Softmax of large scores is one-hot and has no gradient; ×32 shows 79 % on one token | book Figs 3.15, 3.16 · 3×3 scores and weights drawn | Weights × values = result |
| **the layer** | What is the whole thing as code? | A few matmuls: fast, fusable (FlashAttention), equivariant | `SelfAttention_v1` · 64-point patch, permutation check | Why PTv3 chose this form |
| **vector vs scalar** | Was there a richer operator? | PTv1's vector attention: a weight per channel, an MLP per pair; 64× the numbers at scale | shapes (64, 64) vs (64, 64, 8) | Attention sees its whole group → lesson 04 |

## Lesson 04 · Mask and interaction

*Question: what must attention not see, and how do groups exchange information?* (book Figure 3.23)

| Card | Question | Why we need it | What we build | Hands on to the next card |
|---|---|---|---|---|
| **causal mask** | Should a unit see everything in its group? | LLM: the target is the next token, so no. Point cloud: the target is a label per point, so yes | tril mask + renormalise · 3×3 weights with and without a mask, drawn | Masking after softmax needs a second normalisation |
| **−∞ trick** | Where is the cheap place to mask? | Before softmax: exp(−∞) = 0, one normalisation, a constant buffer | `masked_fill(..., -inf)`, `CausalAttention` · nothing to mask | A model that sees its whole past can overfit to it |
| **dropout / shuffle** | How to stop reliance on one connection? | Randomise what is available. Point cloud: randomise the grouping, since the grouping is the approximation | `Dropout(0.5)` on 6×6 · Shuffle Order permutations per stage, drop path | A patch reaches 64 points; how does a point see the rest? |
| **Shift Order** | How do patches exchange information? | Depth alone does not help with fixed patches; alternatives need masks (+35 ms) | reach measured: 64 → 86 → 112 → 130 points over four blocks, drawn | One attention learns one relation |
| **multi-head** | Several relations at once? | h independent weightings at the cost of one wide head | `MultiHeadAttention` (Listing 3.5) · `PatchAttention` = the same minus two mask lines; shapes drawn | One sub-layer; a model is a stack → lesson 05 |

## Lesson 05 · Block and model

*Question: how are the pieces stacked into a model, and run?* (book Figure 4.3)

| Card | Question | Why we need it | What we build | Hands on to the next card |
|---|---|---|---|---|
| **LayerNorm** | How do we keep activations on scale through 12 layers? | Per-unit statistics; batch independence is why PTv3 moved BN out of the blocks (77.3 vs 76.1) | `LayerNorm` (Listing 4.2) · the same per point | Normalised vectors need a nonlinearity |
| **GELU + FFN** | Where does the nonlinearity live? | Attention mixes linearly; the ×4 MLP per unit is two thirds of a block | `FeedForward` 768→3072→768 · identical MLP per point | Deep stacks lose the gradient |
| **shortcut** | How does the gradient get back? | x + f(x): gradient 0.22 vs 0.0002 in the book's experiment | two shortcuts per block · three in PTv3 (xCPE, attention, MLP) + U-Net skips | That is one block |
| **the block** | What is the repeatable unit? | Same shape in and out, so depth is one knob; pre-norm 77.3 vs post-norm 72.3 | `TransformerBlock` on (2, 4, 768) · `PTv3Block` on (24 949, 32), drawn side by side | GPT stacks at one resolution; a point cloud must change resolution |
| **grid pooling** | How does a point see the whole object? | A 64-point patch at 5 cm is a hub cap; at 80 cm it is the car | ×2 pooling: 24 949 → 2 009 → 501 → 116 → 29, drawn | Assemble and count |
| **the model** | What does the whole thing look like? | 163 M (124 M tied) vs 46.2 M; the mini U-Net without sparse conv has 13.1 M | `GPTModel` · mini U-Net run on the car, the U drawn with real counts | Logits out; what now? |
| **run it** | What do we do with logits? | Closes the chain: ids out, decode. Generation is why the mask existed | `generate_text_simple` (untrained gibberish) · argmax per point in input order | Back to lesson 01 |

## Principles for every card

- **Tiny example first, real data second.** Six words / three points with numbers that can
  be checked by hand, then the same operation on the whole story / the whole car.
- **Every number on a page comes from a script.** `code/llm/*.py` and `code/pc/*.py` print
  sections marked `## [name]`; `build.py` slices them into the pages; `tools/make_figs.py`
  reads `outputs/*.json` to draw the point-cloud figures.
- **Figures:** the text instance uses the book's own figure; the point-cloud instance is
  drawn in the same style with concrete values (teal = weights, violet = biases/values,
  grey = data, green = outputs, amber = look here).
- **Every lesson opens with two maps:** the five lessons with this one highlighted, and
  both pipelines with this lesson's rows marked.
- **A card has:** What · Why we need it · the two instances (figure, output, ⚙ line, code
  one click away) · bridge to the next card.
