Gemma 3 Guide 2025: Google's Best Open-Source LLM
Gemma 3 is Google DeepMind's open-weight model family that punches far above its size class. The 27B flagship beats many 70B models on standard benchmarks, the 4B+ variants are multimodal, every size ships with a 128K context window, and the whole family is Apache 2.0 — making Gemma 3 one of the most capable freely-usable LLM families available in 2025.
What Is Gemma 3?
Gemma 3 is Google DeepMind's family of open-weight language models released in March 2025. The family spans four sizes — 1B, 4B, 12B, and 27B parameters — and is built directly on the same research and training infrastructure as the proprietary Gemini model series. Unlike many open-weight releases, Gemma 3 includes a 128K context window across all sizes and ships with full multimodal (image + text) support starting at the 4B size.
Key properties at a glance:
- Apache 2.0 license — commercial use, fine-tuning, and redistribution are all permitted.
- State-of-the-art efficiency — Gemma 3 27B outperforms several 70B-class models on MMLU and reasoning benchmarks.
- Vision input — 4B, 12B, and 27B process images natively via interleaved text+image chat templates.
- 128K context — long-document QA, entire codebases, and extended conversations fit in a single pass.
- Instruction-tuned variants — every size ships as both a base (
-pt) and instruction-tuned (-it) checkpoint.
Model Variants
The Gemma 3 ecosystem covers a wide range of deployment targets:
| Model | Vision | Context | Best for |
|---|---|---|---|
| Gemma 3 1B | No | 32K | Edge / mobile / ultra-low VRAM |
| Gemma 3 4B | Yes | 128K | Consumer GPU, vision tasks, local dev |
| Gemma 3 12B | Yes | 128K | Balanced quality/cost, A10G / 3090 |
| Gemma 3 27B | Yes | 128K | Flagship — beats many 70B models |
| Gemma 3n | Yes | 32K | On-device / NPU / MediaPipe |
| ShieldGemma | No | 8K | Safety classifier / content moderation |
Run Locally with Ollama
Ollama is the fastest way to run Gemma 3 locally — one command downloads, quantizes, and serves the model with an OpenAI-compatible API:
Install Ollama + pull Gemma 3
# macOS / Linux curl -fsSL https://ollama.com/install.sh | sh # Pull and run Gemma 3 4B (vision-capable, ~3 GB Q4) ollama run gemma3:4b # Pull and run Gemma 3 27B (flagship, ~17 GB Q4) ollama run gemma3:27b # Run with vision input from the CLI ollama run gemma3:4b "Describe this image" --image /path/to/image.jpg
Query via OpenAI SDK (Ollama serves on port 11434)
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
response = client.chat.completions.create(
model="gemma3:4b",
messages=[{"role": "user", "content": "Explain attention mechanisms."}],
)
print(response.choices[0].message.content) Python with Transformers (HuggingFace)
Load Gemma 3 directly from the Hugging Face Hub. You must accept the model license at huggingface.co/google/gemma-3-27b-it and authenticate with huggingface-cli login before downloading.
Text generation — gemma-3-27b-it
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "google/gemma-3-27b-it"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{"role": "user", "content": "What is the capital of France?"}
]
inputs = tokenizer.apply_chat_template(
messages,
return_tensors="pt",
return_dict=True,
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)) Vision input — gemma-3-4b-it with PIL image
from transformers import AutoProcessor, AutoModelForImageTextToText
from PIL import Image
import torch, requests
model_id = "google/gemma-3-4b-it"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
image = Image.open(requests.get("https://example.com/chart.png", stream=True).raw)
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "Describe what you see in this chart."},
],
}
]
inputs = processor.apply_chat_template(
messages, add_generation_prompt=True, return_dict=True, return_tensors="pt"
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)) Via Google AI Studio / Gemini API
Google serves Gemma 3 27B through the Gemini API endpoint, which is accessible via Google AI Studio (free tier available) and fully OpenAI-compatible. This is the lowest-friction path if you want a hosted Gemma endpoint without managing infrastructure:
Install the Google Gen AI SDK
pip install google-genai
Call gemma-3-27b-it via Gemini API (OpenAI-compatible)
from openai import OpenAI
# Get a free API key at aistudio.google.com
client = OpenAI(
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
api_key="YOUR_GEMINI_API_KEY",
)
response = client.chat.completions.create(
model="gemma-3-27b-it",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the transformer architecture."},
],
max_tokens=1024,
)
print(response.choices[0].message.content) AI Studio free tier allows up to 1500 requests/day for Gemma 3 27B — enough for development and prototyping. For production, switch to Vertex AI on Google Cloud for SLA-backed serving.
Via Groq and Other Providers
Several third-party inference providers host Gemma models for ultra-low-latency serving. Groq currently serves Gemma 2 9B (the predecessor to Gemma 3) at speeds exceeding 800 tokens/second — the fastest available hosted option for the Gemma family:
Groq — Gemma 2 9B at 800+ tok/s
pip install groq
groq_gemma.py
from groq import Groq
client = Groq(api_key="YOUR_GROQ_API_KEY")
response = client.chat.completions.create(
model="gemma2-9b-it", # Groq hosts Gemma 2 9B
messages=[
{"role": "user", "content": "Write a quicksort in Python."}
],
temperature=0.7,
max_tokens=1024,
)
print(response.choices[0].message.content)
Other providers hosting Gemma models: Together AI (google/gemma-3-27b-it), Fireworks AI, Replicate, and HuggingFace Inference Endpoints.
Gemma 3 vs Phi-4 vs Llama 3.1 vs Qwen2.5
How does Gemma 3 stack up against the top open-weight competitors?
| Model | MMLU | HumanEval | MATH | MMMU (vision) |
|---|---|---|---|---|
| Gemma 3 27B | 85.0% | 65.0% | 71.0% | 59.0% |
| Gemma 3 12B | 80.0% | 58.0% | 63.0% | 55.0% |
| Phi-4 14B | 84.8% | 82.6% | 80.4% | n/a |
| Llama 3.1 70B | 86.0% | 80.5% | 68.0% | n/a |
| Qwen2.5 72B | 86.2% | 86.6% | 82.4% | n/a |
Gemma 3 27B is competitive with models 2-3x its size on MMLU and reasoning. Phi-4 and Qwen2.5 lead on coding (HumanEval/MATH), but Gemma 3 is the only one in this table offering native multimodal input (MMMU) at the 27B size class. For vision tasks, Gemma 3 4B achieves ~55% MMMU — solid for a 4B model.
On-Device: Gemma 3n
Gemma 3n is a specialized sub-family engineered for on-device deployment on smartphones, tablets, and edge NPU hardware. It uses a per-layer embedding (PLE) technique that shares parameters across layers to reduce the active memory footprint to as low as 2B effective parameters while retaining quality closer to a 4B model.
Key integrations:
- MediaPipe LLM Inference API — Google's framework for on-device ML tasks on Android and iOS. Gemma 3n ships as a first-class MediaPipe model.
- Android AI Edge — integrates with Qualcomm, MediaTek, and Samsung NPU runtimes for hardware-accelerated inference.
- iOS / Core ML — Gemma 3n can be exported to Core ML format for Apple Neural Engine inference on iPhone and iPad.
Run Gemma 3n via MediaPipe Python (desktop testing)
pip install mediapipe
from mediapipe.tasks.python import text
# Download model from: ai.google.dev/edge/mediapipe/solutions/genai/llm_inference
model_path = "gemma3n_e4b_it_q8_ekv1024.task"
options = text.language_model.LanguageModelOptions(
base_options=text.BaseOptions(model_asset_path=model_path),
max_tokens=512,
)
with text.LanguageModel.create_from_options(options) as llm:
result = llm.generate_response("Translate 'hello' to French.")
print(result.text) Fine-Tuning Gemma 3 with LoRA
Gemma 3's Apache 2.0 license explicitly permits fine-tuning and redistribution of derived models. The recommended approach is LoRA (Low-Rank Adaptation) via the trl + peft libraries, which adds trainable rank-decomposition matrices to attention layers without touching base weights:
Install fine-tuning dependencies
pip install trl peft bitsandbytes accelerate datasets
finetune_gemma3.py — LoRA SFT on a custom dataset
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model
from trl import SFTTrainer, SFTConfig
from datasets import load_dataset
import torch
model_id = "google/gemma-3-4b-it"
# 4-bit QLoRA for consumer GPUs (16 GB VRAM sufficient for 4B)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=bnb_config,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
lora_config = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM",
)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
# trainable params: ~8.4M / 4B total — 0.2%
dataset = load_dataset("your-org/your-dataset", split="train")
training_args = SFTConfig(
output_dir="./gemma3-4b-lora",
num_train_epochs=3,
per_device_train_batch_size=2,
gradient_accumulation_steps=4,
learning_rate=2e-4,
fp16=False,
bf16=True,
logging_steps=10,
save_steps=100,
)
trainer = SFTTrainer(
model=model,
args=training_args,
train_dataset=dataset,
tokenizer=tokenizer,
)
trainer.train() For managed fine-tuning without setting up infrastructure, Google's Vertex AI offers a supervised fine-tuning pipeline for Gemma 3 with a few-click UI or Python SDK. The resulting adapter is deployable directly to Vertex AI endpoints.
Running Gemma via Google AI Studio or Vertex AI?
Prismix monitors Google AI's status in real time. Know instantly when the Gemini API, AI Studio, or Vertex AI endpoints are degraded — before your users notice.
Check Google AI Status →