Appendix D

Notation

Every symbol, shape, and counting rule the book uses, in one place.

Sizes

SymbolMeaningLlama 3 8BLlama 3.1 405BIntroduced
Vvocabulary size128,256128,256Ch 1
Tsequence length (tokens in the context)up to 128kup to 128kCh 2
Bbatch size (sequences processed together)set per runCh 5
Cmodel width: length of a token's vector4,09616,384Ch 2
H (MLP)MLP hidden width14,33653,248Ch 2
H (heads)number of attention heads per layer; context makes clear which H32128Ch 4
dhead width: length of one head's q, k, v128128Ch 3
rKV heads ÷ query heads (grouped-query attention); also LoRA rank in Ch 140.250.0625Ch 4
Lnumber of blocks (layers)32126Ch 4
Nnumber of parameters8.03 B405.85 BCh 4
Dnumber of training tokens15 T15.6 TCh 8

Shapes

Shapes are written in brackets, batch first. Inner dimensions must match to multiply: [n] × [n, m] → [m], and [T, n] × [n, m] → [T, m] applies the same map to every row.

TensorShapeWhat it is
token ids[B, T]integers from the tokenizer
x, the residual stream[B, T, C]one vector per token, the same shape through every block
Q, K, V[B, T, d] per headqueries, keys, values
scores, attention weights[B, T, T] per headQ·Kᵀ/√d, masked, softmaxed per row
logits z, probabilities p[B, T, V]one next-token distribution per position
KV cache[L, 2, KV heads, T, d] per sequencestored keys and values of every past token

Learned matrices

MatrixShapeRoleIntroduced
W_E[V, C]embedding: token id selects a rowCh 2 §2.3
W_Q, W_K, W_V[C, d] per headquery, key, value projectionsCh 3 §3.2
W_O[C, C]mixes concatenated heads back into the streamCh 4 §4.1
W_in, W_out[C, H], [H, C]MLP expand and compress (plus W_gate [C, H] when gated)Ch 2 §2.6
g[C]RMSNorm gainsCh 4 §4.3
W_U[C, V]unembedding: stream to logitsCh 2, Ch 4

Quantities and operations

SymbolMeaningIntroduced
θall the model's parametersCh 1
zlogits: unconstrained scores, one per vocabulary entryCh 1 §1.3
p = softmax(z / T)probabilities; T here is temperature, not sequence lengthCh 1 §1.3
loss = −ln p(target)cross-entropy: the surprise at the true next token, averaged over positionsCh 1 §1.4
e^(mean loss)perplexityCh 1 §1.4
a · bdot product, Σ aᵢbᵢ = |a||b|cos θCh 2 §2.2
∂L/∂w, ∇Lpartial derivative; gradient (same shape as θ)Ch 5 §5.1
ηlearning rateCh 5 §5.2
m, vAdam's running averages of the gradient and its squareCh 5 §5.5
KL(p ‖ q)Σ p ln(p/q): how far q is from pCh 15, Ch 27
βstrength of the KL penalty in preference optimisationCh 15

Counting rules

RuleFormulaIntroduced
matmul cost[T, n] × [n, m] ≈ 2·T·n·m operationsCh 2 §2.4
parameter countL·(2C² + 2C²·r + 3C·H) + 2·V·C (gated MLP, grouped-query attention)Ch 4 §4.6
forward pass≈ 2N operations per token, plus attention's T² termsCh 4 §4.7
training≈ 6N per token; 6·N·D per runCh 5, Ch 8
training memory≈ 16 bytes per parameter: weight 2, gradient 2, fp32 master 4, Adam m and v 8Ch 5 §5.7
serving memory2 bytes per parameter in bf16; ≈ 0.5 in 4-bitCh 7, Ch 27
KV cache per token2 × L × (KV heads) × d × bytesCh 7 §7.2
decode time per token≈ bytes of weights ÷ memory bandwidth (memory-bound)Ch 7 §7.2
compute-optimal data≈ 20 tokens per parameterCh 8
minimum detectable difference≈ 2.8 × √(discordant fraction / n) for paired evalsCh 23 §23.5

Markers used in the text

publicstated in a published paper, report, model card, or documentation
inferredreasoned from public facts; the text says from what
unknownnot disclosed by the labs