One lookup table, one block repeated thirty-two times, one matrix at the end. Know the shapes and every memory figure in this runbook becomes something you derive rather than remember — including the answer to “how many users fit”.
One lookup table, one block repeated thirty-two times, one matrix at the end. The block is always the same shape; only its learned numbers differ from layer to layer.
128,256 × 4,096. A token id is a row number.
Each reads the stream twice and adds to it twice.
One more RMSNorm at the top.
4,096 × 128,256 — the mirror of the embedding.
One raw score per vocabulary entry.
One vector per token, 4,096 numbers wide, running the entire height of the model. No block ever overwrites it. Each block reads it, works out a small correction, and adds that correction back.
Sixty-four specialists. Nobody may delete anything; each may only write additions in the margin. Half are allowed to glance at everyone else’s copy before they write — those are the attention blocks. The other half must work from their own copy alone — the feed-forward blocks.
Divide by root-mean-square, scale by a learned weight.
The only place tokens see each other.
Into the residual stream.
Same operation, different weights.
Each token alone. 70% of the parameters.
And on to the next block.
Makes the magnitude of the vector predictable, so the next block sees inputs in a stable range no matter how much earlier layers added.
4,096 per norm, two norms per layer, plus one at the top.
RMSNorm skips the mean subtraction and the bias. Slightly cheaper, empirically just as good.
It is the reason activations stay in a sane range.
That single fact explains why attention is the only part that produces a cache, and why the feed-forward block can be sharded, routed or replaced without anything breaking.
A vector 4,096 wide. That is the model dimension.
W_Q is 4096×4096. W_K and W_V are 4096×1024.
8 KV heads × 128 = 1024. Not 4096 ÷ 8 = 512.
4 KiB per token per layer. Q is used once and discarded.
4096×4096, unchanged across MHA, MQA and GQA.
41,943,040 parameters per layer.
The query is what this token is looking for. The key is what it advertises to others. The value is what it hands over if selected. Dot every query against every key, soften into weights that sum to one, take that weighted blend of values.
4,096 is a width, not a length. It is how many numbers describe one token. A model 4,096 wide can have a 128,000-token window; different axes entirely.
Heads partition the vector, they do not copy it. 4096 ÷ 128 = 32 heads, each owning a 128-number slice. 32 heads learn 32 relationships, not 32 meanings.
Attention gets the papers and the interview questions. The feed-forward block gets four times the parameters.
SwiGLU has a gate, an up and a down — so 3 × d × ffn.
3 × 4,096 × 14,336.
Each token is processed in isolation.
The classic FFN was 2 × d × 4d = 8d². Keeping that count with three matrices needs 8/3 × d = 10,923.
Almost every candidate can talk about attention and almost none mention that it is a sixth of the model. Saying “the feed-forward block is 70% of the parameters, so it is where weight quantisation actually pays, and it produces no KV cache at all” does two things at once.
The most useful thing in this document. Turn a config into a parameter count and you get the weight footprint at any precision and the cache per token for free.
128,256
4,096
32
32
8
14,336
“Embedding is vocab times d_model. Per layer, attention is d_model times q-heads times head-dim, plus twice d_model times kv-heads times head-dim, plus the output projection back to d_model — and the feed-forward is three times d_model times the FFN width, because SwiGLU has a gate, an up and a down. Multiply the layer by the layer count, add the embedding, add the output head if it is not tied.”
The standard estimate is two operations per parameter — one multiply, one add — giving 16.06 GFLOP for the 8B. But the embedding table is a lookup, not a matrix multiply, so its 525 million parameters contribute nothing.
After all 32 blocks: one vector 4,096 wide.
4096×128256 — 1.05 GFLOP, ~7% of the forward pass.
One per vocabulary entry. 0.49 MiB in fp32, per position.
The other positions are prompt — already known.
Sometimes. Weight tying reuses one matrix for both, saving 525M parameters on an 8B.
128,000 learned entries plus 256 reserved slots — role headers, end-of-turn, and spares for later fine-tuning.
On the logits, after the head and before the softmax.
No. The relationship between sunrise and east is distributed across the weights; nothing is localised in a way you can point at.
For an 8,192-token prefill the full logits tensor would be 3.9 GiB. Prefill deliberately never computes it — the output head is applied to the last position only.
Walk me through one transformer layer.
Here is a config file. How much memory will this model need?
Why does the cache formula not contain d_model or query heads?
Why 32 layers rather than one much wider one?
The team wants a model with a much bigger vocabulary.
What is the largest single activation, and why is it not a problem?
Someone proposes pruning attention heads to save memory.
QWhat is d_model, exactly?
The number of values that describe one token at every point inside the model — 4,096 for the 8B, 8,192 for the 70B. It is a width, not a length, and has nothing to do with context. The heads partition it: 4096 ÷ 128 = 32.
QIs head_dim always 128?
Not by law, but remarkably stable. The 8B (4,096 wide, 32 heads), 70B (8,192, 64) and 405B (16,384, 128) all land on 128. Models scale by adding heads and layers rather than widening each head. Read it from the config.
QWhy is the FFN width 14,336 and not 16,384?
SwiGLU has three matrices where the classic FFN had two. Matching the old 8d² count with three needs 8/3 × d = 10,923; Llama applies a 1.3 multiplier and rounds up to a multiple of 1,024 — exactly 14,336. You can reproduce the config value from the heuristic.
QDo all layers have the same weights?
The same shape, different numbers. Every one of the 32 blocks has its own 218 million parameters, learned independently. A few research architectures share weights across layers; no mainstream open model does.
QWhere is the model’s knowledge stored?
Distributed across the weights, with the feed-forward blocks carrying most of it — they hold 70% and there is research treating them as key-value memories. But nothing is localised. That is why a model cannot cite a source, and why removing a fact is an open research problem.
QWhy does the residual connection matter for inference?
Mostly it does not — it is a training device. The one inference-facing consequence is that the stream stays in a stable numeric range, which is what makes activations quantisable and what RMSNorm exists to protect.
QDoes the embedding table get read on every decode step?
Only one row per token — 8 KiB out of a 1 GiB table — so negligible as a read. The output head is the opposite: the full 4096×128256 matrix is multiplied every step, 1.05 GFLOP and ~7% of the forward pass. Same size, completely different runtime profiles.
QWhy 2 FLOPs per parameter?
A matrix multiply does one multiply and one add per weight. The refinement: the embedding is a lookup, so the honest figure is 2 × (N − embedding) — 15.01 GFLOP rather than 16.06 for the 8B. Training is roughly 6N.
QWhat is weight tying and should I care?
Using the same matrix for the input embedding and the output head, saving vocab × d_model. It matters most where that table is a big fraction of the model. Check tie_word_embeddings — getting it wrong on a small model throws your total out by 10% or more.
QCould I just remove layers to make the model smaller?
People do — depth pruning, and it works better than you would expect on middle layers. But it is a training project: quality drops and needs recovery fine-tuning. Against quantisation’s reliable 2–4× in an afternoon, it is rarely the right first move in serving.
Attention gets the questions; the feed-forward block gets the parameters. Attention is 17% of an 8B and the only thing that produces a KV cache. The feed-forward block is 70%, processes each token alone, and caches nothing. Those are two different memory problems with two different sets of fixes — and conflating them is the single most common error in this whole subject.
Which model and precision — and has anyone counted the parameters from the config?
Is the output head tied to the embedding table on the models you serve?
What is the KV head count, and did you choose the model partly for it?
Has anyone measured the activation and workspace reserve, or is it a guess?
Do you ever request log-probabilities on prompt tokens, and do you know what that costs?