9th July 2026
https://poloclub.github.io/transformer-explainer/
Prefill Phase
Decode Phase
ms
ms
Compute Heavy
Bandwidth Heavy
Compute Heavy
Bandwidth Heavy
Compute Bound
Memory Bound
FLOPs/ sec
FLOPs/ byte
FLOPs/ sec
FLOPs/ byte
Peak FLOPs
FLOPs/ sec
FLOPs/ byte
Peak FLOPs
Bandwidth
FLOPs/ sec
FLOPs/ byte
Peak FLOPs
Bandwidth
Prefill
Decode
<Token>
q
k
v
<Token>
q
k
v
KV Cache= 2
<Token>
q
k
v
KV Cache= 2 * dim
dim
KV Cache= 2 * dim * num heads
KV Cache= 2 * dim * num heads * num layers
Layer 1
Layer 1
Layer 2
Layer n
| Format | Bit |
|---|---|
| FP64 | 8 |
| FP32 | 4 |
| FP16/BF16 | 2 |
| FP8 | 1 |
| FP4 | 0.5 |
KV Cache= 2 * dim * num heads * num layers * kv data type
<Token>
KV Cache= 2 * dim * num heads * num layers * kv data type * seq length
<Token>
<Token>
<Token>
<Token>
<Token>
......
https://huggingface.co/meta-llama/Llama-2-7b
https://huggingface.co/meta-llama/Llama-2-7b
KV Cache= 2 * dim * num heads * num layers * kv data type * seq length