QAT & GGUF Guide
Gemma 4 QAT, Ollama & GGUF VRAM Guide (Weights-Only vs. 8K Total)
Verified Gemma 4 QAT (gemma4:12b-it-qat ~7.2 GB) and ggml-org GGUF guide reconciling official Weights-Only VRAM (2.9 GB / 4.5 GB / 6.7 GB) against real 8K-context Total VRAM and Qwen 3.5 4B (3.0 GB / 3.7 GB VRAM).
When sizing a GPU or Apple Silicon Mac for Gemma 4, developers frequently run into two conflicting numbers: Google DeepMind model cards quote bare 4-bit Weights-Only memory (2.9 GB for E2B, 4.5 GB for E4B, and 6.7 GB for 12B), while real local runtimes like Ollama, llama.cpp, and LM Studio allocate 4.5–6.0 GB, 6.5–8.0 GB, and 9.5–12.0 GB at an 8,192-token context window.
Both figures are mathematically correct—they measure different stages of inference. Meanwhile, Google and Ollama now distribute official Quantization-Aware Trained (QAT) 4-bit tags such as ollama pull gemma4:12b-it-qat (~7.2 GB download) alongside community ggml-org Q4_K_M GGUF builds, delivering near-BF16 reasoning quality at 3x lower VRAM. Below is the complete dual-column VRAM calibration table, exact CLI commands, and side-by-side comparison with compact contenders like Qwen 3.5 4B.
1. Dual-Column Calibration: Official Weights-Only VRAM vs. 8K-Context Total VRAM
Static weight size only accounts for quantized transformer and vision parameters sitting idle on disk or copied into GPU memory at zero context. The moment llama.cpp or Ollama initializes an active session, total VRAM expands according to: Total VRAM = Quantized Model Weights + Vision/Audio Projector (mmproj) + 8K KV Attention Cache + Backend Compute Graph Buffers (~450–900 MB on CUDA/Metal).
Use the dual-column table below to cross-check Google DeepMind official weights-only documentation against real-world 8K-context allocation across Ollama QAT tags, ggml-org GGUF files, and Alibaba Qwen 3.5 4B:
| Model Checkpoint | Official Weights-Only (Q4) | Ollama QAT / GGUF Download | 8K-Context Total VRAM | Minimum Comfortable Hardware |
|---|---|---|---|---|
| Qwen 3.5 4B (Q4_K_M) | 2.5 GB (text) / 3.0 GB pkg | 3.0 GB (qwen3.5:4b) | 3.7 GB | 6 GB RTX 3060 Laptop, 8 GB Mac M1/M2 |
| Gemma 4 E2B IT (QAT / Q4) | 2.9 GB | ~3.1–3.4 GB | 4.5–6.0 GB | 6–8 GB RTX Laptop, 8 GB Mac, 8 GB Android |
| Gemma 4 E4B IT (QAT / Q4) | 4.5 GB | ~4.6–5.3 GB | 6.5–8.0 GB | 8 GB RTX 4060 / 3070, 16 GB Apple Silicon |
| Gemma 4 12B IT (QAT 4-bit) | 6.7 GB | ~7.2 GB (gemma4:12b-it-qat) | 9.5–12.0 GB | 12 GB RTX 3060 / 4070, 16–24 GB Mac |
| Gemma 4 26B-A4B MoE (QAT) | 14.8 GB | ~15.8 GB | 18.5–22.0 GB | 24 GB RTX 3090 / 4090, 32 GB+ M2/M3/M4 Max |
| Gemma 4 31B IT (QAT / Q4_K_M) | 17.6 GB | ~18.4 GB | 22.0–25.5 GB | 24 GB RTX 4090 (tight 8K), 36–48 GB Mac Studio |
2. Why Official QAT (gemma4:12b-it-qat) Beats Naive 4-Bit Post-Training Quantization
Standard GGUF files (such as Q4_0 or Q4_K_M) apply Post-Training Quantization (PTQ): a finished 16-bit BF16 checkpoint is rounded down to 4-bit block weights using calibration heuristics or importance matrices (imatrix). On multimodal instruction models with 128K–256K RoPE scaling and delicate vision-language cross-attention, naive 4-bit rounding can degrade multi-step coding accuracy, JSON schema adherence, and multilingual precision.
Quantization-Aware Training (QAT) solves this during Google DeepMind training itself. Simulated int4 quantization noise is injected into forward passes for thousands of gradient steps so weights adapt around low-bit quantization boundaries before export. When packaged into Q4_0 / Q4_K GGUF tensors (~7.2 GB for 12B IT QAT), QAT recovers roughly 55%–70% of the perplexity gap between standard PTQ Q4 and unquantized 24 GB BF16—without costing a single extra megabyte of runtime VRAM or slowing down CUDA/Metal kernels.
- Identical inference throughput: QAT checkpoints compile down to standard llama.cpp integer block formats (primarily Q4_0 + high-precision embedding/output tensors), running at full memory-bandwidth speed on NVIDIA Tensor Cores, Apple Metal, and Vulkan.
- Multimodal projector intact: Official Ollama -qat tags bundle the calibrated vision encoder weights (~600–850 MB), explaining why gemma4:12b-it-qat downloads ~7.2 GB on disk even though bare 4-bit text weights measure 6.7 GB.
- Cleaner 8 GB / 12 GB edge behavior: Fewer outlier activation spikes make QAT checkpoints noticeably steadier when paired with Q8_0 KV cache quantization (-ctk q8_0 -ctv q8_0).
3. Verified Ollama QAT & ggml-org GGUF CLI Commands (Copy & Run)
For 90% of desktop Mac, Linux, and Windows NVIDIA users, pulling the official QAT manifest in Ollama is the fastest one-command setup. If you want granular control over flash attention, quantized KV cache, or split MoE offloading, pull the upstream ggml-org GGUF directly into llama.cpp (build b5000+):
# 1) Official Ollama 4-bit QAT (~7.2 GB download, 9.5–12 GB VRAM at 8K context)
ollama pull gemma4:12b-it-qat
ollama run gemma4:12b-it-qat
# Smaller 8 GB GPU / Laptop QAT & Qwen 3.5 4B alternatives
ollama pull gemma4:e4b-it-qat
ollama pull qwen3.5:4b
# 2) Direct llama.cpp CLI with official ggml-org Hugging Face GGUF + Flash Attention + Q8 KV Cache
llama-cli \
-hf ggml-org/gemma-4-12b-it-QAT-Q4_0-GGUF \
-ngl 99 \
-fa on \
-c 8192 \
-ctk q8_0 -ctv q8_0 \
--temp 1.0 --top-k 64 --top-p 0.95
# 3) Local OpenAI-compatible HTTP server on port 8080 (ggml-org Q4_K_M GGUF)
llama-server \
-hf ggml-org/gemma-4-12b-it-GGUF:Q4_K_M \
-ngl 99 -fa on -c 8192 --port 80804. Head-to-Head on 4 GB – 8 GB GPUs: Qwen 3.5 4B vs. Gemma 4 E2B & E4B
When dedicated GPU VRAM is capped at 4 GB, 6 GB, or 8 GB (RTX 3050, RTX 3060 Laptop, RTX 4060, Steam Deck, or base 8 GB M1/M2 MacBooks), picking between Alibaba Qwen 3.5 4B and Google Gemma 4 E2B/E4B hinges on exact sub-gigabyte headroom.
Because Gemma 4 E2B and E4B use Per-Layer Embeddings (PLE) and native multimodal tokenizers, their total parameter files are slightly heavier than pure dense 4B text models. Qwen 3.5 4B at Q4_K_M downloads ~3.0 GB (2.5 GB text backbone + tokenizer/projector overhead) and settles at just 3.7 GB total VRAM at an 8K context window—making it the cleanest fit on 4 GB–6 GB discrete GPUs where Gemma 4 E4B (6.5–8.0 GB total VRAM) would spill across PCIe.
| Metric | Qwen 3.5 4B (Q4_K_M) | Gemma 4 E2B IT (QAT) | Gemma 4 E4B IT (QAT) |
|---|---|---|---|
| Download Size (Q4) | 3.0 GB (2.5 GB bare GGUF) | ~3.1–3.4 GB | ~4.6–5.3 GB |
| Weights-Only VRAM | 2.5–2.8 GB | 2.9 GB | 4.5 GB |
| 8K-Context Total VRAM | 3.7 GB | 4.5–6.0 GB | 6.5–8.0 GB |
| 6 GB Laptop GPU Fit | Smooth (~45–65 tok/s) | Comfortable (~40–55 tok/s) | Tight (4K ctx + Q8 KV) |
| 8 GB RTX 4060 Fit | Headroom for 32K+ ctx | Headroom for 32K+ ctx | Sweet spot at 8K–16K ctx |
| Best Strength | Compact coding, STEM & low-VRAM fit | Mobile/Edge multimodal + audio | Strongest 8 GB multimodal reasoning |
5. Reclaiming 1.5–2.5 GB of VRAM: KV Cache Quantization & Context Sizing
If gemma4:12b-it-qat (~7.2 GB on disk) overflows your 8 GB or 12 GB GPU when you paste long repository files, the culprit is almost never the model weights—it is an oversized default context allocation or unquantized FP16 KV cache.
In Ollama, set OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0 in your service environment, and cap num_ctx at 8192 inside a custom Modelfile instead of pre-allocating 32768 or 65536 tokens. On Gemma 4 12B, dropping from 32K FP16 KV cache down to 8K Q8_0 KV cache trims active VRAM from ~13.4 GB down to ~9.6 GB, keeping every single transformer layer locked inside fast 12 GB GDDR6X memory.
6. Apple Silicon Unified Memory Ceiling vs. Discrete NVIDIA PCIe GPUs
On discrete NVIDIA RTX GPUs (RTX 3060 12 GB, RTX 4060 Ti 16 GB, RTX 4090 24 GB), VRAM is physically separate from host DDR4/DDR5 RAM across a PCIe bus. Crossing that boundary by even 400 MB drops token generation by 60%–80%, which is why checking the 8K-Context Total VRAM column—rather than bare Weights-Only VRAM—is mandatory before pulling a larger tag.
On Apple Silicon Macs (M1, M2, M3, M4), macOS reserves roughly 25%–33% of unified memory for WindowServer and kernel pages by default. That means a 16 GB MacBook Pro practically exposes ~10.5–12.0 GB to Metal GPU allocation—making gemma4:e4b-it-qat (~6.5–8.0 GB total) effortless and gemma4:12b-it-qat (~9.5–11.2 GB with Q8_0 KV cache) achievable when heavy browser tabs are closed, while 24 GB+ Macs run 12B QAT with comfortable 32K context headroom.
How to Run Gemma 4 12B QAT Locally Without Spilling Over GPU VRAM
- Verify your usable GPU VRAM or Apple Silicon unified memory ceiling (target >=12 GB VRAM for Gemma 4 12B IT QAT, >=8 GB for E4B QAT, or >=4 GB for Qwen 3.5 4B Q4_K_M).
- Enable Flash Attention and Q8_0 KV cache quantization (export OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0 before starting ollama serve, or pass -fa on -ctk q8_0 -ctv q8_0 in llama.cpp).
- Pull the official Quantization-Aware Trained checkpoint via ollama pull gemma4:12b-it-qat (~7.2 GB download) or download ggml-org/gemma-4-12b-it-QAT-Q4_0-GGUF.
- Run an interactive 8,192-context session and confirm with ollama ps or nvidia-smi that 100% of layers remain on GPU (0% CPU split).
Recommended models
Frequently asked questions
- Why does Google list Gemma 4 12B at 6.7 GB while Ollama and llama.cpp use 9.5–12 GB VRAM?
- Google DeepMind reports bare 4-bit transformer weight size (6.7 GB) at zero context. Once you load the multimodal vision projector (~0.5–0.8 GB), allocate an 8,192-token KV attention cache (~1.2–2.2 GB), and initialize CUDA/Metal compute buffers (~0.6–0.9 GB), real-world total VRAM sits between 9.5 GB and 12.0 GB.
- What is the exact Ollama command for the official Gemma 4 12B QAT model?
- Run ollama pull gemma4:12b-it-qat followed by ollama run gemma4:12b-it-qat. The QAT 4-bit archive downloads roughly 7.2 GB and preserves near-BF16 instruction and coding accuracy without increasing VRAM usage over standard Q4_K_M.
- Should I download ggml-org GGUF or Unsloth Dynamic Q4_K_XL GGUF?
- Both work seamlessly in llama.cpp and LM Studio. Official ggml-org QAT GGUF builds mirror Google DeepMind Quantization-Aware Training weights directly, while Unsloth Dynamic 2.0 quants (Q4_K_XL) selectively upcast sensitive attention and vision layers to 6-bit/8-bit at a ~0.4–0.7 GB larger file size.
- How much VRAM does Qwen 3.5 4B Q4_K_M actually need compared to Gemma 4 E2B?
- Qwen 3.5 4B Q4_K_M requires roughly 3.0 GB on disk (2.5 GB bare text GGUF) and 3.7 GB total VRAM at an 8K context window, making it ~0.8–1.5 GB lighter in active memory than Gemma 4 E2B IT (4.5–6.0 GB with PLE and multimodal buffers).
- Can an 8 GB RTX 4060 run gemma4:12b-it-qat without slow CPU offloading?
- Not at full 100% GPU residency—a 7.2 GB checkpoint plus CUDA context and KV cache exceeds 8.0 GB, forcing 4–8 layers onto PCIe system RAM and dropping speed to ~6–11 tok/s. On 8 GB cards, gemma4:e4b-it-qat (6.5–8.0 GB total VRAM) or qwen3.5:4b (3.7 GB total VRAM) runs 4x–6x faster.