Calculate bytes per token
For a dense model with full attention, multiply 2 × attention layers × KV heads × KV head dimension × bytes per cache value. The factor of two counts keys and values. Use the KV head count, which can differ from the query head count in grouped-query attention.
Scale by context and concurrency
Multiply bytes per token by your target tokens per sequence and by the number of concurrent sequences. Include input and generated tokens when budgeting total context. The calculator assumes each sequence uses its full cache and does not share a prefix.
Work through an 8B model
The Qwen3 8B preset uses 36 layers, 8 KV heads, and head dimension 128. At 2 bytes per FP16 element, one sequence uses 147,456 bytes of cache per token. At 8,192 tokens, that’s 1.125 GiB. Doubling context or active sequences doubles this part of the estimate.
Qwen3 8B configuration ↗
Account for scales and runtime allocations
The Q8_0 and Q4_0 presets include a 2-byte scale per group of 32 values, so they use 34 and 18 bytes per group respectively. Runtime support can vary. A model file’s disk size can differ from loaded weight memory. Use your runtime’s reported weight memory when you have it.
ggml block sizes ↗
Know what the number covers
The estimate uses 2³⁰ bytes per GiB. Reserve memory for buffers, activations and other programs. Sliding-window attention, offloaded caches, shared prefixes and runtime-specific padding can make real memory usage differ. Memory capacity by itself doesn’t establish model support or generation speed.
Transformers cache types and offloading ↗