The most capable open model family, built from Gemini 3 research. Now in five sizes — with Multi-Token Prediction drafters for faster inference. Frontier intelligence, free, Apache 2.0, running on your own hardware.
# Install Ollama (Mac / Linux) curl -fsSL https://ollama.com/install.sh | sh # Pull and run Gemma 4 — choose your size ollama run gemma4:e2b # 2B — phones, Pi ollama run gemma4:e4b # 4B — laptop ollama run gemma4:12b # 12B unified — laptop ★ balanced ollama run gemma4:26b # 26B MoE — workstation ★ recommended ollama run gemma4:31b # 31B dense — server / H100 # REST API (once running) curl http://localhost:11434/api/chat \ -d '{"model":"gemma4","messages":[{"role":"user","content":"Hello!"}]}'
from transformers import AutoProcessor, AutoModelForImageTextToText import torch # Load model — swap model_id for your chosen size model_id = "google/gemma-4-26b-it" # or e2b-it / e4b-it / 12b-it / 31b-it processor = AutoProcessor.from_pretrained(model_id) model = AutoModelForImageTextToText.from_pretrained( model_id, torch_dtype=torch.bfloat16, device_map="auto", ) messages = [{ "role": "user", "content": [{"type": "text", "text": "Explain quantum entanglement."}] }] inputs = processor.apply_chat_template( messages, tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, enable_thinking=True, # ← thinking mode! ).to(model.device) output = model.generate(**inputs, max_new_tokens=2048) print(processor.decode(output[0], skip_special_tokens=True))
# pip install google-genai from google import genai client = genai.Client(api_key="YOUR_API_KEY") response = client.models.generate_content( model="gemma-4-31b-it", # or gemma-4-26b-it / 12b-it contents="Write a haiku about open-source AI.", ) print(response.text) # ── REST equivalent ───────────────────────────────── # curl "https://generativelanguage.googleapis.com/v1beta/ # models/gemma-4-31b-it:generateContent?key=YOUR_KEY" \ # -H 'Content-Type: application/json' -X POST \ # -d '{"contents":[{"parts":[{"text":"Hello!"}]}]}'
# Install vLLM pip install vllm # Start OpenAI-compatible server vllm serve google/gemma-4-26b-it \ --dtype auto \ --max-model-len 65536 \ --tensor-parallel-size 2 # for multi-GPU # Query via OpenAI SDK from openai import OpenAI client = OpenAI( base_url="http://localhost:8000/v1", api_key="none", ) resp = client.chat.completions.create( model="google/gemma-4-26b-it", messages=[{"role":"user","content":"Hello Gemma!"}], ) print(resp.choices[0].message.content)
# Install MLX LM pip install mlx-lm # Run inference (4-bit quantized) mlx_lm.generate \ --model mlx-community/gemma-4-e4b-it-4bit \ --prompt "Explain transformers simply." \ --max-tokens 512 # Or 26B at 4-bit for M2 Max / M3 Max (≥64 GB) mlx_lm.generate \ --model mlx-community/gemma-4-26b-it-4bit \ --prompt "Write a Python quicksort." \ --max-tokens 1024 # Python API from mlx_lm import load, generate model, tokenizer = load("mlx-community/gemma-4-e4b-it-4bit") response = generate(model, tokenizer, prompt="Hello!", max_tokens=256) print(response)
# NVIDIA NIM — containerised, production-ready docker run --gpus all \ -p 8000:8000 \ nvcr.io/nim/google/gemma-4-26b-it:latest # Unsloth Fine-tune Studio (Mac / Linux / WSL) pip install unsloth # Dockerfile snippet for custom build FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04 RUN pip install vllm transformers COPY serve.py /app/serve.py CMD ["python", "/app/serve.py"]
| Benchmark | What it measures | Gemma 4 31B |
|---|---|---|
| AIME 2026 ★ Math | Competition mathematics | |
| MMLU Pro | Knowledge & reasoning | |
| GPQA Diamond | Graduate-level science reasoning | |
| LiveCodeBench v6 | Code generation |
Gemma 4 is Google DeepMind's most capable family of open-weight AI models, launched on April 2, 2026 and built from the same research as the frontier Gemini 3 models. It's designed to deliver frontier-level reasoning small enough to run on your own hardware.
It ships in five sizes — E2B, E4B, the 12B Unified, a 26B Mixture-of-Experts, and a 31B Dense flagship — all under a permissive Apache 2.0 license. The models are multimodal (text, image and video input, with native audio on E2B, E4B and 12B), fluent in 140+ languages, support up to 256K context, and include configurable thinking mode, function calling, and MTP drafters for faster inference.
Match the model to your hardware and use case — E2B/E4B for phones and laptops, 12B for balanced local use, 26B/31B for workstations and servers. See the Model Variants above for specs.
Easiest is Ollama (one command). Prefer a GUI? Use LM Studio. Want raw weights for Python? Use Hugging Face or Kaggle. On a Mac, MLX is fastest; for CPU or any hardware, llama.cpp.
Gemma 4 is gated: click Accept once on the Hugging Face or Kaggle model card (or authenticate with a token in scripts). It's Apache 2.0 — commercial use is allowed. Ollama and LM Studio handle this for you.
Install a runner and pull the model. With Ollama: ollama run gemma4:12b. With Transformers: pip install transformers then load google/gemma-4-12b-it. The weights download automatically on first run, then work fully offline.
Gemma is a family of generative AI models for tasks like question answering, summarization, and reasoning. The models are provided with open weights and permit responsible commercial use, so you can tune and deploy them in your own projects. Gemma 4 spans four distinct architectures across five sizes, each tuned for specific hardware:
Effective 2B and 4B dense models built for ultra-mobile, edge, and browser deployment (think Pixel and Chrome). They use Per-Layer Embeddings (PLE) to squeeze maximum capability out of a tiny on-device footprint.
A 12B encoder-free multimodal model that replaces separate vision and audio encoders with direct linear projections of the input — feeding images and audio straight into the LLM backbone.
A highly efficient 26B MoE built for high-throughput, advanced reasoning. It activates only ~4B parameters per token, so it delivers fast tokens-per-second while keeping flagship-class quality.
A powerful 31B dense model that bridges server-grade performance and local execution — the top pick for maximum quality and a strong base for fine-tuning.
Reasoning: every model is a capable reasoner with configurable thinking modes. Extended multimodality: all sizes process text and images (variable aspect ratio and resolution) plus video, with native audio on E2B, E4B, and 12B. Context: 128K on the small models, 256K on the medium ones. Coding & agents: notable coding gains with built-in function calling for autonomous agents. Native system prompts: first-class support for the system role. Multi-Token Prediction: every size ships a dedicated draft model for speculative decoding — significantly faster inference with no quality loss.
Gemma 4 comes in five sizes (E2B, E4B, 12B, 26B A4B, 31B), usable at default 16-bit precision or lower via quantization. Approximate memory to load the weights (with ~20% overhead) is below — mobile figures use LiteRT-LM:
| Model | BF16 (16-bit) | SFP8 (8-bit) | Q4_0 (4-bit) | Mobile | Mobile (text-only) |
|---|---|---|---|---|---|
| Gemma 4 E2B | 11.4 GB | 5.7 GB | 2.9 GB | 1.1 GB | 0.84 GB |
| Gemma 4 E4B | 17.9 GB | 8.9 GB | 4.5 GB | 2.5 GB | 2.2 GB |
| Gemma 4 12B | 26.7 GB | 13.4 GB | 6.7 GB | — | — |
| Gemma 4 26B A4B | 57.7 GB | 28.8 GB | 14.4 GB | — | — |
| Gemma 4 31B | 69.9 GB | 34.9 GB | 17.5 GB | — | — |
Figures cover static weights only and may change with your inference tool and environment. Note: PLE makes the small models' load memory higher than their effective-parameter count suggests; the 26B MoE must load all 26B params even though only ~4B are active per token; and the KV cache for long context adds VRAM on top. Fine-tuning needs far more memory than inference — use PEFT methods like LoRA to keep it manageable.
For maximum efficiency with minimal quality loss, Google ships official QAT checkpoints. Unlike post-training quantization (which compresses a finished model and can degrade quality), QAT bakes quantization simulation into training itself, so the model learns to compensate for the precision loss — yielding small models that perform nearly identically to their full-precision baselines. Pick the right variant for your engine:
| Target engine | Download suffix | Primary use case |
|---|---|---|
| llama.cpp / LM Studio | {model}-qat-q4_0-gguf | Zero-setup local on CPU, Apple Silicon, or consumer GPUs |
| vLLM / SGLang | {model}-qat-w4a16-ct (server) · {model}-qat-mobile-ct | High-throughput 4-bit weights with 16-bit activations |
| Speculative decoding | {model}-qat-q4_0-unquantized + -assistant drafter | Primary model plus its MTP draft model for faster generation |
| Other formats (e.g. MLX) | {model}-qat-q4_0-unquantized | Unquantized weights for converting to other formats |
| Mobile (Transformers) | {model}-qat-mobile-transformers | Edge-optimized weights; reference for other mobile formats |
Official QAT collections live on Hugging Face (google/gemma-4-qat-q4-0 and google/gemma-4-qat-mobile) and Kaggle — covering GGUF, unquantized/assistant, compressed-tensors (w4a16-ct), and mobile builds. Mobile checkpoints use a custom wNa8o8 schema with targeted 2-bit decode layers and optimized KV caches for edge RAM limits.
ollama run gemma4:12b. An NVIDIA GPU with recent CUDA drivers speeds things up, but CPU-only works for the smaller sizes.mlx_lm.generate --model mlx-community/gemma-4-e4b-it-4bit. Leave headroom, since the OS and model share the same memory pool.pip install transformers and load google/gemma-4-12b-it, or pull files directly with huggingface-cli download google/gemma-4-12b-it. Supported formats include Safetensors, GGUF, and PyTorch.ollama run gemma4:12b (swap in e2b, e4b, 26b, or 31b). It downloads the weights on first run and drops you into a chat prompt. Ollama also serves a local OpenAI-compatible API on port 11434, so your apps can call it fully offline. See the Ollama library.