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