NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CodeGemma: Open Code Models Based on Gemma

Heri Zhao, Jeffrey Hui, Joshua Howland, Nam Nguyen, Siqi Zuo, Andrea Hu, Christopher A. Choquette-Choo, Jingyue Shen, Joe Kelley, Kshitij Bansal, Luke Vilnis, Mateo Wirth, Paul Michel, Peter Choy, Pratik Joshi, Ravin Kumar, Sarmad Hashmi, Shubham Agrawal, Zhitao Gong, Jane Fine, Tris Warkentin, Ale Jakse Hartman, Bin Ni, Kathy Korevec, Kelly Schaefer, Scott HuffmanarXiv 2024

Abstract

This paper introduces CodeGemma, a collection of specialized open code models built on top of Gemma, capable of a variety of code and natural language generation tasks. We release three model variants. CodeGemma 7B pretrained (PT) and instruction-tuned (IT) variants have remarkably resilient natural language understanding, excel in mathematical reasoning, and match code capabilities of other open models. CodeGemma 2B is a state-of-the-art code completion model designed for fast code infilling and open-ended generation in latency-sensitive settings.

1. Introduction

While large language models (LLMs) have become proficient at writing code, there is a persistent tension between model size, latency, and specialized capability. Developers need models that can not only generate code from a prompt but also "infill" missing logic within an existing file—a task known as Fill-in-the-Middle (FIM). Furthermore, many code-specific models sacrifice natural language understanding or mathematical reasoning to gain coding proficiency. CodeGemma aims to bridge this gap, providing a suite of models that excel at coding and logic without losing the linguistic fluidity of the base Gemma models.

2. Methodology

CodeGemma leverages the same transformer architecture as the original Gemma models but applies several specialized training techniques to optimize for developer workflows.

The CodeGemma training pipeline, illustrating the derivation of 2B and 7B variants from Gemma pretrained models through specialized code infilling and instruction tuning.

2.1 Fill-in-the-Middle (FIM) Training

The models are trained to predict missing code blocks given a prefix and a suffix. The researchers utilized a high FIM rate (80-90%), ensuring the models are exceptionally proficient at real-time code completion within IDEs. This is particularly critical for the 2B variant, which is optimized for low-latency environments.

2.2 Multi-file Packing

To help the model understand cross-file dependencies, researchers used dependency graphs and unit-test proximity to "pack" related source files into the same training sequences. This mimics the repository-level context developers work in, allowing the model to better understand project-wide logic.

2.3 Instruction Tuning and Reasoning

The 7B instruction-tuned (IT) variant underwent supervised fine-tuning (SFT) and reinforcement learning from human feedback (RLHF). Crucially, this included a heavy dose of mathematical datasets to bolster the model's logical reasoning capabilities, treating math as a proxy for complex algorithmic logic.

3. Datasets and Evaluation

The models were pretrained on a massive corpus of 500 billion to 1 trillion tokens, primarily consisting of English web documents, mathematics, and publicly available code. Evaluation was conducted across several dimensions:

  • Coding Benchmarks: HumanEval (Python), MBPP (Mostly Basic Python Problems), and BabelCode for multi-lingual support.
  • Math Benchmarks: GSM8k and the MATH dataset.
  • Natural Language Benchmarks: Standard sets like BoolQ, PIQA, and MMLU to ensure the model maintained general-purpose utility.

4. Key Results

CodeGemma demonstrates significant improvements over both its base models and existing code-specialized models. The 2B model provides a distinct latency advantage, being nearly twice as fast as many competitors during inference, making it ideal for local IDE integrations.

Comparison of CodeGemma variants against base Gemma models on HumanEval and MBPP benchmarks, showing significant gains in coding proficiency.

4.1 Python and Multi-lingual Proficiency

As shown in the evaluation results, the 7B-IT v1.1 model achieved a 60.4% score on HumanEval, a substantial lead over the base Gemma 7B (32.3%). While Python is the primary benchmark, the models showed strong gains across C++, Java, and Rust, particularly in the v1.1 updates which increased training data for the 2B model to 1 trillion tokens.

4.2 Mathematical Reasoning

On the GSM8K math benchmark, CodeGemma 7B-IT v1.1 reached 47.3%, vastly outperforming Code Llama (13.0%) and StarCoder2 (40.4%). This confirms the hypothesis that exposing the model to high-level mathematics significantly boosts its ability to solve complex coding problems.

5. Conclusion

CodeGemma provides a powerful, open-weight solution for developers, balancing specialized coding tasks with general reasoning. While the 2B model serves as a high-speed completion specialist, the 7B variants offer a generalist approach for generation and complex reasoning. Future work will likely focus on deeper repository-level understanding to provide even more context-aware assistance in massive codebases.

Summary updated

BibTeX
@misc{zhao2024codegemma,
  author = {Heri Zhao and Jeffrey Hui and Joshua Howland and Nam Nguyen and Siqi Zuo and Andrea Hu and Christopher A. Choquette-Choo and Jingyue Shen and Joe Kelley and Kshitij Bansal and Luke Vilnis and Mateo Wirth and Paul Michel and Peter Choy and Pratik Joshi and Ravin Kumar and Sarmad Hashmi and Shubham Agrawal and Zhitao Gong and Jane Fine and Tris Warkentin and Ale Jakse Hartman and Bin Ni and Kathy Korevec and Kelly Schaefer and Scott Huffman},
  title = {{CodeGemma: Open Code Models Based on Gemma}},
  year = {2024},
  eprint = {2406.11409},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.11409},
}
Figure