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