Token Anatomy
interactive illustration · numbers from a simulation
Scene 1 · same model, two computers

Both computers fit the same model. Which one generates the next token faster?

Same model, same short prompt, 32 GB of memory each. In the simulation they differ only in effective read bandwidth: the width of the road between memory and the compute unit.

Scene 2 · stop on a single token

{{s2Title}}

Your prediction for A: {{guessL}} tok/s
memory weight read compute next token
{{m.name}}
memory 32 GB · model {{m.gbL}} GB
{{m.bwL}} GB/s
effective read · simulation assumption
model {{m.gbL}} GB (same on both)32 GB
{{m.textBefore}}{{m.newTok}}
MEMORY
weight read →
{{m.bwL}} GB/s
COMPUTE
{{m.tokLabel}}
generation speed {{m.speedNote}}
{{m.countL}}
simulated time of one step t = {{tL}} ms
{{m.status}}
0 ms{{axisMidL}} ms{{axisL}} ms
vertical line: token ready after {{m.TL}} ms
Waiting for {{m.waitText}} Without them the compute unit cannot produce the token: every step needs all the weights.
Token ready. The hatched segment is time in which this machine has nothing left to read in this step.
weight block = {{blockGBL}} GB (20 blocks = {{gbL}} GB) already transferred in this step not arrived yet road width ∝ bandwidth current time t · token ready
tok/s
You will see the result and the formula only after you check.
{{streamNote}}
t = {{tL}} ms shared timeline for both machines · pace: {{rateL}} ms of simulation per second
Same prefix ({{sharedPrefixL}}) · both machines compute the same token #{{sharedTokenN}} {{cmpFirst}} {{cmpSecond}}
Jump to:
Calculation

In this model every step reads . At {{bwBL}} GB/s that takes about {{TBL}} ms.

Click {{gbL}} GB to highlight the blocks behind this number on both machines.

Computer A Computer B
Effective bandwidth {{bwAL}} GB/s {{bwBL}} GB/s
Read per token {{gbL}} GB {{gbL}} GB
Estimated token time {{TAL}} ms {{TBL}} ms
Estimated speed {{tpsAL}} tokens/s {{tpsBL}} tokens/s
All values in the table are simulation results for the assumptions above.
Your intuition vs calculation (computer A)
{{cb.label}}{{cb.valL}} tok/s
{{cmpText}}
{{ratioText}}
token time ≈ read per token ÷ bandwidth {{gbL}} GB ÷ {{bwBL}} GB/s = {{TBsL}} s = {{TBL}} ms
tokens/s ≈ bandwidth ÷ read per token {{bwAL}} GB/s ÷ {{gbL}} GB = {{tpsAL}} tok/s

Simplification: a dense model, one generated sequence, {{gbL}} GB of weights read per token. We ignore other memory traffic and assume that decoding is limited by read bandwidth, not by compute.

Where do these bytes come from? Click any weight block in memory, or:
Simulation assumptions (you can change them)
A change recalculates the read time, tokens/s, the road widths and the animation.
Scene 3 · where do the bytes come from?

Block {{sbN}}: look inside

This is the same weight block that just flowed from memory to the compute unit. It holds {{blockGBL}} GB and consists of millions of identical groups.

1 · memory
Model {{gbL}} GB = 20 blocks of {{blockGBL}} GB. Pick another block to compare.
2 · selected block {{sbN}} of 20
{{fragmentLabel}}
{{blockGBL}} GB ≈ {{groupsL}} million groups of 32 weights. The grid shows a sample of groups. The white square is the group shown enlarged.
3 · one group
Click the white group in the block to see how the weights are stored.
{{groupContext}} {{groupTitle}}
{{gc.q}}
{{weightsBytesL}}
each weight is an integer from −8 to 7
{{scaleBytesL}}
{{groupConclusion}}
the same group as a bit string, to scale
128 weight bits16 scale bits
32 × 4 bits + 16 bits = 144 bits per group.
A weight is reconstructed as q × s, e.g. {{q0L}} × {{scaleL}} = {{w0L}}.
At model scale: {{gbL}} GB × 8 bits ÷ 4.5 bits ≈ {{paramsL}} billion weights.
Hover overTap the orange scale segment to expand the calculation.

An illustrative example of a block format. Real formats may store other metadata, for example an extra offset, scales on several levels or groups of a different size. The weight and scale values in this group are examples.

Scene 4 · prediction versus measurement

Compare the prediction with a measurement

The bandwidth estimate describes the stage that generates the next tokens (decode). That is what the measurement is compared with. Prompt processing (prefill) is shown separately.

Bandwidth estimate

{{estTag}}

{{ownFromSampleText}}

{{eBwL}} GB/s ÷ {{eGbL}} GB = {{eTpsL}} tok/s token time ≈ {{eTL}} ms · stage: decode
Your prediction from scene 1: {{guessL}} tok/s
The {{tpsAL}} and {{tpsBL}} tok/s from the previous scenes are simulation results, not measurements.

Engine measurement

Waiting for a benchmark measurement · {{benchSource}}

{{sampleNote}}

{{sampleAssumptionsText}}

{{br.k}}
{{br.v}}
The file has several decode records. Choose the one to compare. The record number is its position in the JSON array.
PREFILL · prompt processing {{prefillL}} not compared: this stage processes many tokens at once
DECODE · next tokens {{decodeL}} {{decodeSamplesL}} compared with the estimate
{{fileErr}}
How to measure
1. Run the engine benchmark with a short prompt and a fixed number of generated tokens. Example for llama.cpp:
llama-bench -m model.gguf -p 512 -n 128 -o json > result.json
Test pp512 is prefill, test tg128 is decode.
2. Note the hardware, the model and quantization, the engine with its version, and the context length.
3. Load the file here or enter the values manually. Only decode is compared with the estimate.
Decode: measurement vs measurement · two runs
{{cmpHeadA}} {{cmpHeadB}}
{{cr.k}} {{cr.a}} {{cr.b}}
{{cmpDiffHead}}: {{cmpDiffL}}
{{cmpPctL}}
{{cmpStatus}}
{{cmpNote}}
{{cmpStatus}}
{{cmpStatus}}
Decode: estimate vs measurement
{{bb.label}}{{bb.valL}} tok/s
{{benchDiffText}}
{{impliedText}}

{{tokenTimeText}}

What is worth checking?
HYPOTHESIS 1 KV cache traffic For every token the engine also reads the keys and values of earlier positions. That read grows with the context length and is not in our formula. How to check: repeat the decode measurement with a short and a long context. If the speed drops as the context grows, the KV cache adds reads.
HYPOTHESIS 2 Compute and dequantization cost 4-bit weights have to be unpacked and multiplied by the scale. If the compute unit cannot keep up, a step takes longer than the read alone. How to check: compare two quantizations of the same model. If the token time does not scale with the number of bytes, something other than memory is the limit.
HYPOTHESIS 3 Bandwidth actually achieved The nominal datasheet value is a ceiling. The effective read under a real workload is often lower. How to check: measure the bandwidth with a memory test (e.g. STREAM) and use the result in the formula with the “Custom” option.
HYPOTHESIS 4 Fixed time per token Part of the time per token may not grow with the bytes read. Our formula assumes that this part is zero. How to check: on the same hardware, with the same decode settings and the same quantization, measure several sizes of one model family, repeating the run for each size. Fit a straight line to the elapsed time per token against the model size. A positive crossing with the time axis supports a fixed cost per token if it stays above zero across the spread of the repetitions. It does not say what causes that cost.
Prediction journal · private

Record your prediction before you measure

Enter how many tokens per second (or milliseconds per token) you expect on your hardware before you run llama-bench. Only you can see the entry.

My prediction

E.g. 4 for a 4 GB model. 1 GB = 10⁹ bytes.

Effective, e.g. 80.

Entry description (optional)

Editors' examples · public

Example scenarios

Ready-made examples from the editors: the weight size, the bandwidth of two computers, a hypothesis and, where available, a sample measurement with its source. This is not data from anyone's journal.

Published scenarios

    Unpublish the scenario?

    Delete the draft?