Tokens, embeddings, and the residual stream
Text becomes integers before it becomes anything else. A tokenizer (BPE for most modern models) maps a string to a list of integers in [0, vocab_size). Llama 3 uses a 128,256-entry vocabulary; GPT-2 used 50,257. Nothing about this step is learned during pretraining — the merges were fit once on a corpus and frozen.
Those integers index into an embedding table of shape [vocab_size, d_model]. For Llama-3-8B that is [128256, 4096] = 525 million parameters, just to turn integers into vectors. The lookup produces a tensor of shape [batch, seq, d_model].
That tensor is the residual stream, and it is the single most useful mental object in the architecture. Its width never changes. Every block in the network reads the stream, computes something, and adds the result back:
x = x + attention(norm(x))
x = x + mlp(norm(x))
Note the +. Layers do not transform the stream, they contribute to it. This is why you can delete a layer from a trained transformer and often get degraded-but-coherent output: you removed one contribution from a sum of 32, not a link in a chain.
For inference, the shape [batch, seq, d_model] is where your intuition should live. During prefill seq is the whole prompt — maybe 2,000. During decode seq is 1. Same weights, same code path, wildly different arithmetic. That gap is the entire subject of Module 4.
A "hidden state" is just one slice of this stream: a single d_model-length vector at one position, at one layer. When people say a model "represents" something, they mean a direction in this 4096-dimensional space.
token ids [B, S]
|
v embedding lookup [128256, 4096]
┌─────────────────────────────────────────┐
│ RESIDUAL STREAM [B, S, 4096] │ <-- width never changes
└─────────────────────────────────────────┘
| ^ | ^
v | v |
norm->attn --+ norm->mlp ---+ (x32 layers)
|
v final norm + lm_head [4096, 128256]
logits [B, S, 128256]
REMEMBERThe residual stream is a fixed-width bus of shape [batch, seq, d_model] that every layer reads from and writes back into.