Serving Gemma 4 12B with vLLM using NVFP4

·5 min readlocal-aiai

Quick Start (TL;DR)

For a standard production deployment on a Blackwell-class GPU with the language model only:

Terminal window
vllm serve unsloth/gemma-4-12b-it-awq \
--max-model-len 8192 \
--dtype auto --max-num-batched_tokens 8192

Ollama (Simplest)

Terminal window
ollama run gemma:12b

Ollama works out of the box but doesn’t support the new Gemma 4 tool-calling template as reliably as llama.cpp yet. Use for quick testing, not production coding workflows.

Prompt Structure That Works

Community-tested system prompt for coding:

You are a coding assistant. Rules:
1. Output ONLY code unless asked to explain.
2. If the task is ambiguous, ask ONE clarifying question — do not guess.
3. Include brief inline comments for non-obvious logic.
4. Use the existing codebase style. If unsure, use PEP 8 / standard conventions.
5. Never invent imports or APIs. If you need an import, state it explicitly.

Key observations:

  • “Ask one question” beats “don’t hallucinate” — the model actually uses it.
  • Inline comments catch reasoning errors early.
  • Style matching requires showing a code snippet in the prompt.

What Gemma 4 12B Does Well

  • Small refactors: rename, extract function, split class — reliable
  • Bug fixing with context: feed the error + the file, it usually nails it
  • Boilerplate generation: CRUD endpoints, React components, test scaffolds
  • Code explanation: “What does this function do?” — consistently accurate
  • Single-file Python/JS/TS: Complete scripts under 200 lines work well

Where It Struggles

  • Multi-file refactors: loses track of cross-file imports
  • Complex algorithm design: tends to pick the simplest (sometimes wrong) approach
  • Tool calling with >3 tools: gets confused by large tool schemas
  • Framework-specific gotchas: Next.js hydration, Rust lifetime errors — needs context

Hardware Checklist

GPUVRAMVerdict
RTX 409024 GBComfortable BF16 or Q4 + headroom
RTX 4070 / 408012-16 GBQ4 QAT, 8K context
RTX 3060 / 40608-12 GBQ4 QAT, 4K context
Mac M2/M316 GBQ4 QAT via MLX, ~25 t/s
Mac M2/M324 GBBF16 via MLX, ~15 t/s

The Reliable Workflow (Summary)

  1. Load QAT or AWQ Q4 — never naive GGUF
  2. Use --jinja in llama.cpp for tool calling
  3. Chunk every task into <100-line outputs
  4. Show relevant code in the prompt (5-15 lines of context)
  5. Verify before proceeding — one broken step cascades

Gemma 4 12B is not the strongest coding model available — Qwen3.6 27B and Gemma 4 31B are objectively better. But it’s the smallest model that handles coding reliably at scale, and at 7 GB quantized, it runs on hardware most developers already own.