# Gemma 2: Improving Open Language Models at a Practical Size

Gemma family trains small open models by distilling from a larger teacher

Gemma Team, Morgane Riviere, Shreya Pathak, Pier Giuseppe Sessa, Cassidy Hardin, Surya Bhupatiraju and 192 more · arXiv · 2024-7-31

- **Problem** Small models have mostly improved by training on more tokens, but that route gives only logarithmic gains as data grows.
- **Method** Gemma 2 trains the 2B and 9B models by distillation from a larger teacher's token probabilities instead of next-token prediction.
- **Results** A 2B model trained on 500B tokens averaged 67.7 over three benchmarks with distillation, against 60.3 from scratch.

## Why small models need a different route

Small models have improved quickly, but mostly by training on longer token streams. That route scales only logarithmically with dataset size, and the authors note that the latest small models consume up to 15T tokens for gains of less than 1-2% on the state of the art. The authors read this as evidence that small models are still under-trained, and they look for ways to make each training step carry more information.

## Distillation as a richer training target

Gemma 2 replaces the one-hot target at each token with the probability distribution a larger teacher model assigns to possible next tokens. The usual use of distillation is to shorten training by giving a small model richer gradients. Here the 2B and 9B models are instead trained on more than 50× the compute-optimal token quantity, so the teacher's signal is used to approximate training on more data than is available.

For each token x with context x\_c, the student is trained to match the teacher's probability P\_T(x \| x\_c). The loss is the negative log-likelihood of the student under the teacher distribution, written as \\\[ \\min\_{P\_S} \\sum\_x -P\_T(x\\mid x\_c)\\log P\_S(x\\mid x\_c) \\\] where P\_S is the parameterized probability of the student. The minus sign sits in front of the teacher-weighted log term, so minimizing the sum raises the student probability of tokens the teacher gives weight to.

The 27B model is trained on 13 trillion tokens, the 9B model on 8 trillion and the 2B model on 2 trillion. The data is primarily English and comes from web documents, code and science articles, and the models are not multimodal or specifically tuned for multilingual capability.

## Architecture changes on the Gemma 1 base

The models keep the decoder-only Transformer of the first Gemma generation, with RoPE, GeGLU and an 8192-token context. The main changes concern depth and attention, and Table 1 lists 26, 42 and 46 layers for the 2B, 9B and 27B models, with d\_model values of 2304, 3584 and 4608.

Attention alternates by layer between local sliding-window attention with a 4096-token window and global attention spanning 8192 tokens.

RMSNorm normalizes the input and the output of each sub-layer, both the attention and the feedforward layer, which the authors use to stabilize training. Grouped-Query Attention uses num\_groups = 2; the authors chose it after ablations that showed faster inference while downstream performance held.

## From pre-trained checkpoints to chat models

Supervised fine-tuning runs behavioral cloning on synthetic and human-written prompt-response pairs, with responses mostly generated by the teacher. It also distills from the teacher on the student's own output distribution.

RLHF follows the algorithm of Gemma 1.1, but uses a new reward model that is an order of magnitude larger than the policy and is oriented toward multi-turn conversation. The policy is trained on the same prompts as the supervised stage.

Averaging is applied after each phase and across models trained with different hyperparameters. Synthetic data is filtered to remove personal information, unsafe or toxic outputs, mistaken self-identification and duplicates. Gemma 2 uses the same control tokens as Gemma 1 but a different chat format, in which a generation ends with the end-of-turn token followed by the end-of-sequence token.

## Distillation against training from scratch

The comparison trains a 2B model on 500B tokens, either from scratch or distilled from a 7B teacher, and reports the average over three benchmarks. The distilled model averaged 67.7 and the scratch model 60.3, with higher being better.

The authors note that 500B tokens is 10× the compute-optimal count for a 2B model. The 7B teacher was chosen so the teacher-to-student ratio matches the 27B-to-9B distillation the authors target.

Distilled students reached 21, 17 and 15, against 23, 19 and 17 from scratch, and the teacher was held at 7B parameters across these sizes.

## Architecture choices from the 9B ablations

Replacing Multi-Head Attention with GQA moved the four-benchmark average on a 9B model from 50.3 to 50.8. The authors saw few performance changes and kept GQA because it has fewer parameters and runs faster at inference.

At the same parameter count, the deeper 9B network averaged 52.0 on four benchmarks, against 50.8 for the wider one. The authors describe the gap as small but consistent across benchmarks, and this supports the deeper design.

The local sliding window was varied at inference only, for the 9B model, with validation perplexity 1.63 at window 4096, 1.63 at 2048 and 1.64 at 1024. The authors present this as a way to trade a small amount of perplexity for slightly faster inference.

## Pre-trained model benchmarks

On the HuggingFace suite, the 27B model scores 75.2 on MMLU against 74.3 for Qwen1.5 32B and 79.2 for LLaMA-3 70B. On GSM8K it scores 74.0, against 61.1 for Qwen1.5 and 76.9 for LLaMA-3 70B. The authors note that the 27B model is 2.5× smaller than LLaMA-3 70B and was trained on 2/3rds less data. The body names the comparison model Qwen1.5 34B, while the table and its caption name Qwen1.5 32B.

Across eight benchmarks where LLaMA-3 results are available, the average is 44.0 for Gemma-1 2B, 50.0 for Gemma 2 2B, 70.2 for Gemma 2 9B and 74.4 for Gemma 2 27B. Gemma 2 9B also exceeds the Gemma-1 7B average of 62.4 and the LLaMA-3 8B average of 61.9 in the same table. The authors report improvements of up to 10% on some benchmarks for the 9B model over earlier versions.

The two 2B models were trained on 2T tokens for Gemma 2 and 3T tokens for Gemma 1, and the authors take the gap as evidence that distillation improves quality even at a similar token count.

## Chatbot Arena rankings

The instruction-tuned models were compared by blind side-by-side judgments from human raters on the Chatbot Arena and scored with Elo. Gemma 2 27B IT scores 1218, above Llama 3 70B at 1206, and Gemma 2 9B IT scores 1187, close to GPT-4-0314 at 1186.

Gemma 2 2B IT scores 1126, above GPT-3.5-Turbo-0613 at 1116.

## Multi-turn and preference human studies

The multi-turn study uses 500 held-out scenarios, each a sequence of requests such as brainstorming or planning, with an average of 8.4 user turns. Raters scored user satisfaction on a 1-to-5 scale, giving 4.20 for Gemma 2 IT 27B, 4.04 for 9B, 3.64 for 2B and 3.32 for Gemma 1.1 IT 7B. On conversation goal achievement, the 27B model scores 4.24 against 3.36 for Gemma 1.1 IT 7B.

The preference studies use held-out single-turn prompts on safety and instruction following, with the comparison to GPT4o as the base for safety win-loss ratios. Gemma 2 IT 27B reaches 37.7% on instruction following, against 24.3% for Gemma 1.1 IT 7B. The authors report that all Gemma 2 sizes produce safer prompts than GPT4o on the held-out safety set.

## Memorization and personal data

Memorization is tested by giving 50-token prompts drawn from training data and checking whether the continuation matches, with exact matching and approximate matching using an edit distance of 10%. Verbatim memorization is below 0.1% and lower than prior models of similar size, and memorization is concentrated in code, wiki and science sources.

Approximate memorization is higher than exact memorization, but it remains low, and the increase over exact memorization is smaller than in earlier models.

Memorized outputs were checked with a sensitive-data tool that sorts personal data into three severity levels. No high-severity personal data was emitted, and 0.00026% of memorized data contained lower-severity personal information.

## Offensive cyber-security and self-proliferation checks

The model is asked to break into a simulated server and retrieve a secret, tested on InterCode-CTF, an internal CTF suite and a Hack the Box challenge. On InterCode-CTF, Gemma 2 27B solved 34 of 76 challenges (45%), against 12 of 76 (16%) for CodeGemma 1 7B and 62 of 76 (82%) for Gemini 1.5 Pro. The InterCode-CTF numbers are not comparable with externally reported results, because challenges that require internet access were omitted.

On the self-proliferation tasks, Gemma 2 27B completed 22 of 45 milestones (49%), with no end-to-end pass and one challenge with success on all milestones. On vulnerability detection, the 27B model scores 63% on PrimeVul and 72% on SecretPatch, and the authors describe its performance as close to chance on several of the datasets.

## Sensitivity of MMLU to formatting

The MMLU standard deviation across 12 formatting and evaluation combinations is 1.5 for Gemma 1 2B, 2.1 for Gemma 2 2B and 6.9 for Mistral 7B. It is 0.7 for Gemma 1 7B, 0.9 for Gemma 2 9B and 1.0 for Gemma 2 27B, so a lower value indicates more stable scores.

## Limitations

The 27B model trails LLaMA-3 70B by only a few percent on the HuggingFace suite, and the authors suggest it lies on the same Pareto curve as the LLaMA-3 models. The authors also say it is not clear how these pre-training differences affect the quality of the instruction-tuned models.

The personal-data detection tools ignore context and produce false positives, so the reported rates are likely overestimates. On InterCode-CTF, the 27B model solved fewer challenges than Gemini 1.5 Pro, and the results cannot be compared with external ones.

Training data is primarily English, and the models are not multimodal or specifically trained for multilingual capability.

## Paper info

- **Authors**: Gemma Team, Morgane Riviere, Shreya Pathak, Pier Giuseppe Sessa, Cassidy Hardin, Surya Bhupatiraju, Léonard Hussenot, Thomas Mesnard, Bobak Shahriari, Alexandre Ramé, Johan Ferret, Peter Liu, Pouya Tafti, Abe Friesen, Michelle Casbon, Sabela Ramos, Ravin Kumar, Charline Le Lan, Sammy Jerome, Anton Tsitsulin, Nino Vieillard, Piotr Stanczyk, Sertan Girgin, Nikola Momchev, Matt Hoffman, Shantanu Thakoor, Jean-Bastien Grill, Behnam Neyshabur, Olivier Bachem, Alanna Walton, Aliaksei Severyn, Alicia Parrish, Aliya Ahmad, Allen Hutchison, Alvin Abdagic, Amanda Carl, Amy Shen, Andy Brock, Andy Coenen, Anthony Laforge, Antonia Paterson, Ben Bastian, Bilal Piot, Bo Wu, Brandon Royal, Charlie Chen, Chintu Kumar, Chris Perry, Chris Welty, Christopher A. Choquette-Choo, Danila Sinopalnikov, David Weinberger, Dimple Vijaykumar, Dominika Rogozińska, Dustin Herbison, Elisa Bandy, Emma Wang, Eric Noland, Erica Moreira, Evan Senter, Evgenii Eltyshev, Francesco Visin, Gabriel Rasskin, Gary Wei, Glenn Cameron, Gus Martins, Hadi Hashemi, Hanna Klimczak-Plucińska, Harleen Batra, Harsh Dhand, Ivan Nardini, Jacinda Mein, Jack Zhou, James Svensson, Jeff Stanway, Jetha Chan, Jin Peng Zhou, Joana Carrasqueira, Joana Iljazi, Jocelyn Becker, Joe Fernandez, Joost van Amersfoort, Josh Gordon, Josh Lipschultz, Josh Newlan, Ju-yeong Ji, Kareem Mohamed, Kartikeya Badola, Kat Black, Katie Millican, Keelin McDonell, Kelvin Nguyen, Kiranbir Sodhia, Kish Greene, Lars Lowe Sjoesund, Lauren Usui, Laurent Sifre, Lena Heuermann, Leticia Lago, Lilly McNealus, Livio Baldini Soares, Logan Kilpatrick, Lucas Dixon, Luciano Martins, Machel Reid, Manvinder Singh, Mark Iverson, Martin Görner, Mat Velloso, Mateo Wirth, Matt Davidow, Matt Miller, Matthew Rahtz, Matthew Watson, Meg Risdal, Mehran Kazemi, Michael Moynihan, Ming Zhang, Minsuk Kahng, Minwoo Park, Mofi Rahman, Mohit Khatwani, Natalie Dao, Nenshad Bardoliwalla, Nesh Devanathan, Neta Dumai, Nilay Chauhan, Oscar Wahltinez, Pankil Botarda, Parker Barnes, Paul Barham, Paul Michel, Pengchong Jin, Petko Georgiev, Phil Culliton, Pradeep Kuppala, Ramona Comanescu, Ramona Merhej, Reena Jana, Reza Ardeshir Rokni, Rishabh Agarwal, Ryan Mullins, Samaneh Saadat, Sara Mc Carthy, Sarah Cogan, Sarah Perrin, Sébastien M. R. Arnold, Sebastian Krause, Shengyang Dai, Shruti Garg, Shruti Sheth, Sue Ronstrom, Susan Chan, Timothy Jordan, Ting Yu, Tom Eccles, Tom Hennigan, Tomas Kocisky, Tulsee Doshi, Vihan Jain, Vikas Yadav, Vilobh Meshram, Vishal Dharmadhikari, Warren Barkley, Wei Wei, Wenming Ye, Woohyun Han, Woosuk Kwon, Xiang Xu, Zhe Shen, Zhitao Gong, Zichuan Wei, Victor Cotruta, Phoebe Kirk, Anand Rao, Minh Giang, Ludovic Peran, Tris Warkentin, Eli Collins, Joelle Barral, Zoubin Ghahramani, Raia Hadsell, D. Sculley, Jeanine Banks, Anca Dragan, Slav Petrov, Oriol Vinyals, Jeff Dean, Demis Hassabis, Koray Kavukcuoglu, Clement Farabet, Elena Buchatskaya, Sebastian Borgeaud, Noah Fiedel, Armand Joulin, Kathleen Kenealy, Robert Dadashi, Alek Andreev
- **Venue**: arXiv · Preprint
- **First published**: 2024-7-31
- **Added**: 2026-11-12
- **Updated**: 2024-10-2
- **Version**: v3
- **arXiv**: 2408.00118
- **Category**: cs.CL · cs.AI
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2408.00118v3) · [PDF ↗](https://arxiv.org/pdf/2408.00118v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Gemma Team, Morgane Riviere, Shreya Pathak, Pier Giuseppe Sessa, Cassidy Hardin, Surya Bhupatiraju, Léonard Hussenot, Thomas Mesnard, Bobak Shahriari, Alexandre Ramé, Johan Ferret, Peter Liu, Pouya Tafti, Abe Friesen, Michelle Casbon, Sabela Ramos, Ravin Kumar, Charline Le Lan, Sammy Jerome, Anton Tsitsulin et al. (2024). Gemma 2: Improving Open Language Models at a Practical Size. arXiv:2408.00118v3. https://arxiv.org/abs/2408.00118v3

**BibTeX**

```
@misc{team2024gemma,
  title = {{Gemma 2: Improving Open Language Models at a Practical Size}},
  author = {Gemma Team and Morgane Riviere and Shreya Pathak and Pier Giuseppe Sessa and Cassidy Hardin and Surya Bhupatiraju and Léonard Hussenot and Thomas Mesnard and Bobak Shahriari and Alexandre Ramé and Johan Ferret and Peter Liu and Pouya Tafti and Abe Friesen and Michelle Casbon and Sabela Ramos and Ravin Kumar and Charline Le Lan and Sammy Jerome and Anton Tsitsulin and Nino Vieillard and Piotr Stanczyk and Sertan Girgin and Nikola Momchev and Matt Hoffman and Shantanu Thakoor and Jean-Bastien Grill and Behnam Neyshabur and Olivier Bachem and Alanna Walton and Aliaksei Severyn and Alicia Parrish and Aliya Ahmad and Allen Hutchison and Alvin Abdagic and Amanda Carl and Amy Shen and Andy Brock and Andy Coenen and Anthony Laforge and Antonia Paterson and Ben Bastian and Bilal Piot and Bo Wu and Brandon Royal and Charlie Chen and Chintu Kumar and Chris Perry and Chris Welty and Christopher A. Choquette-Choo and Danila Sinopalnikov and David Weinberger and Dimple Vijaykumar and Dominika Rogozińska and Dustin Herbison and Elisa Bandy and Emma Wang and Eric Noland and Erica Moreira and Evan Senter and Evgenii Eltyshev and Francesco Visin and Gabriel Rasskin and Gary Wei and Glenn Cameron and Gus Martins and Hadi Hashemi and Hanna Klimczak-Plucińska and Harleen Batra and Harsh Dhand and Ivan Nardini and Jacinda Mein and Jack Zhou and James Svensson and Jeff Stanway and Jetha Chan and Jin Peng Zhou and Joana Carrasqueira and Joana Iljazi and Jocelyn Becker and Joe Fernandez and Joost van Amersfoort and Josh Gordon and Josh Lipschultz and Josh Newlan and Ju-yeong Ji and Kareem Mohamed and Kartikeya Badola and Kat Black and Katie Millican and Keelin McDonell and Kelvin Nguyen and Kiranbir Sodhia and Kish Greene and Lars Lowe Sjoesund and Lauren Usui and Laurent Sifre and Lena Heuermann and Leticia Lago and Lilly McNealus and Livio Baldini Soares and Logan Kilpatrick and Lucas Dixon and Luciano Martins and Machel Reid and Manvinder Singh and Mark Iverson and Martin Görner and Mat Velloso and Mateo Wirth and Matt Davidow and Matt Miller and Matthew Rahtz and Matthew Watson and Meg Risdal and Mehran Kazemi and Michael Moynihan and Ming Zhang and Minsuk Kahng and Minwoo Park and Mofi Rahman and Mohit Khatwani and Natalie Dao and Nenshad Bardoliwalla and Nesh Devanathan and Neta Dumai and Nilay Chauhan and Oscar Wahltinez and Pankil Botarda and Parker Barnes and Paul Barham and Paul Michel and Pengchong Jin and Petko Georgiev and Phil Culliton and Pradeep Kuppala and Ramona Comanescu and Ramona Merhej and Reena Jana and Reza Ardeshir Rokni and Rishabh Agarwal and Ryan Mullins and Samaneh Saadat and Sara Mc Carthy and Sarah Cogan and Sarah Perrin and Sébastien M. R. Arnold and Sebastian Krause and Shengyang Dai and Shruti Garg and Shruti Sheth and Sue Ronstrom and Susan Chan and Timothy Jordan and Ting Yu and Tom Eccles and Tom Hennigan and Tomas Kocisky and Tulsee Doshi and Vihan Jain and Vikas Yadav and Vilobh Meshram and Vishal Dharmadhikari and Warren Barkley and Wei Wei and Wenming Ye and Woohyun Han and Woosuk Kwon and Xiang Xu and Zhe Shen and Zhitao Gong and Zichuan Wei and Victor Cotruta and Phoebe Kirk and Anand Rao and Minh Giang and Ludovic Peran and Tris Warkentin and Eli Collins and Joelle Barral and Zoubin Ghahramani and Raia Hadsell and D. Sculley and Jeanine Banks and Anca Dragan and Slav Petrov and Oriol Vinyals and Jeff Dean and Demis Hassabis and Koray Kavukcuoglu and Clement Farabet and Elena Buchatskaya and Sebastian Borgeaud and Noah Fiedel and Armand Joulin and Kathleen Kenealy and Robert Dadashi and Alek Andreev},
  year = {2024},
  eprint = {2408.00118},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.00118v3}
}
```

## Other paper commentary

- [A Survey on Large Language Model based Autonomous Agents](https://refivu.com/en/papers/9d1600e9-9099-49ab-b9f8-7e2c2083c79f-a-survey-on-large-language-model-based-autonomous.md)
- [Lost in the Middle: How Language Models Use Long Contexts](https://refivu.com/en/papers/990be3e6-ce8b-473a-94d1-735a4cb6a76f-lost-in-the-middle-how-language-models-use.md)
- [MiniGPT-4: Enhancing Vision-Language Understanding with Advanced Large Language Models](https://refivu.com/en/papers/f07e6e3f-3ab5-42dc-98c8-a32fe7d8820d-minigpt-4-enhancing-vision-language-understanding-with.md)
- [Learning to Prompt for Vision-Language Models](https://refivu.com/en/papers/c492cb20-7c19-4275-b139-f97eecec7359-learning-to-prompt-for-vision-language-models.md)
- [Universal and Transferable Adversarial Attacks on Aligned Language Models](https://refivu.com/en/papers/6bc6f22f-cd10-41c0-ba7c-3e3d376cf3b9-universal-and-transferable-adversarial-attacks-on-aligned.md)
- [Code Llama: Open Foundation Models for Code](https://refivu.com/en/papers/d1b3e035-fd64-4a9c-a7a6-cfb45de54052-code-llama-open-foundation-models-for-code.md)
- [Recurrent Neural Network Regularization](https://refivu.com/en/papers/317651d8-c32f-47cc-ad63-48860741508c-recurrent-neural-network-regularization.md)
- [Distillation as a Defense to Adversarial Perturbations against Deep Neural Networks](https://refivu.com/en/papers/c5136527-4bfb-4b86-9a2a-78184dd93989-distillation-as-a-defense-to-adversarial-perturbations.md)
- [SuperGlue: Learning Feature Matching with Graph Neural Networks](https://refivu.com/en/papers/9343403c-486b-4202-af8a-3329d26b1dad-superglue-learning-feature-matching-with-graph-neural.md)
- [Progressive Neural Networks](https://refivu.com/en/papers/312c9749-ed9b-42c3-9bf3-bb139310d4dd-progressive-neural-networks.md)
- [Cyclical Learning Rates for Training Neural Networks](https://refivu.com/en/papers/922235f3-8c7b-4983-9a6d-b6a3d0b4a72e-cyclical-learning-rates-for-training-neural-networks.md)
- [NTU RGB+D: A Large Scale Dataset for 3D Human Activity Analysis](https://refivu.com/en/papers/5edff39c-c403-4be6-ac6f-5fbcfa1ca3f7-ntu-rgb-d-a-large-scale-dataset-for.md)

## Terms in this paper

- [perplexity](https://refivu.com/en/terms/2b204e513801-perplexity)
- [MMLU](https://refivu.com/en/terms/3036c0ba5adb-mmlu)
- [knowledge distillation](https://refivu.com/en/terms/b8544f4ba83e-knowledge-distillation)
- [RMSNorm](https://refivu.com/en/terms/9b1cafd281f0-rmsnorm)
- [RoPE](https://refivu.com/en/terms/e4cc5cfc6ebf-rope)
- [RLHF](https://refivu.com/en/terms/1e6d2905ced3-rlhf)
- [grouped-query attention](https://refivu.com/en/terms/d8b75471c6ff-grouped-query-attention)
- [supervised fine-tuning (SFT)](https://refivu.com/en/terms/b08583cba2aa-supervised-fine-tuning-sft)
- [GeGLU](https://refivu.com/en/terms/9d6ee5d4da52-geglu)
- [standard deviation](https://refivu.com/en/terms/514f0034c693-standard-deviation)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/aaf9911d-9b96-4e9e-be15-d3cdb554211a-gemma-2-improving-open-language-models-at-a)
