Skip to content

● Conductor's cloud service has shut down. Switch to CoderBaba →

Google

CodeGemma

Google's lightweight Gemma-based code models (2B and 7B) for fast code completion and generation on laptops and edge devices.

Overview

CodeGemma is Google's family of small code models, released in April 2024 and built on the open Gemma models. It focuses on doing a few things very well with minimal hardware: fast code completion, code generation from natural language and chat about code, all in models small enough for a laptop.

There are three variants: a 2B model for fast completion, a 7B pretrained model for completion and generation, and a 7B instruction-tuned model for chat. The 7B models received roughly 500 billion tokens of additional training, mostly code, on top of Gemma.

Model variants

VariantPurposeNotes
CodeGemma 2BFast fill-in-the-middle completionTuned for low-latency autocomplete
CodeGemma 7BCompletion and generationPretrained base model with FIM
CodeGemma 7B-ITChat and instruction followingExplanations, generation, Q&A

Google followed up with 1.1 versions in 2024 with quality improvements, and Ollama's codegemma tags point to current versions.

Training and design

CodeGemma inherits Gemma's architecture and tokenizer, then continues pretraining with a fill-in-the-middle objective on a code-heavy mix that includes deduplicated public code plus mathematics data. Google described a multi-file packing approach that groups related files from the same repository during training, which helps the model use context from neighboring files, an important skill for completion in real projects.

The 8K context window is modest, but for autocomplete it is rarely the bottleneck: most completion requests include only the current file and a few related snippets.

Benchmarks and what they mean

We don't list a headline score because Google reported results across several completion and generation benchmarks, mostly in comparison with other small models of the time. At release, the 7B models were competitive with other 7B code models, and the 2B model stood out for its speed-to-quality ratio in completion. Newer small models, such as Qwen2.5-Coder 1.5B, are strong competitors today, so try both on your own code.

Hardware requirements

Variant4-bit8-bitRuns on
2Babout 1.6 GBabout 3 GBAny laptop, even CPU-only
7Babout 5 GBabout 9 GB8 GB GPU or 16 GB Mac

Because it is so small, CodeGemma 2B can share a machine with a larger chat model without competing much for memory.

How to run it

Ollama

# fast autocomplete
ollama pull codegemma:2b
 
# chat and generation
ollama run codegemma:7b

Hugging Face Transformers

from transformers import AutoModelForCausalLM, AutoTokenizer
 
model_id = "google/codegemma-7b-it"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

The official Hugging Face repositories require accepting Google's terms before downloading.

Using it in your editor

CodeGemma 2B is a natural tab-autocomplete model. In Continue or a similar extension, set codegemma:2b as the autocomplete model, served by Ollama, and keep completions short for the lowest latency. For chat, either use CodeGemma 7B-IT or pair the 2B autocomplete model with a stronger chat model such as Qwen2.5-Coder 14B.

It's also well suited to on-device and edge scenarios: offline coding tools, education apps or developer tools that must run on modest hardware without a network connection.

Strengths

  • Very fast on CPUs and small GPUs
  • Fill-in-the-middle support
  • Low memory use, so it pairs well with a larger chat model
  • Backed by Google's Gemma ecosystem and tooling
  • Commercial use permitted

Limitations

  • The small size limits quality on complex, multi-file tasks
  • The 8K context window is short by current standards
  • It isn't designed for agentic workflows
  • The custom license includes a prohibited use policy

License in plain English

The Gemma Terms of Use allow commercial use, modification and redistribution. You must follow Google's prohibited use policy and pass those terms on if you distribute the model or derivatives. For typical developer tools and products, commercial use is allowed.

Practical tips

Pick the right variant for the job. The 2B model and the 7B pretrained model are completion models: they continue code and fill gaps, but they aren't tuned to follow chat instructions. For questions, explanations and "write me a function" prompts, use the instruction-tuned 7B variant. A common mistake is wiring the 7B instruct model into autocomplete, or the 2B model into chat, and concluding the model is weak.

Let your tool handle fill-in-the-middle. CodeGemma's completion models use special tokens to mark the code before the cursor, the code after it and the gap to fill. Editor extensions with built-in CodeGemma templates assemble these automatically. If you call the model directly through an API, follow the exact token format in the model card. Small formatting mistakes noticeably hurt completion quality.

Keep prompts short and local. With an 8K context, CodeGemma does best on the current file plus a little surrounding context. Configure your autocomplete extension to send a modest window around the cursor rather than entire files. You'll get faster, more relevant suggestions.

Use low temperature for code. For completion, a temperature of 0 to 0.2 gives stable, predictable output. Raise it a little for brainstorming in chat, but keep it low when you want code that compiles.

Measure latency, not just quality. For autocomplete, a suggestion that appears in 200 milliseconds is worth more than a slightly better one that takes two seconds. Try the 2B model first and move up to 7B only if suggestions are too often wrong for your codebase.

Alternatives

Frequently asked questions

Which CodeGemma model is best for autocomplete?

The 2B model is optimized for fast fill-in-the-middle completion. The 7B instruction-tuned model is better for chat and code generation.

Can CodeGemma run without a GPU?

Yes. The 2B model runs comfortably on a modern laptop CPU, and the 7B model runs on CPU too, more slowly. Apple Silicon Macs run both quickly.

Can I use CodeGemma commercially?

Yes. The Gemma Terms of Use allow commercial use, subject to Google's prohibited use policy.

Are there newer versions of CodeGemma?

Google released CodeGemma 1.1 updates in 2024 with quality improvements. Google's newer general Gemma models are also strong at code, so check them if you want a more recent small model.

Similar models

all models →