Skip to content
Inference Academy

Can I run Gemma 4 31B on Apple M5 (24GB)?

Yes: Gemma 4 31B runs on Apple M5 (24GB) with Q2_K at roughly 7 tokens/s. Estimated memory 14.7 GiB at 8,192 tokens of context.

Share

With Q2_K you can push the context to about 12,800 tokens before memory runs out (F16 KV cache).

Memory by quantisation (8,192-token context)

QuantisationMemoryVerdictEst. speed
F16Unquantized reference59.9 GiBDoes not fit—
Q8_0Near-lossless33.1 GiBNeeds CPU offload—
Q6_KVery close to F1626.1 GiBNeeds CPU offload—
Q5_K_MGreat quality/size23.0 GiBNeeds CPU offload—
Q4_K_MBest default for most20.0 GiBNeeds CPU offload—
IQ4_XSSmaller 4-bit (imatrix)17.9 GiBNeeds CPU offload—
Q3_K_MNoticeable loss16.7 GiBTight~6 tok/s
Q2_KLast resort; big loss14.7 GiBFits~7 tok/s

Apple M5 (24GB) offers about 24 GiB of memory (70% usable for a model) at 153 GB/s. Speed is a bandwidth-bound estimate of single-stream generation at 65% efficiency; real results vary by runtime, drivers and settings, so measure on your machine.

The best setup on Apple M5 (24GB)

The highest-quality build that fits is Q2_K, using about 14.7 GiB of the 16.8 GiB this device can give a model, leaving about 2.1 GiB spare. Decode speed is estimated at 7 tokens per second, which is about 5 words per second, roughly reading speed, fine for chat but slow for long answers or agents that make many calls.

Q2_K is aggressive and the quality loss is noticeable, especially on reasoning and code. If you can, pick a smaller model at 4 bits instead: it usually beats a larger model squeezed to Q2_K.

Context length and memory headroom

Gemma 4 31B only keeps a full-length cache in 10 of its 60 layers; the other 50 use a 1,024-token sliding window whose cache stops growing, which keeps long contexts cheap. At the default f16 cache, every 1,000 tokens of context costs about 80 MB, so an 8,192-token conversation holds about 1.41 GiB of cache.

With Q2_K the context could stretch to roughly 12,800 tokens before memory runs out. Quantising the cache to q8_0 halves that cost.

The spare memory could hold about 1 more 8,192-token conversation at once if you serve several people from this machine.

Could you run something bigger?

Among the models we track, Gemma 4 31B is about the largest this hardware runs well. Going up in size means more memory or a lower quantisation, and below 4 bits quality drops quickly.

Why the speed is what it is

Generating a token means reading about 18.6 GB of weights from memory at Q4_K_M. Apple M5 (24GB) moves about 153 GB per second, so the absolute ceiling is roughly 8 tokens per second, and real runs reach about 65 percent of that. The compute units are mostly waiting for memory, which is why bandwidth matters more than raw GPU or CPU speed for single-user chat.

On a Mac, Ollama and LM Studio use the GPU through Metal automatically, and MLX often decodes a little faster for the same model. Keep other memory-hungry apps closed, because the GPU can only wire about three quarters of unified memory by default.

How this is calculated

Weights ≈ parameters × bits per weight ÷ 8. KV cache ≈ 2 × 10 full-attention layers × 4 KV heads × 512 head dim × 2 bytes per token, plus 50 sliding-window layers capped at 1024 tokens. Decode speed ≈ efficiency × memory bandwidth ÷ bytes read per token. Learn the maths in VRAM math and memory bandwidth, or try the VRAM calculator.

Running slowly or out of memory? See CUDA out of memory and the quantisation lesson.