# Same file size, five times the context memory

**URL:** <https://discuss.huggingface.co/t/same-file-size-five-times-the-context-memory/191947>\
**Category:** Show and Tell\
**Created:** [November 16, 2026, 2:47pm UTC](https://discuss.huggingface.co/t/same-file-size-five-times-the-context-memory/191947 "2026-11-16T14:47:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyferUnknown](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/cyferunknown/32/65188_2.png) [@CyferUnknown](https://discuss.huggingface.co/u/CyferUnknown)\
**Post date:** [November 16, 2026, 2:47pm UTC](https://discuss.huggingface.co/t/same-file-size-five-times-the-context-memory/191947/1 "2026-11-16T14:47:23Z")

</div>

Most “will it run on my card” answers count the file. I did that too for a long time: file size plus a bit, done. Then I started computing the context cache per model for a small site I run, and the file turned out to be the boring part.

Two models with almost the same file:

| | Q4\_K\_M file | context cache at 32K | total at 32K |
| --- | --- | --- | --- |
| Qwen3 8B | 4.7 GB | 4.5 GB | 10.9 GB |
| Gemma 4 E4B | 4.6 GB | 0.9 GB | 7.2 GB |

On a 12 GB card the first one spills into system RAM at 32K and the second one has room to spare. Same download size.

## Why

The cache is plain arithmetic from `config.json`:

```auto
bytes per token = 2 × layers × kv_heads × head_dim × 2 (keys and values, f16)

```

Qwen3 8B has 36 layers and every one of them keeps the whole context, with 8 KV heads of 128. That’s 147,456 bytes per token. Times 32,768 tokens you land at 4.5 GB.

Gemma 4 E4B has 42 layers, but only 7 of them keep the whole context. The other 35 are sliding-window layers that stop at 512 tokens, so they cost under 40 MB no matter how long the chat gets. The 7 full ones come to 28,672 bytes per token, about 0.9 GB at 32K.

This isn’t a Gemma thing. gpt-oss 20B keeps the full context in 12 of its 24 layers, Gemma 3 27B in 10 of 62, Qwen3.8 27B in 16 of 64. Put Gemma 3 27B at 32K into the every-layer formula and you get about 15 GB of cache. It’s 2.9.

## Where it decides things

The pick on my site this week is Qwen3 14B, an 8.4 GB file. At 8K context it needs 10.8 GB all in. A 12 GB card has about 10.6 left once you keep a margin for the driver and the desktop. So it misses by 0.2 GB. It loads fine, and then it spills.

Here’s a 12 GB card (RTX 3060) with a few models people ask about. All numbers in GB:

| Model (Q4\_K\_M) | File | Total at 8K | | Total at 32K | |
| --- | --- | --- | --- | --- | --- |
| Granite 4.2 3B | 2.1 | 3.6 | fits | 6.3 | fits |
| Gemma 4 E4B | 4.6 | 5.8 | fits | 7.2 | fits |
| Qwen3 8B | 4.7 | 6.8 | fits | 10.9 | spills |
| Gemma 4 12B | 6.6 | 8.1 | fits | 9.2 | fits |
| Qwen3 14B | 8.4 | 10.8 | spills | 15.3 | spills |
| gpt-oss 20B | 10.8 | 12.2 | spills | 13.5 | spills |

Look at Gemma 4 12B and Qwen3 8B at 32K. The bigger file fits, the smaller one doesn’t.

And this is what a bigger card buys you, counted over the 49 models I track (a comfortable fit, not “barely”):

| Card | at 8K | at 32K |
| --- | --- | --- |
| 8 GB | 10 | 5 |
| 12 GB | 15 | 12 |
| 16 GB | 17 | 14 |
| 24 GB | 24 | 19 |

Going from 12 to 16 GB gets you two more models. I did not expect that.

## Where I got it wrong

In October someone here on the forum recomputed my Gemma 4 numbers from the configs and found that I was giving the full-attention layers the wrong head shape. My cache for Gemma 4 12B at 32K was 2.3 GB. The real number is 0.8. That changed the verdict on a 12 GB card from “spills” to “fits”. It’s fixed, and the thread with the math is still up: [LFM2.5 8B-A1B measured: 0.4 GB of context cache at 32K, and why that matters more than the file size](https://discuss.huggingface.co/t/190787)

I mention it because the same kind of mistake can sit in another model right now and I wouldn’t know. If a number looks off for something you run, tell me.

## What this doesn’t tell you

- Speed. I don’t measure tokens per second, so I don’t publish any.
- Two of the 49 models, Llama 3.1 8B and Llama 3.2 3B, have gated configs. No attention shape, no cache number. They show up as unknown instead of a guess.
- The runtime overhead (about 1 GB at 8K, close to 2 GB at 32K) is an assumption, not a measurement. So is the 12 percent I keep free on the card.

## If you want to play with it

I put the whole thing into a Space that draws the card like an X-ray. The file settles into the memory, the cache grows when you drag the context up, and you see the moment it spills: [The Card, Seen Through - a Hugging Face Space by CyferUnknown](https://huggingface.co/spaces/CyferUnknown/llm-vram-xray)

The numbers are also there as a dataset (CC BY 4.0): [CyferUnknown/open-model-vram-requirements · Datasets at Hugging Face](https://huggingface.co/datasets/CyferUnknown/open-model-vram-requirements)
