Gemma 4 local setup: which of the five models fits your memory, Ollama, LM Studio, llama.cpp and MLX commands, coding scores and the Apache 2.0 license.
To run Gemma 4 locally, pick the 26B A4B MoE (an 18 GB q4_K_M download, 3.8B active parameters) for a 24 GB GPU or 32 GB+ Mac, the 31B dense model if you can spare 20 GB and want the strongest coder, or E4B and 12B on smaller machines. All five run in Ollama, LM Studio, llama.cpp and MLX under Apache 2.0. The 31B scores 80.0% on LiveCodeBench v6, though many developers prefer Qwen for long agent runs.
- April 2, 2026 (12B on June 3)
- gemma4:26b, 18 GB q4_K_M
- 128K (E2B, E4B), 256K (12B+)
- Apache 2.0
Key takeaways
- Gemma 4 has five models: E2B, E4B, 12B Unified, 26B A4B (MoE, 3.8B active) and 31B dense. Context is 128K on the two small ones and 256K on the rest.
- Ollama q4_K_M downloads run from 4.6 GB (E2B) to 20 GB (31B). The 26B MoE at 18 GB is the usual pick for a 24 GB card because it generates several times faster than the 31B.
- Google's own scores put the 31B at 80.0% LiveCodeBench v6 and 2150 Codeforces Elo, and the 26B A4B at 77.1% and 1718. No SWE-bench numbers are published.
- Tool calling and a thinking mode are built in, but early Ollama and GGUF builds had parser and chat-template bugs, so update your runtime and re-pull old files.
- Gemma 4 is Apache 2.0, not the older Gemma Terms of Use, so commercial use needs no separate acceptable-use policy.
Running Gemma 4 local comes down to one choice: which of the five models fits your memory. On a 24 GB GPU or a 32 GB Mac, start with the 26B A4B mixture-of-experts model. It is an 18 GB download in Ollama and generates fast because only 3.8B parameters are active per token. If you want the best code quality and can live with slower output, use the 31B dense model. Everything below was checked against Google’s model card, the Ollama library and LM Studio on November 2, 2026.
Which Gemma 4 model should you run?
Run the largest Gemma 4 model whose 4-bit file fits in your VRAM or unified memory with a few GB left over for context. Google released Gemma 4 on April 2, 2026 with four models, and added the 12B “Unified” model on June 3, 2026 (Google blog). The table combines the model card with Ollama’s tag list.
| Model | Type | Parameters | Context | Inputs | Ollama q4_K_M | q8_0 | bf16 |
|---|---|---|---|---|---|---|---|
| E2B | Dense | 2.3B effective (5.1B with embeddings) | 128K | Text, image, audio | 4.6 GB | 6.0 GB | 10 GB |
| E4B | Dense | 4.5B effective (8B with embeddings) | 128K | Text, image, audio | 6.6 GB | 9.0 GB | 16 GB |
| 12B Unified | Dense, encoder-free | 11.95B | 256K | Text, image, audio | 8.0 GB | 13 GB | 24 GB |
| 26B A4B | MoE, 128 experts, 8 active + 1 shared | 25.2B total, 3.8B active | 256K | Text, image | 18 GB | 28 GB | 52 GB |
| 31B | Dense | 30.7B | 256K | Text, image | 20 GB | 34 GB | 63 GB |
The sizes follow from the parameter counts. At about 4.5 to 5 bits per weight, 30.7B parameters come to roughly 17 to 19 GB, and the vision encoder adds a little more, which is why the 31B lands at 20 GB. Three things to know before you pick:
- The file is the floor, not the total. Context costs memory on top. Unsloth’s run guide puts total memory for 4-bit at 16 to 18 GB for the 26B A4B and 17 to 20 GB for the 31B. See local LLM hardware requirements for how to budget the KV cache.
- MoE trades memory for speed. The 26B needs nearly the memory of the 31B but computes about an eighth as many parameters per token, so it generates much faster on the same hardware.
- QAT builds are worth a look. Google released quantization-aware-trained checkpoints in June 2026. In Ollama the
-it-qattags are slightly smaller than q4_K_M (16 GB for the 26B, 19 GB for the 31B, 7.2 GB for the 12B).
Ollama’s gemma4:latest points to E4B, not the coding-capable larger models, so always name the tag.
How do you run Gemma 4 in Ollama, LM Studio, llama.cpp and MLX?
Ollama is the shortest path. LM Studio is easiest with a GUI, llama.cpp gives the most control, and MLX is the native option on Apple silicon. For background on the two file formats, see GGUF vs MLX.
Ollama. Pull a tag and raise the context window, because Ollama’s default is only 4K tokens on GPUs under 24 GiB and 32K up to 48 GiB, while its docs recommend at least 64,000 for coding tools.
ollama pull gemma4:26b
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
ollama run gemma4:26b
# dense 31B, or the QAT build
ollama run gemma4:31b-it-qatRun ollama ps afterwards and check the PROCESSOR column. Anything other than 100% GPU means layers spilled to system RAM.
LM Studio. LM Studio lists GGUF and MLX builds of all five models, from 4.20 GB (E2B) to 19.00 GB (31B) (model page). A developer who ran the 26B on a 48 GB M4 Pro published this headless sequence using the lms CLI (blog post, April 2026):
lms get google/gemma-4-26b-a4b
lms load google/gemma-4-26b-a4b --context-length 128000
lms server startllama.cpp. Unsloth’s guide gives this form, with Google’s recommended sampling of temperature 1.0, top_p 0.95 and top_k 64:
./llama.cpp/llama-cli \
-hf unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \
--temp 1.0 --top-p 0.95 --top-k 64For a server, use llama-server with --chat-template-kwargs '{"enable_thinking":false}' to turn thinking off. Unsloth says llama-cli doesn’t reliably disable it.
MLX. Gemma 4 is multimodal, so the mlx-community conversions use mlx-vlm, not mlx-lm (model card):
pip install -U mlx-vlm
mlx_vlm.generate --model mlx-community/gemma-4-26b-a4b-it-4bit --prompt "Write a Python LRU cache"How good is Gemma 4 at coding?
On Google’s published scores, Gemma 4 31B is a strong coder for its size, and a big jump over Gemma 3. The model card reports these instruction-tuned results:
| Model | LiveCodeBench v6 | Codeforces Elo | Tau2 (agentic) |
|---|---|---|---|
| 31B | 80.0% | 2150 | 76.9% |
| 26B A4B | 77.1% | 1718 | 68.2% |
| 12B Unified | 72.0% | 1659 | not published |
| E4B | 52.0% | 940 | not published |
| E2B | 44.0% | 633 | not published |
| Gemma 3 27B (no thinking) | 29.1% | 110 | not published |
Read these with care. They are Google’s self-reported numbers, and LiveCodeBench and Codeforces measure competitive-programming problems, not editing a real repository. Google publishes no SWE-bench or Terminal-Bench scores for Gemma 4, and this site hasn’t run its own tests. Tau2 is the closest thing to an agent benchmark in the card, and there the 31B leads the 26B by almost nine points.
For how Gemma 4 ranks against Qwen, DeepSeek and others, see the best local LLMs for coding. This page stays on running Gemma itself.
We build CandorNo GPU? Use a hosted model
Uncensored AI, right in your browser.
Candor runs open models with refusals removed, so it answers the questions other assistants deflect. New accounts get free credits, no card needed.
Try Candor freeDoes Gemma 4 support tool calling and thinking mode locally?
Yes to both, and both work in the main runtimes, but the early builds were buggy. Google’s launch post lists built-in function calling, structured JSON output and native system instructions (announcement).
How each works:
- Thinking is switched on by putting
<|think|>at the start of the system prompt. The model then writes a thought channel before its answer. Except on E2B and E4B, it emits an empty thought block even with thinking off, so parsers must expect one (model card). - History should hold only final answers from earlier turns, except on tool-call turns, where the card says to keep the thinking.
- Tool calls use dedicated tokens (
<|tool_call>,<|tool_response>) rather than plain JSON. Ollama and llama.cpp translate these into OpenAI-style tool calls. Google’s function-calling guide says thinking “significantly enhances its function-calling accuracy.”
The bugs were real. On launch day, Ollama 0.20.0-rc1 failed to parse Gemma 4 tool calls whenever an argument contained a double quote, such as a git commit message. The issue was fixed and closed on April 3, 2026 (ollama#15241). GGUF files from the first days also shipped with a chat template that later builds corrected. If tool calls fail, update the runtime and re-pull the model before blaming Gemma.
What does the Gemma 4 license allow?
Gemma 4 is released under Apache 2.0, which allows commercial use, modification and redistribution. Google’s launch post calls it a “commercially permissive Apache 2.0 license,” and the Hugging Face cards list apache-2.0.
This is a change. Gemma 1 through 3 and their variants use the separate Gemma Terms of Use. Google’s terms page, last modified April 1, 2026, now covers only the older models and points Gemma 4 users to its own license. So:
- You can ship Gemma 4 inside a paid product, fine-tune it and redistribute the weights.
- You must keep the license and notices and mark files you changed if you redistribute.
- Check the generation. A product still on Gemma 3 is still bound by the older terms.
For how this compares with Llama, Qwen and DeepSeek licenses, see LLM licenses and acceptable use explained.
What do developers report in practice?
Developers broadly agree that the 26B MoE is the fast daily driver, that the 31B writes better code but is slow on Macs, and that Qwen still wins more often for long agentic sessions. These are individual community reports on different hardware, not our tests.
| Setup | Report | Source |
|---|---|---|
| RTX 5090, llama.cpp, 26B A4B Q4_0 | 214 tok/s; 31B QAT Q4_0 ran at 58 tok/s. The poster still prefers Qwen3.6-35B-A3B for coding | HN comment, Jul 2026 |
| MacBook Pro M5, 48 GB | 31B at Q6 about 9 tok/s, “good for coding”; 26B A4B at Q4 about 50 tok/s | HN comment, Apr 2026 |
| M4 Pro, 48 GB, LM Studio, 26B Q4_K_M | 51 tok/s in chat; Claude Code worked through LM Studio’s server but slowed down, hit swap, and suited single-file tasks | Blog post, Apr 2026 |
| Laptop with about 4.5 GB free VRAM, llama.cpp, 26B A4B | 200 to 300 tok/s prompt processing and 20 to 40 tok/s output, after a lot of parameter tuning | HN comment, Oct 2026 |
Ollama MLX runner, gemma4:31b-coding-mtp-bf16 | About 2x faster on coding tasks with the multi-token-prediction drafter; quantized models had lower draft acceptance | HN comment, May 2026 |
The qualitative reports split along task type:
- Code understanding: Gemma. An r/LocalLLaMA poster found the 31B better than Qwen 3.6 27B and 35B-A3B at explaining and extending messy research code, especially at tracing how one change affects other parts (thread). Commenters in the same thread said Gemma is strongest in short contexts of 10K to 20K tokens.
- Agent loops: often Qwen. Several commenters in that thread keep Qwen for long-context agentic work and tool calling. On Hacker News, one developer called Qwen3.6 the consensus pick for coding, with Gemma stronger at OCR and audio, and said the harness matters most at this size (HN comment, May 2026). Another found Gemma 4 tool use good but agentic coding not yet working well for them (HN comment, Apr 2026).
- Settings matter. One developer got better results from the 31B on a small C project at temperature 0 (HN comment, May 2026). That conflicts with Google’s recommended temperature of 1.0, so test both on your own code.
Multi-token prediction is the speed lever to watch. Google’s MTP post claims up to a 3x speedup with unchanged output quality, and about 2.2x for the 26B on Apple silicon at batch sizes of 4 to 8. The Ollama coding MTP tag is a 64 GB bf16 download and, per one user, requires macOS (HN comment).
FAQ
What are the Gemma 4 local requirements?
At 4-bit, plan on about 5 GB of free memory for E2B, 7 GB for E4B, 8 GB for the 12B, and 18 to 20 GB for the 26B A4B and 31B, plus room for context. A 24 GB GPU or a 32 GB Mac runs either large model at 4-bit.
Is Gemma 4 good for coding?
For its size, yes. The 31B scores 80.0% on LiveCodeBench v6 per Google’s model card. Developers report it is strong at reading and editing code in short contexts, but many still prefer Qwen models for long agentic coding sessions.
Which is better locally, Gemma 4 26B or 31B?
The 26B A4B is several times faster because only 3.8B parameters are active per token. The 31B scores higher on every coding benchmark Google publishes. Use the 26B for interactive work and the 31B when accuracy matters more than speed.
Can I use Gemma 4 with a coding agent like Claude Code?
Yes. Ollama and LM Studio expose compatible servers, and developers have run Gemma 4 behind Claude Code. Expect it to handle focused single-file tasks better than long multi-step agent runs, and set the context to at least 64K.
Can I use Gemma 4 commercially?
Yes. Gemma 4 is Apache 2.0, so commercial use, fine-tuning and redistribution are allowed as long as you keep the license and notices.
We build CandorSkip the setup
Want an uncensored model without hosting one?
Candor (candorai.dev) is an uncensored AI chat app that runs in your browser: it answers the questions mainstream assistants dodge, on health, money, law and work, without the lecture. New accounts get free credits, no card needed.
Facts from candorai.dev, checked Nov 10, 2026. Candor never changes how we rank or review models. Disclosure.
Sources (10)
- Gemma 4 model card, Google AI for Developers
- google/gemma-4-26B-A4B-it, Hugging Face model card
- Gemma 4 launch post, Google blog (April 2, 2026)
- gemma4 tags, Ollama library
- Gemma 4, LM Studio model page
- Gemma 4 run guide, Unsloth documentation
- Function calling with Gemma, Google AI for Developers
- Accelerating Gemma 4 with multi-token prediction drafters, Google blog (May 5, 2026)
- gemma4:31b - Tool Call Fails, ollama/ollama issue #15241
- Context length, Ollama documentation
Written by Refusal Rate editors from papers, model cards, official docs and pricing pages. Anything we ran ourselves is labeled as our own test, with the hardware and settings. Our method.