How much VRAM does Gemma 4 E2B need at Q4_K_M? Phone-class via interleaved SWA

By TechCompare · Updated · How we check

Gemma 4 E2B at Q4_K_M needs about 4.4 GB at its full 128K context. That suits phones with 8 GB+ unified memory via MLC or Llamafile, integrated graphics laptops, a Raspberry Pi 5 with extra RAM and the Steam Deck. The interleaved SWA design keeps the KV cache to 0.82 GB at that length.

Calculator

Estimated VRAM required

4.4 GB

5.1B params at Q4_K_M, 131,072 token context, batch 1, inference.

Weights
3.2 GB
KV cache
0.9 GB
Overhead
0.4 GB

Estimate accuracy: Weights within ~3% of most GGUF files from Q4_K_M up, ~7% for Q3_K_M and Q2_K. KV cache within ~5% for standard GQA models, ~10% for MLA or hybrid state estimates. Real VRAM may vary with framework (vLLM vs llama.cpp vs Transformers), Flash Attention, and driver overhead.

Sliding-window attention applied: This model caps 5 of every 6 layers at a 512-token window. KV cache estimate is 85% smaller than naive full-attention math at this context length.

Hardware that fits

Unified memory machines show a model budget, not their installed memory. We hold back 8 GB for the system, or use the vendor's GPU limit when that's lower. It's a planning estimate, not a hard limit.

RTX 5060
Consumer
8 GB
54% used
Apple M5 16GB
Unified
~8 GB
54% of estimate
RTX 5070
Consumer
12 GB
36% used
A100 40GB
Datacenter
40 GB
11% used

Gemma 4 E2B at Q4_K_M with native 128K context needs about 4.4 GB of VRAM total. The 'E' stands for Edge: the model is designed for phones, laptops, and integrated graphics.

The architecture is 35 layers with interleaved sliding-window attention: every 5th layer does full attention, the rest cap their KV cache at a 512-token window. Only the full attention layers grow with context, so the KV cache is 0.06 GB at 8K, 0.21 GB at 32K and 0.82 GB at 128K.

How this is calculated

3.12 GB of weights at Q4_K_M (the 5.1B param count includes embedding + LM head, both at full precision), 0.82 GB KV cache thanks to SWA and cache sharing, and ~0.40 GB overhead. The last 20 layers reuse the cache of earlier layers, so only 15 layers store their own. 3 of those cache the full 128K, and the other 12 are capped at 512 tokens.

SWA is the structural feature that makes E2B usable at long context on tiny hardware, because only those 3 full attention layers grow with the prompt.

Verdict

Interleaved SWA and cache sharing do the work on the cache: only 3 of 35 layers cache the full 128K context.

That compression is what makes E2B usable at long context on phones with 8 GB of unified memory and on a Raspberry Pi 5 with extra RAM.

More Gemma scenarios

Kimi K3.1 Pro at Q4_K_M
A 2.78T expert pool with 24 latent attention layers and fixed state in the other 69.
View details
Mistral Large 4 at Q4_K_M
A 1T expert pool with 63 latent cache owners and 44 layers that also store an index key.
View details
Muse Spark Open at Q4_K_M
Only 16 of its 62 layers grow with context, and the other 46 hold a 2,048 token window.
View details

Frequently asked questions

How does interleaved SWA save memory?
Most layers (4 of every 5 in E2B) only attend to the most recent 512 tokens, so their KV cache is capped at 512 tokens regardless of total context. Only every 5th layer is global and caches the full context. E2B also lets its last 20 layers reuse an earlier layer's cache, so just 3 global layers grow with the prompt.
What's the difference between E2B and E4B?
E4B is roughly 8B params with 42 layers and 2 KV heads, about 2x the memory of E2B and noticeably stronger reasoning. Both use the same SWA scheme. Pick E2B for phones, E4B for laptops with 8+ GB GPU memory.
Why does the param count say 5.1B for a '2B' model?
Gemma counts 'E2B' / 'E4B' as effective dense parameters, but the actual file is ~5.1B because of larger embedding tables and tied weights. The calculator uses the actual param count to size weights correctly.