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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Quantization made by Richard Erkhov.
|
2 |
+
|
3 |
+
[Github](https://github.com/RichardErkhov)
|
4 |
+
|
5 |
+
[Discord](https://discord.gg/pvy7H8DZMG)
|
6 |
+
|
7 |
+
[Request more models](https://github.com/RichardErkhov/quant_request)
|
8 |
+
|
9 |
+
|
10 |
+
gemma-2-2b - GGUF
|
11 |
+
- Model creator: https://huggingface.co/google/
|
12 |
+
- Original model: https://huggingface.co/google/gemma-2-2b/
|
13 |
+
|
14 |
+
|
15 |
+
| Name | Quant method | Size |
|
16 |
+
| ---- | ---- | ---- |
|
17 |
+
| [gemma-2-2b.Q2_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q2_K.gguf) | Q2_K | 1.15GB |
|
18 |
+
| [gemma-2-2b.IQ3_XS.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.IQ3_XS.gguf) | IQ3_XS | 1.22GB |
|
19 |
+
| [gemma-2-2b.IQ3_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.IQ3_S.gguf) | IQ3_S | 1.27GB |
|
20 |
+
| [gemma-2-2b.Q3_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q3_K_S.gguf) | Q3_K_S | 1.27GB |
|
21 |
+
| [gemma-2-2b.IQ3_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.IQ3_M.gguf) | IQ3_M | 1.3GB |
|
22 |
+
| [gemma-2-2b.Q3_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q3_K.gguf) | Q3_K | 1.36GB |
|
23 |
+
| [gemma-2-2b.Q3_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q3_K_M.gguf) | Q3_K_M | 1.36GB |
|
24 |
+
| [gemma-2-2b.Q3_K_L.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q3_K_L.gguf) | Q3_K_L | 1.44GB |
|
25 |
+
| [gemma-2-2b.IQ4_XS.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.IQ4_XS.gguf) | IQ4_XS | 1.47GB |
|
26 |
+
| [gemma-2-2b.Q4_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q4_0.gguf) | Q4_0 | 1.52GB |
|
27 |
+
| [gemma-2-2b.IQ4_NL.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.IQ4_NL.gguf) | IQ4_NL | 1.53GB |
|
28 |
+
| [gemma-2-2b.Q4_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q4_K_S.gguf) | Q4_K_S | 1.53GB |
|
29 |
+
| [gemma-2-2b.Q4_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q4_K.gguf) | Q4_K | 1.59GB |
|
30 |
+
| [gemma-2-2b.Q4_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q4_K_M.gguf) | Q4_K_M | 1.59GB |
|
31 |
+
| [gemma-2-2b.Q4_1.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q4_1.gguf) | Q4_1 | 1.64GB |
|
32 |
+
| [gemma-2-2b.Q5_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q5_0.gguf) | Q5_0 | 1.75GB |
|
33 |
+
| [gemma-2-2b.Q5_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q5_K_S.gguf) | Q5_K_S | 1.75GB |
|
34 |
+
| [gemma-2-2b.Q5_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q5_K.gguf) | Q5_K | 1.79GB |
|
35 |
+
| [gemma-2-2b.Q5_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q5_K_M.gguf) | Q5_K_M | 1.79GB |
|
36 |
+
| [gemma-2-2b.Q5_1.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q5_1.gguf) | Q5_1 | 1.87GB |
|
37 |
+
| [gemma-2-2b.Q6_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q6_K.gguf) | Q6_K | 2.0GB |
|
38 |
+
| [gemma-2-2b.Q8_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-2b-gguf/blob/main/gemma-2-2b.Q8_0.gguf) | Q8_0 | 2.59GB |
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
Original model description:
|
44 |
+
---
|
45 |
+
license: gemma
|
46 |
+
library_name: transformers
|
47 |
+
pipeline_tag: text-generation
|
48 |
+
extra_gated_heading: Access Gemma on Hugging Face
|
49 |
+
extra_gated_prompt: >-
|
50 |
+
To access Gemma on Hugging Face, you’re required to review and agree to
|
51 |
+
Google’s usage license. To do this, please ensure you’re logged in to Hugging
|
52 |
+
Face and click below. Requests are processed immediately.
|
53 |
+
extra_gated_button_content: Acknowledge license
|
54 |
+
---
|
55 |
+
|
56 |
+
|
57 |
+
# Gemma 2 model card
|
58 |
+
|
59 |
+
**Model Page**: [Gemma](https://ai.google.dev/gemma/docs/base)
|
60 |
+
|
61 |
+
**Resources and Technical Documentation**:
|
62 |
+
|
63 |
+
* [Responsible Generative AI Toolkit][rai-toolkit]
|
64 |
+
* [Gemma on Kaggle][kaggle-gemma]
|
65 |
+
* [Gemma on Vertex Model Garden][vertex-mg-gemma2]
|
66 |
+
|
67 |
+
**Terms of Use**: [Terms][terms]
|
68 |
+
|
69 |
+
**Authors**: Google
|
70 |
+
|
71 |
+
## Model Information
|
72 |
+
|
73 |
+
Summary description and brief definition of inputs and outputs.
|
74 |
+
|
75 |
+
### Description
|
76 |
+
|
77 |
+
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
78 |
+
built from the same research and technology used to create the Gemini models.
|
79 |
+
They are text-to-text, decoder-only large language models, available in English,
|
80 |
+
with open weights for both pre-trained variants and instruction-tuned variants.
|
81 |
+
Gemma models are well-suited for a variety of text generation tasks, including
|
82 |
+
question answering, summarization, and reasoning. Their relatively small size
|
83 |
+
makes it possible to deploy them in environments with limited resources such as
|
84 |
+
a laptop, desktop or your own cloud infrastructure, democratizing access to
|
85 |
+
state of the art AI models and helping foster innovation for everyone.
|
86 |
+
|
87 |
+
### Usage
|
88 |
+
|
89 |
+
Below we share some code snippets on how to get quickly started with running the model. First, install the Transformers library with:
|
90 |
+
```sh
|
91 |
+
pip install -U transformers
|
92 |
+
```
|
93 |
+
|
94 |
+
Then, copy the snippet from the section that is relevant for your usecase.
|
95 |
+
|
96 |
+
#### Running with the `pipeline` API
|
97 |
+
|
98 |
+
```python
|
99 |
+
import torch
|
100 |
+
from transformers import pipeline
|
101 |
+
|
102 |
+
pipe = pipeline(
|
103 |
+
"text-generation",
|
104 |
+
model="google/gemma-2-2b",
|
105 |
+
device="cuda", # replace with "mps" to run on a Mac device
|
106 |
+
)
|
107 |
+
|
108 |
+
text = "Once upon a time,"
|
109 |
+
outputs = pipe(text, max_new_tokens=256)
|
110 |
+
response = outputs[0]["generated_text"]
|
111 |
+
print(response)
|
112 |
+
```
|
113 |
+
|
114 |
+
#### Running the model on a single / multi GPU
|
115 |
+
|
116 |
+
```python
|
117 |
+
# pip install accelerate
|
118 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
119 |
+
import torch
|
120 |
+
|
121 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
|
122 |
+
model = AutoModelForCausalLM.from_pretrained(
|
123 |
+
"google/gemma-2-2b",
|
124 |
+
device_map="auto",
|
125 |
+
)
|
126 |
+
|
127 |
+
input_text = "Write me a poem about Machine Learning."
|
128 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
129 |
+
|
130 |
+
outputs = model.generate(**input_ids, max_new_tokens=32)
|
131 |
+
print(tokenizer.decode(outputs[0]))
|
132 |
+
```
|
133 |
+
|
134 |
+
#### Running the model through a CLI
|
135 |
+
|
136 |
+
The [local-gemma](https://github.com/huggingface/local-gemma) repository contains a lightweight wrapper around Transformers
|
137 |
+
for running Gemma 2 through a command line interface, or CLI. Follow the [installation instructions](https://github.com/huggingface/local-gemma#cli-usage)
|
138 |
+
for getting started, then launch the CLI through the following command:
|
139 |
+
|
140 |
+
```shell
|
141 |
+
local-gemma --model "google/gemma-2-2b" --prompt "What is the capital of Mexico?"
|
142 |
+
```
|
143 |
+
|
144 |
+
#### Quantized Versions through `bitsandbytes`
|
145 |
+
|
146 |
+
<details>
|
147 |
+
<summary>
|
148 |
+
Using 8-bit precision (int8)
|
149 |
+
</summary>
|
150 |
+
|
151 |
+
```python
|
152 |
+
# pip install bitsandbytes accelerate
|
153 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
154 |
+
|
155 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
156 |
+
|
157 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
|
158 |
+
model = AutoModelForCausalLM.from_pretrained(
|
159 |
+
"google/gemma-2-2b",
|
160 |
+
quantization_config=quantization_config,
|
161 |
+
)
|
162 |
+
|
163 |
+
input_text = "Write me a poem about Machine Learning."
|
164 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
165 |
+
|
166 |
+
outputs = model.generate(**input_ids, max_new_tokens=32)
|
167 |
+
print(tokenizer.decode(outputs[0]))
|
168 |
+
```
|
169 |
+
</details>
|
170 |
+
|
171 |
+
<details>
|
172 |
+
<summary>
|
173 |
+
Using 4-bit precision
|
174 |
+
</summary>
|
175 |
+
|
176 |
+
```python
|
177 |
+
# pip install bitsandbytes accelerate
|
178 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
179 |
+
|
180 |
+
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
|
181 |
+
|
182 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
|
183 |
+
model = AutoModelForCausalLM.from_pretrained(
|
184 |
+
"google/gemma-2-2b",
|
185 |
+
quantization_config=quantization_config,
|
186 |
+
)
|
187 |
+
|
188 |
+
input_text = "Write me a poem about Machine Learning."
|
189 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
190 |
+
|
191 |
+
outputs = model.generate(**input_ids, max_new_tokens=32)
|
192 |
+
print(tokenizer.decode(outputs[0]))
|
193 |
+
```
|
194 |
+
</details>
|
195 |
+
|
196 |
+
#### Advanced Usage
|
197 |
+
|
198 |
+
<details>
|
199 |
+
<summary>
|
200 |
+
Torch compile
|
201 |
+
</summary>
|
202 |
+
|
203 |
+
[Torch compile](https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html) is a method for speeding-up the
|
204 |
+
inference of PyTorch modules. The Gemma-2 2b model can be run up to 6x faster by leveraging torch compile.
|
205 |
+
|
206 |
+
Note that two warm-up steps are required before the full inference speed is realised:
|
207 |
+
|
208 |
+
```python
|
209 |
+
import os
|
210 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
211 |
+
|
212 |
+
from transformers import AutoTokenizer, Gemma2ForCausalLM
|
213 |
+
from transformers.cache_utils import HybridCache
|
214 |
+
import torch
|
215 |
+
|
216 |
+
torch.set_float32_matmul_precision("high")
|
217 |
+
|
218 |
+
# load the model + tokenizer
|
219 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
|
220 |
+
model = Gemma2ForCausalLM.from_pretrained("google/gemma-2-2b", torch_dtype=torch.bfloat16)
|
221 |
+
model.to("cuda")
|
222 |
+
|
223 |
+
# apply the torch compile transformation
|
224 |
+
model.forward = torch.compile(model.forward, mode="reduce-overhead", fullgraph=True)
|
225 |
+
|
226 |
+
# pre-process inputs
|
227 |
+
input_text = "The theory of special relativity states "
|
228 |
+
model_inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
229 |
+
prompt_length = model_inputs.input_ids.shape[1]
|
230 |
+
|
231 |
+
# set-up k/v cache
|
232 |
+
past_key_values = HybridCache(
|
233 |
+
config=model.config,
|
234 |
+
max_batch_size=1,
|
235 |
+
max_cache_len=model.config.max_position_embeddings,
|
236 |
+
device=model.device,
|
237 |
+
dtype=model.dtype
|
238 |
+
)
|
239 |
+
|
240 |
+
# enable passing kv cache to generate
|
241 |
+
model._supports_cache_class = True
|
242 |
+
model.generation_config.cache_implementation = None
|
243 |
+
|
244 |
+
# two warm-up steps
|
245 |
+
for idx in range(2):
|
246 |
+
outputs = model.generate(**model_inputs, past_key_values=past_key_values, do_sample=True, temperature=1.0, max_new_tokens=128)
|
247 |
+
past_key_values.reset()
|
248 |
+
|
249 |
+
# fast run
|
250 |
+
outputs = model.generate(**model_inputs, past_key_values=past_key_values, do_sample=True, temperature=1.0, max_new_tokens=128)
|
251 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
252 |
+
```
|
253 |
+
|
254 |
+
For more details, refer to the [Transformers documentation](https://huggingface.co/docs/transformers/main/en/llm_optims?static-kv=basic+usage%3A+generation_config).
|
255 |
+
|
256 |
+
</details>
|
257 |
+
|
258 |
+
### Inputs and outputs
|
259 |
+
|
260 |
+
* **Input:** Text string, such as a question, a prompt, or a document to be
|
261 |
+
summarized.
|
262 |
+
* **Output:** Generated English-language text in response to the input, such
|
263 |
+
as an answer to a question, or a summary of a document.
|
264 |
+
|
265 |
+
### Citation
|
266 |
+
|
267 |
+
```none
|
268 |
+
@article{gemma_2024,
|
269 |
+
title={Gemma},
|
270 |
+
url={https://www.kaggle.com/m/3301},
|
271 |
+
DOI={10.34740/KAGGLE/M/3301},
|
272 |
+
publisher={Kaggle},
|
273 |
+
author={Gemma Team},
|
274 |
+
year={2024}
|
275 |
+
}
|
276 |
+
```
|
277 |
+
|
278 |
+
## Model Data
|
279 |
+
|
280 |
+
Data used for model training and how the data was processed.
|
281 |
+
|
282 |
+
### Training Dataset
|
283 |
+
|
284 |
+
These models were trained on a dataset of text data that includes a wide variety
|
285 |
+
of sources. The 27B model was trained with 13 trillion tokens, the 9B model was
|
286 |
+
trained with 8 trillion tokens, and 2B model was trained with 2 trillion tokens.
|
287 |
+
Here are the key components:
|
288 |
+
|
289 |
+
* Web Documents: A diverse collection of web text ensures the model is exposed
|
290 |
+
to a broad range of linguistic styles, topics, and vocabulary. Primarily
|
291 |
+
English-language content.
|
292 |
+
* Code: Exposing the model to code helps it to learn the syntax and patterns of
|
293 |
+
programming languages, which improves its ability to generate code or
|
294 |
+
understand code-related questions.
|
295 |
+
* Mathematics: Training on mathematical text helps the model learn logical
|
296 |
+
reasoning, symbolic representation, and to address mathematical queries.
|
297 |
+
|
298 |
+
The combination of these diverse data sources is crucial for training a powerful
|
299 |
+
language model that can handle a wide variety of different tasks and text
|
300 |
+
formats.
|
301 |
+
|
302 |
+
### Data Preprocessing
|
303 |
+
|
304 |
+
Here are the key data cleaning and filtering methods applied to the training
|
305 |
+
data:
|
306 |
+
|
307 |
+
* CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
|
308 |
+
applied at multiple stages in the data preparation process to ensure the
|
309 |
+
exclusion of harmful and illegal content.
|
310 |
+
* Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
|
311 |
+
reliable, automated techniques were used to filter out certain personal
|
312 |
+
information and other sensitive data from training sets.
|
313 |
+
* Additional methods: Filtering based on content quality and safety in line with
|
314 |
+
[our policies][safety-policies].
|
315 |
+
|
316 |
+
## Implementation Information
|
317 |
+
|
318 |
+
Details about the model internals.
|
319 |
+
|
320 |
+
### Hardware
|
321 |
+
|
322 |
+
Gemma was trained using the latest generation of
|
323 |
+
[Tensor Processing Unit (TPU)][tpu] hardware (TPUv5p).
|
324 |
+
|
325 |
+
Training large language models requires significant computational power. TPUs,
|
326 |
+
designed specifically for matrix operations common in machine learning, offer
|
327 |
+
several advantages in this domain:
|
328 |
+
|
329 |
+
* Performance: TPUs are specifically designed to handle the massive computations
|
330 |
+
involved in training LLMs. They can speed up training considerably compared to
|
331 |
+
CPUs.
|
332 |
+
* Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
|
333 |
+
for the handling of large models and batch sizes during training. This can
|
334 |
+
lead to better model quality.
|
335 |
+
* Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
|
336 |
+
handling the growing complexity of large foundation models. You can distribute
|
337 |
+
training across multiple TPU devices for faster and more efficient processing.
|
338 |
+
* Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
|
339 |
+
solution for training large models compared to CPU-based infrastructure,
|
340 |
+
especially when considering the time and resources saved due to faster
|
341 |
+
training.
|
342 |
+
* These advantages are aligned with
|
343 |
+
[Google's commitments to operate sustainably][sustainability].
|
344 |
+
|
345 |
+
### Software
|
346 |
+
|
347 |
+
Training was done using [JAX][jax] and [ML Pathways][ml-pathways].
|
348 |
+
|
349 |
+
JAX allows researchers to take advantage of the latest generation of hardware,
|
350 |
+
including TPUs, for faster and more efficient training of large models.
|
351 |
+
|
352 |
+
ML Pathways is Google's latest effort to build artificially intelligent systems
|
353 |
+
capable of generalizing across multiple tasks. This is specially suitable for
|
354 |
+
[foundation models][foundation-models], including large language models like
|
355 |
+
these ones.
|
356 |
+
|
357 |
+
Together, JAX and ML Pathways are used as described in the
|
358 |
+
[paper about the Gemini family of models][gemini-2-paper]; "the 'single
|
359 |
+
controller' programming model of Jax and Pathways allows a single Python
|
360 |
+
process to orchestrate the entire training run, dramatically simplifying the
|
361 |
+
development workflow."
|
362 |
+
|
363 |
+
## Evaluation
|
364 |
+
|
365 |
+
Model evaluation metrics and results.
|
366 |
+
|
367 |
+
### Benchmark Results
|
368 |
+
|
369 |
+
These models were evaluated against a large collection of different datasets and
|
370 |
+
metrics to cover different aspects of text generation:
|
371 |
+
|
372 |
+
| Benchmark | Metric | Gemma 2 PT 2B | Gemma 2 PT 9B | Gemma 2 PT 27B |
|
373 |
+
| ------------------------------ | ------------- | ------------- | ------------- | -------------- |
|
374 |
+
| [MMLU][mmlu] | 5-shot, top-1 | 51.3 | 71.3 | 75.2 |
|
375 |
+
| [HellaSwag][hellaswag] | 10-shot | 73.0 | 81.9 | 86.4 |
|
376 |
+
| [PIQA][piqa] | 0-shot | 77.8 | 81.7 | 83.2 |
|
377 |
+
| [SocialIQA][socialiqa] | 0-shot | 51.9 | 53.4 | 53.7 |
|
378 |
+
| [BoolQ][boolq] | 0-shot | 72.5 | 84.2 | 84.8 |
|
379 |
+
| [WinoGrande][winogrande] | partial score | 70.9 | 80.6 | 83.7 |
|
380 |
+
| [ARC-e][arc] | 0-shot | 80.1 | 88.0 | 88.6 |
|
381 |
+
| [ARC-c][arc] | 25-shot | 55.4 | 68.4 | 71.4 |
|
382 |
+
| [TriviaQA][triviaqa] | 5-shot | 59.4 | 76.6 | 83.7 |
|
383 |
+
| [Natural Questions][naturalq] | 5-shot | 16.7 | 29.2 | 34.5 |
|
384 |
+
| [HumanEval][humaneval] | pass@1 | 17.7 | 40.2 | 51.8 |
|
385 |
+
| [MBPP][mbpp] | 3-shot | 29.6 | 52.4 | 62.6 |
|
386 |
+
| [GSM8K][gsm8k] | 5-shot, maj@1 | 23.9 | 68.6 | 74.0 |
|
387 |
+
| [MATH][math] | 4-shot | 15.0 | 36.6 | 42.3 |
|
388 |
+
| [AGIEval][agieval] | 3-5-shot | 30.6 | 52.8 | 55.1 |
|
389 |
+
| [DROP][drop] | 3-shot, F1 | 52.0 | 69.4 | 72.2 |
|
390 |
+
| [BIG-Bench][big-bench] | 3-shot, CoT | 41.9 | 68.2 | 74.9 |
|
391 |
+
|
392 |
+
## Ethics and Safety
|
393 |
+
|
394 |
+
Ethics and safety evaluation approach and results.
|
395 |
+
|
396 |
+
### Evaluation Approach
|
397 |
+
|
398 |
+
Our evaluation methods include structured evaluations and internal red-teaming
|
399 |
+
testing of relevant content policies. Red-teaming was conducted by a number of
|
400 |
+
different teams, each with different goals and human evaluation metrics. These
|
401 |
+
models were evaluated against a number of different categories relevant to
|
402 |
+
ethics and safety, including:
|
403 |
+
|
404 |
+
* Text-to-Text Content Safety: Human evaluation on prompts covering safety
|
405 |
+
policies including child sexual abuse and exploitation, harassment, violence
|
406 |
+
and gore, and hate speech.
|
407 |
+
* Text-to-Text Representational Harms: Benchmark against relevant academic
|
408 |
+
datasets such as [WinoBias][winobias] and [BBQ Dataset][bbq].
|
409 |
+
* Memorization: Automated evaluation of memorization of training data, including
|
410 |
+
the risk of personally identifiable information exposure.
|
411 |
+
* Large-scale harm: Tests for "dangerous capabilities," such as chemical,
|
412 |
+
biological, radiological, and nuclear (CBRN) risks.
|
413 |
+
|
414 |
+
### Evaluation Results
|
415 |
+
|
416 |
+
The results of ethics and safety evaluations are within acceptable thresholds
|
417 |
+
for meeting [internal policies][safety-policies] for categories such as child
|
418 |
+
safety, content safety, representational harms, memorization, large-scale harms.
|
419 |
+
On top of robust internal evaluations, the results of well-known safety
|
420 |
+
benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
|
421 |
+
are shown here.
|
422 |
+
|
423 |
+
#### Gemma 2.0
|
424 |
+
|
425 |
+
| Benchmark | Metric | Gemma 2 IT 2B | Gemma 2 IT 9B | Gemma 2 IT 27B |
|
426 |
+
| ------------------------ | ------------- | ------------- | ------------- | -------------- |
|
427 |
+
| [RealToxicity][realtox] | average | 8.16 | 8.25 | 8.84 |
|
428 |
+
| [CrowS-Pairs][crows] | top-1 | 37.67 | 37.47 | 36.67 |
|
429 |
+
| [BBQ Ambig][bbq] | 1-shot, top-1 | 83.20 | 88.58 | 85.99 |
|
430 |
+
| [BBQ Disambig][bbq] | top-1 | 69.31 | 82.67 | 86.94 |
|
431 |
+
| [Winogender][winogender] | top-1 | 52.91 | 79.17 | 77.22 |
|
432 |
+
| [TruthfulQA][truthfulqa] | | 43.72 | 50.27 | 51.60 |
|
433 |
+
| [Winobias 1_2][winobias] | | 59.28 | 78.09 | 81.94 |
|
434 |
+
| [Winobias 2_2][winobias] | | 88.57 | 95.32 | 97.22 |
|
435 |
+
| [Toxigen][toxigen] | | 48.32 | 39.30 | 38.42 |
|
436 |
+
|
437 |
+
## Dangerous Capability Evaluations
|
438 |
+
|
439 |
+
### Evaluation Approach
|
440 |
+
|
441 |
+
We evaluated a range of dangerous capabilities:
|
442 |
+
|
443 |
+
- **Offensive cybersecurity:** To assess the model's potential for misuse in
|
444 |
+
cybersecurity contexts, we utilized both publicly available
|
445 |
+
Capture-the-Flag (CTF) platforms like InterCode-CTF and Hack the Box, as
|
446 |
+
well as internally developed CTF challenges. These evaluations measure the
|
447 |
+
model's ability to exploit vulnerabilities and gain unauthorized access in
|
448 |
+
simulated environments.
|
449 |
+
- **Self-proliferation:** We evaluated the model's capacity for
|
450 |
+
self-proliferation by designing tasks that involve resource acquisition, code
|
451 |
+
execution, and interaction with remote systems. These evaluations assess
|
452 |
+
the model's ability to independently replicate and spread.
|
453 |
+
- **Persuasion:** To evaluate the model's capacity for persuasion and
|
454 |
+
deception, we conducted human persuasion studies. These studies involved
|
455 |
+
scenarios that measure the model's ability to build rapport, influence
|
456 |
+
beliefs, and elicit specific actions from human participants.
|
457 |
+
|
458 |
+
### Evaluation Results
|
459 |
+
|
460 |
+
All evaluations are described in detail in
|
461 |
+
[Evaluating Frontier Models for Dangerous Capabilities][eval-danger]
|
462 |
+
and in brief in the
|
463 |
+
[Gemma 2 technical report][tech-report].
|
464 |
+
|
465 |
+
<table>
|
466 |
+
<thead>
|
467 |
+
<tr>
|
468 |
+
<th>Evaluation</th>
|
469 |
+
<th>Capability</th>
|
470 |
+
<th>Gemma 2 IT 27B</th>
|
471 |
+
</tr>
|
472 |
+
</thead>
|
473 |
+
<tbody>
|
474 |
+
<tr>
|
475 |
+
<td>InterCode-CTF</td>
|
476 |
+
<td>Offensive cybersecurity</td>
|
477 |
+
<td>34/76 challenges</td>
|
478 |
+
</tr>
|
479 |
+
<tr>
|
480 |
+
<td>Internal CTF</td>
|
481 |
+
<td>Offensive cybersecurity</td>
|
482 |
+
<td>1/13 challenges</td>
|
483 |
+
</tr>
|
484 |
+
<tr>
|
485 |
+
<td>Hack the Box</td>
|
486 |
+
<td>Offensive cybersecurity</td>
|
487 |
+
<td>0/13 challenges</td>
|
488 |
+
</tr>
|
489 |
+
<tr>
|
490 |
+
<td>Self-proliferation early warning</td>
|
491 |
+
<td>Self-proliferation</td>
|
492 |
+
<td>1/10 challenges</td>
|
493 |
+
</tr>
|
494 |
+
<tr>
|
495 |
+
<td>Charm offensive</td>
|
496 |
+
<td>Persuasion</td>
|
497 |
+
<td>Percent of participants agreeing:
|
498 |
+
81% interesting,
|
499 |
+
75% would speak again,
|
500 |
+
80% made personal connection</td>
|
501 |
+
</tr>
|
502 |
+
<tr>
|
503 |
+
<td>Click Links</td>
|
504 |
+
<td>Persuasion</td>
|
505 |
+
<td>34% of participants</td>
|
506 |
+
</tr>
|
507 |
+
<tr>
|
508 |
+
<td>Find Info</td>
|
509 |
+
<td>Persuasion</td>
|
510 |
+
<td>9% of participants</td>
|
511 |
+
</tr>
|
512 |
+
<tr>
|
513 |
+
<td>Run Code</td>
|
514 |
+
<td>Persuasion</td>
|
515 |
+
<td>11% of participants</td>
|
516 |
+
</tr>
|
517 |
+
<tr>
|
518 |
+
<td>Money talks</td>
|
519 |
+
<td>Persuasion</td>
|
520 |
+
<td>£3.72 mean donation</td>
|
521 |
+
</tr>
|
522 |
+
<tr>
|
523 |
+
<td>Web of Lies</td>
|
524 |
+
<td>Persuasion</td>
|
525 |
+
<td>18% mean shift towards correct belief, 1% mean shift towards
|
526 |
+
incorrect belief</td>
|
527 |
+
</tr>
|
528 |
+
</tbody>
|
529 |
+
</table>
|
530 |
+
|
531 |
+
## Usage and Limitations
|
532 |
+
|
533 |
+
These models have certain limitations that users should be aware of.
|
534 |
+
|
535 |
+
### Intended Usage
|
536 |
+
|
537 |
+
Open Large Language Models (LLMs) have a wide range of applications across
|
538 |
+
various industries and domains. The following list of potential uses is not
|
539 |
+
comprehensive. The purpose of this list is to provide contextual information
|
540 |
+
about the possible use-cases that the model creators considered as part of model
|
541 |
+
training and development.
|
542 |
+
|
543 |
+
* Content Creation and Communication
|
544 |
+
* Text Generation: These models can be used to generate creative text formats
|
545 |
+
such as poems, scripts, code, marketing copy, and email drafts.
|
546 |
+
* Chatbots and Conversational AI: Power conversational interfaces for customer
|
547 |
+
service, virtual assistants, or interactive applications.
|
548 |
+
* Text Summarization: Generate concise summaries of a text corpus, research
|
549 |
+
papers, or reports.
|
550 |
+
* Research and Education
|
551 |
+
* Natural Language Processing (NLP) Research: These models can serve as a
|
552 |
+
foundation for researchers to experiment with NLP techniques, develop
|
553 |
+
algorithms, and contribute to the advancement of the field.
|
554 |
+
* Language Learning Tools: Support interactive language learning experiences,
|
555 |
+
aiding in grammar correction or providing writing practice.
|
556 |
+
* Knowledge Exploration: Assist researchers in exploring large bodies of text
|
557 |
+
by generating summaries or answering questions about specific topics.
|
558 |
+
|
559 |
+
### Limitations
|
560 |
+
|
561 |
+
* Training Data
|
562 |
+
* The quality and diversity of the training data significantly influence the
|
563 |
+
model's capabilities. Biases or gaps in the training data can lead to
|
564 |
+
limitations in the model's responses.
|
565 |
+
* The scope of the training dataset determines the subject areas the model can
|
566 |
+
handle effectively.
|
567 |
+
* Context and Task Complexity
|
568 |
+
* LLMs are better at tasks that can be framed with clear prompts and
|
569 |
+
instructions. Open-ended or highly complex tasks might be challenging.
|
570 |
+
* A model's performance can be influenced by the amount of context provided
|
571 |
+
(longer context generally leads to better outputs, up to a certain point).
|
572 |
+
* Language Ambiguity and Nuance
|
573 |
+
* Natural language is inherently complex. LLMs might struggle to grasp subtle
|
574 |
+
nuances, sarcasm, or figurative language.
|
575 |
+
* Factual Accuracy
|
576 |
+
* LLMs generate responses based on information they learned from their
|
577 |
+
training datasets, but they are not knowledge bases. They may generate
|
578 |
+
incorrect or outdated factual statements.
|
579 |
+
* Common Sense
|
580 |
+
* LLMs rely on statistical patterns in language. They might lack the ability
|
581 |
+
to apply common sense reasoning in certain situations.
|
582 |
+
|
583 |
+
### Ethical Considerations and Risks
|
584 |
+
|
585 |
+
The development of large language models (LLMs) raises several ethical concerns.
|
586 |
+
In creating an open model, we have carefully considered the following:
|
587 |
+
|
588 |
+
* Bias and Fairness
|
589 |
+
* LLMs trained on large-scale, real-world text data can reflect socio-cultural
|
590 |
+
biases embedded in the training material. These models underwent careful
|
591 |
+
scrutiny, input data pre-processing described and posterior evaluations
|
592 |
+
reported in this card.
|
593 |
+
* Misinformation and Misuse
|
594 |
+
* LLMs can be misused to generate text that is false, misleading, or harmful.
|
595 |
+
* Guidelines are provided for responsible use with the model, see the
|
596 |
+
[Responsible Generative AI Toolkit][rai-toolkit].
|
597 |
+
* Transparency and Accountability:
|
598 |
+
* This model card summarizes details on the models' architecture,
|
599 |
+
capabilities, limitations, and evaluation processes.
|
600 |
+
* A responsibly developed open model offers the opportunity to share
|
601 |
+
innovation by making LLM technology accessible to developers and researchers
|
602 |
+
across the AI ecosystem.
|
603 |
+
|
604 |
+
Risks identified and mitigations:
|
605 |
+
|
606 |
+
* Perpetuation of biases: It's encouraged to perform continuous monitoring
|
607 |
+
(using evaluation metrics, human review) and the exploration of de-biasing
|
608 |
+
techniques during model training, fine-tuning, and other use cases.
|
609 |
+
* Generation of harmful content: Mechanisms and guidelines for content safety
|
610 |
+
are essential. Developers are encouraged to exercise caution and implement
|
611 |
+
appropriate content safety safeguards based on their specific product policies
|
612 |
+
and application use cases.
|
613 |
+
* Misuse for malicious purposes: Technical limitations and developer and
|
614 |
+
end-user education can help mitigate against malicious applications of LLMs.
|
615 |
+
Educational resources and reporting mechanisms for users to flag misuse are
|
616 |
+
provided. Prohibited uses of Gemma models are outlined in the
|
617 |
+
[Gemma Prohibited Use Policy][prohibited-use].
|
618 |
+
* Privacy violations: Models were trained on data filtered for removal of PII
|
619 |
+
(Personally Identifiable Information). Developers are encouraged to adhere to
|
620 |
+
privacy regulations with privacy-preserving techniques.
|
621 |
+
|
622 |
+
### Benefits
|
623 |
+
|
624 |
+
At the time of release, this family of models provides high-performance open
|
625 |
+
large language model implementations designed from the ground up for Responsible
|
626 |
+
AI development compared to similarly sized models.
|
627 |
+
|
628 |
+
Using the benchmark evaluation metrics described in this document, these models
|
629 |
+
have shown to provide superior performance to other, comparably-sized open model
|
630 |
+
alternatives.
|
631 |
+
|
632 |
+
[tech-report]: https://storage.googleapis.com/deepmind-media/gemma/gemma-2-report.pdf
|
633 |
+
[rai-toolkit]: https://ai.google.dev/responsible
|
634 |
+
[kaggle-gemma]: https://www.kaggle.com/models/google/gemma-2
|
635 |
+
[terms]: https://ai.google.dev/gemma/terms
|
636 |
+
[vertex-mg-gemma2]: https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/gemma2
|
637 |
+
[sensitive-info]: https://cloud.google.com/dlp/docs/high-sensitivity-infotypes-reference
|
638 |
+
[safety-policies]: https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11
|
639 |
+
[prohibited-use]: https://ai.google.dev/gemma/prohibited_use_policy
|
640 |
+
[tpu]: https://cloud.google.com/tpu/docs/intro-to-tpu
|
641 |
+
[sustainability]: https://sustainability.google/operating-sustainably/
|
642 |
+
[jax]: https://github.com/google/jax
|
643 |
+
[ml-pathways]: https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/
|
644 |
+
[sustainability]: https://sustainability.google/operating-sustainably/
|
645 |
+
[foundation-models]: https://ai.google/discover/foundation-models/
|
646 |
+
[gemini-2-paper]: https://goo.gle/gemma2report
|
647 |
+
[mmlu]: https://arxiv.org/abs/2009.03300
|
648 |
+
[hellaswag]: https://arxiv.org/abs/1905.07830
|
649 |
+
[piqa]: https://arxiv.org/abs/1911.11641
|
650 |
+
[socialiqa]: https://arxiv.org/abs/1904.09728
|
651 |
+
[boolq]: https://arxiv.org/abs/1905.10044
|
652 |
+
[winogrande]: https://arxiv.org/abs/1907.10641
|
653 |
+
[commonsenseqa]: https://arxiv.org/abs/1811.00937
|
654 |
+
[openbookqa]: https://arxiv.org/abs/1809.02789
|
655 |
+
[arc]: https://arxiv.org/abs/1911.01547
|
656 |
+
[triviaqa]: https://arxiv.org/abs/1705.03551
|
657 |
+
[naturalq]: https://github.com/google-research-datasets/natural-questions
|
658 |
+
[humaneval]: https://arxiv.org/abs/2107.03374
|
659 |
+
[mbpp]: https://arxiv.org/abs/2108.07732
|
660 |
+
[gsm8k]: https://arxiv.org/abs/2110.14168
|
661 |
+
[realtox]: https://arxiv.org/abs/2009.11462
|
662 |
+
[bold]: https://arxiv.org/abs/2101.11718
|
663 |
+
[crows]: https://aclanthology.org/2020.emnlp-main.154/
|
664 |
+
[bbq]: https://arxiv.org/abs/2110.08193v2
|
665 |
+
[winogender]: https://arxiv.org/abs/1804.09301
|
666 |
+
[truthfulqa]: https://arxiv.org/abs/2109.07958
|
667 |
+
[winobias]: https://arxiv.org/abs/1804.06876
|
668 |
+
[math]: https://arxiv.org/abs/2103.03874
|
669 |
+
[agieval]: https://arxiv.org/abs/2304.06364
|
670 |
+
[drop]: https://arxiv.org/abs/1903.00161
|
671 |
+
[big-bench]: https://arxiv.org/abs/2206.04615
|
672 |
+
[toxigen]: https://arxiv.org/abs/2203.09509
|
673 |
+
[eval-danger]: https://arxiv.org/abs/2403.13793
|
674 |
+
|
675 |
+
|