Can I run Gemma 4 31B locally?

Gemma 4 31B is a dense model: all 31B parameters are used for every token. 50 of its 60 layers use a 1,024-token sliding window, and only 10 global layers keep the full context.

The architecture can share keys and values in its attention, so the KV cache shown here is an upper bound: about 1.4 GB at 8K tokens and 3.3 GB at 32K.

Estimates with default assumptions: 10% runtime overhead, ~90% usable VRAM (~72% on Macs), FP16 KV cache, one sequence. Model data synced from Hugging Face on 2026-11-23. Methodology.

Gemma 4 31B: memory by quantization

30.7B parameters, 60 layers. Weights are real GGUF file sizes from unsloth/gemma-4-31B-it-GGUF.

QuantizationWeightsTotal at 8K contextTotal at 32K context
F1657.2 GB64.3 GB66.2 GB
Q8_030.4 GB34.8 GB36.7 GB
Q6_K23.5 GB27.2 GB29.1 GB
Q5_K_M20.2 GB23.6 GB25.5 GB
Q4_K_M17.1 GB20.2 GB22.1 GB
IQ4_XS15.2 GB18.2 GB20.1 GB
Q3_K_M13.7 GB16.5 GB18.4 GB
Q2_KUnsloth dynamic file (UD-Q2_K_XL)11.0 GB13.5 GB15.3 GB

Which hardware runs Gemma 4 31B?

Highest-quality quantization that fits fully. “Offload” means it runs only with part of the model in system RAM (64 GB assumed).

Hardware8K context32K context
NVIDIA GeForce RTX 4060 Ti 16GBQ2_K (13.5 GB, big quality loss)Offload Q2_K (~56 layers on GPU)
NVIDIA GeForce RTX 4090Q4_K_M (20.2 GB)IQ4_XS (20.1 GB)
NVIDIA GeForce RTX 5090Q6_K (27.2 GB)Q5_K_M (25.5 GB)
2× NVIDIA GeForce RTX 4090Q8_0 (34.8 GB)Q8_0 (36.7 GB)
Mac with M4 Pro (48 GB)Q6_K (27.2 GB)Q6_K (29.1 GB)
Mac Studio M5 Max (64 GB)Q8_0 (34.8 GB)Q8_0 (36.7 GB)

Try your own setup

Model
Your hardware
Context length (tokens)
Assumptions

Result

Fits fully

Gemma 4 31B · Q4_K_M · 8K → NVIDIA GeForce RTX 4090. 1.42 GB of headroom.

Bar: memory needed vs. usable memory (marker).
Memory breakdown
ComponentMemory
Weightsactual GGUF file: Q4_K_M17.1 GB
KV cache8K tokens × 1 seq, F161.41 GB
Runtime overhead10% of weights1.71 GB
Total needed20.2 GB
Usable on your hardware90% of 24.0 GB21.6 GB
  • This architecture can share keys and values; the KV cache shown is an upper bound.

Run it

Starting point, not a guarantee. Downloads the GGUF from Hugging Face.

llama.cpp
llama-server -hf unsloth/gemma-4-31B-it-GGUF:Q4_K_M -c 8192 -ngl 999
ollama
OLLAMA_CONTEXT_LENGTH=8192 ollama serve
ollama run hf.co/unsloth/gemma-4-31B-it-GGUF:Q4_K_M
Model details
Parameters
30.7BDerived from the BF16 GGUF size (61413190528 bytes / 2 bytes per weight), text model only
Layers
60
Attention
Sliding-window + global layers50× window 1024 (16 KV × 256) · 10× full (4 KV × 512)
Max context
256K
License
apache-2.0
Config source
google/gemma-4-31B-itsynced 2026-10-24

Questions

Does Gemma 4 31B fit on an RTX 4090?

Yes: Q4_K_M needs about 20.2 GB at 8K context. At 32K context IQ4_XS fits (about 20.1 GB). An RTX 5090 fits Q6_K at 8K.

Can I run it on a 16 GB GPU?

Only Q2_K fits fully at 8K context (about 13.5 GB), with a big quality loss. Q4_K_M runs with partial CPU offload, which is much slower for a dense model.

Which Mac should I use?

With the default 72% of unified memory usable, a 48 GB Mac fits Q6_K and a 64 GB Mac fits Q8_0.