Attention-cache (KV) memory and re-read cost

Bytes per token
K, V
Load

Qwen3-8B model card: “Context Length: 32,768 natively and 131,072 tokens with YaRN.”

cache, all chats

per chat
all chats
Does it fit?
GPU memory
Conversation
Window at the last reply
Message 1, the first instruction

Tokens processed after the replies
CaseTokens× written
History re-sent every reply
Cut to the window
Prefix cache: each token once

Assumptions and limits

Starts from the Qwen3-8B settings saved with the lesson code. Assumes full attention in every layer, the cache stored at the value type shown, and nothing in GPU memory but weights and cache (no activations, framework overhead or fragmentation). GiB and MiB are powers of 1,024. 8-bit and 4-bit only divide bytes per value; real quantised caches also store scale factors. Qwen3-8B has 32 query heads sharing 8 KV heads: set KV heads to 32 to see the cache without sharing.