jartine commited on
Commit
44bd858
1 Parent(s): 792619b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +738 -0
README.md ADDED
@@ -0,0 +1,738 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ quantized_by: jartine
4
+ license_link: LICENSE
5
+ library_name: transformers
6
+ base_model: google/gemma-2-9b-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 9b Instruct - llamafile
20
+
21
+ Gemma v2 is a large language model released by Google on Jun 27th 2024.
22
+
23
+ - Model creator: [Google](https://huggingface.co/google/)
24
+ - Original model: [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-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 7.3,
29
+ and NetBSD for AMD64 and ARM64.
30
+
31
+ *Software Last Updated: 2024-11-01*
32
+
33
+ ## Quickstart
34
+
35
+ To get started, you need both the Gemma weights, and the llamafile
36
+ software. Both of them are included in a single file, which can be
37
+ downloaded and run as follows:
38
+
39
+ ```
40
+ wget https://huggingface.co/Mozilla/gemma-2-9b-it-llamafile/resolve/main/gemma-2-9b-it.Q6_K.llamafile
41
+ chmod +x gemma-2-9b-it.Q6_K.llamafile
42
+ ./gemma-2-9b-it.Q6_K.llamafile
43
+ ```
44
+
45
+ The default mode of operation for these llamafiles is our new command
46
+ line chatbot interface.
47
+
48
+ ![Screenshot of Gemma 2b llamafile on MacOS](llamafile-gemma.png)
49
+
50
+ Having **trouble?** See the ["Gotchas"
51
+ section](https://github.com/mozilla-ocho/llamafile/?tab=readme-ov-file#gotchas-and-troubleshooting)
52
+ of the README.
53
+
54
+ ## Usage
55
+
56
+ By default, llamafile launches a chatbot in the terminal, and a server
57
+ in the background. The chatbot is mostly self-explanatory. You can type
58
+ `/help` for further details. See the [llamafile v0.8.15 release
59
+ notes](https://github.com/Mozilla-Ocho/llamafile/releases/tag/0.8.15)
60
+ for documentation on our newest chatbot features.
61
+
62
+ To instruct Gemma to do role playing, you can customize the system
63
+ prompt as follows:
64
+
65
+ ```
66
+ ./gemma-2-9b-it.Q6_K.llamafile --chat -p "you are mosaic's godzilla"
67
+ ```
68
+
69
+ To view the man page, run:
70
+
71
+ ```
72
+ ./gemma-2-9b-it.Q6_K.llamafile --help
73
+ ```
74
+
75
+ To send a request to the OpenAI API compatible llamafile server, try:
76
+
77
+ ```
78
+ curl http://localhost:8080/v1/chat/completions \
79
+ -H "Content-Type: application/json" \
80
+ -d '{
81
+ "model": "gemma-9b-it",
82
+ "messages": [{"role": "user", "content": "Say this is a test!"}],
83
+ "temperature": 0.0
84
+ }'
85
+ ```
86
+
87
+ If you don't want the chatbot and you only want to run the server:
88
+
89
+ ```
90
+ ./gemma-2-9b-it.Q6_K.llamafile --server --nobrowser --host 0.0.0.0
91
+ ```
92
+
93
+ An advanced CLI mode is provided that's useful for shell scripting. You
94
+ can use it by passing the `--cli` flag. For additional help on how it
95
+ may be used, pass the `--help` flag.
96
+
97
+ ```
98
+ ./gemma-2-9b-it.Q6_K.llamafile --cli -p 'four score and seven' --log-disable
99
+ ```
100
+
101
+ You then need to fill out the prompt / history template (see below).
102
+
103
+ For further information, please see the [llamafile
104
+ README](https://github.com/mozilla-ocho/llamafile/).
105
+
106
+ ## Troubleshooting
107
+
108
+ Having **trouble?** See the ["Gotchas"
109
+ section](https://github.com/mozilla-ocho/llamafile/?tab=readme-ov-file#gotchas-and-troubleshooting)
110
+ of the README.
111
+
112
+ On Linux, the way to avoid run-detector errors is to install the APE
113
+ interpreter.
114
+
115
+ ```sh
116
+ sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf
117
+ sudo chmod +x /usr/bin/ape
118
+ sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
119
+ sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
120
+ ```
121
+
122
+ On Windows there's a 4GB limit on executable sizes. This means you
123
+ should download the Q2\_K llamafile. For better quality, consider
124
+ instead downloading the official llamafile release binary from
125
+ <https://github.com/Mozilla-Ocho/llamafile/releases>, renaming it to
126
+ have the .exe file extension, and then saying:
127
+
128
+ ```
129
+ .\llamafile-0.8.15.exe -m gemma-2-9b-it.Q6_K.llamafile
130
+ ```
131
+
132
+ That will overcome the Windows 4GB file size limit, allowing you to
133
+ benefit from bigger better models.
134
+
135
+ ## Context Window
136
+
137
+ This model has a max context window size of 8k tokens. By default, a
138
+ context window size of 8192 tokens is used. You may limit the context
139
+ window size by passing the `-c N` flag.
140
+
141
+ ## GPU Acceleration
142
+
143
+ On GPUs with sufficient RAM, the `-ngl 999` flag may be passed to use
144
+ the system's NVIDIA or AMD GPU(s). On Windows, only the graphics card
145
+ driver needs to be installed if you own an NVIDIA GPU. On Windows, if
146
+ you have an AMD GPU, you should install the ROCm SDK v6.1 and then pass
147
+ the flags `--recompile --gpu amd` the first time you run your llamafile.
148
+
149
+ On NVIDIA GPUs, by default, the prebuilt tinyBLAS library is used to
150
+ perform matrix multiplications. This is open source software, but it
151
+ doesn't go as fast as closed source cuBLAS. If you have the CUDA SDK
152
+ installed on your system, then you can pass the `--recompile` flag to
153
+ build a GGML CUDA library just for your system that uses cuBLAS. This
154
+ ensures you get maximum performance.
155
+
156
+ For further information, please see the [llamafile
157
+ README](https://github.com/mozilla-ocho/llamafile/).
158
+
159
+ ## About llamafile
160
+
161
+ llamafile is a new format introduced by Mozilla on Nov 20th 2023. It
162
+ uses Cosmopolitan Libc to turn LLM weights into runnable llama.cpp
163
+ binaries that run on the stock installs of six OSes for both ARM64 and
164
+ AMD64.
165
+
166
+ ## About Quantization Formats
167
+
168
+ This model works well with any quantization format. Q6\_K is the best
169
+ choice overall here. We tested that, with [our 27b Gemma2
170
+ llamafiles](https://huggingface.co/Mozilla/gemma-2-27b-it-llamafile),
171
+ that the llamafile implementation of Gemma2 is able to to produce
172
+ identical responses to the Gemma2 model that's hosted by Google on
173
+ aistudio.google.com. Therefore we'd assume these 9b llamafiles are also
174
+ faithful to Google's intentions. If you encounter any divergences, then
175
+ try using the BF16 weights, which have the original fidelity.
176
+
177
+ ## See Also
178
+
179
+ - <https://huggingface.co/Mozilla/gemma-2-2b-it-llamafile>
180
+ - <https://huggingface.co/Mozilla/gemma-2-27b-it-llamafile>
181
+
182
+ ## License
183
+
184
+ The llamafile software is open source and permissively licensed. However
185
+ the weights embedded inside the llamafiles are governed by Google's
186
+ Gemma License and Gemma Prohibited Use Policy. See the
187
+ [LICENSE](LICENSE) file for further details.
188
+
189
+ ---
190
+
191
+ # Gemma 2 model card
192
+
193
+ **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
194
+
195
+ **Resources and Technical Documentation**:
196
+
197
+ * [Responsible Generative AI Toolkit][rai-toolkit]
198
+ * [Gemma on Kaggle][kaggle-gemma]
199
+ * [Gemma on Vertex Model Garden][vertex-mg-gemma]
200
+
201
+ **Terms of Use**: [Terms](https://www.kaggle.com/models/google/gemma/license/consent/verify/huggingface?returnModelRepoId=google/gemma-2-9b-it)
202
+
203
+ **Authors**: Google
204
+
205
+ ## Model Information
206
+
207
+ Summary description and brief definition of inputs and outputs.
208
+
209
+ ### Description
210
+
211
+ Gemma is a family of lightweight, state-of-the-art open models from Google,
212
+ built from the same research and technology used to create the Gemini models.
213
+ They are text-to-text, decoder-only large language models, available in English,
214
+ with open weights for both pre-trained variants and instruction-tuned variants.
215
+ Gemma models are well-suited for a variety of text generation tasks, including
216
+ question answering, summarization, and reasoning. Their relatively small size
217
+ makes it possible to deploy them in environments with limited resources such as
218
+ a laptop, desktop or your own cloud infrastructure, democratizing access to
219
+ state of the art AI models and helping foster innovation for everyone.
220
+
221
+ ### Usage
222
+
223
+ Below we share some code snippets on how to get quickly started with running the model. First make sure to `pip install -U transformers`, then copy the snippet from the section that is relevant for your usecase.
224
+
225
+
226
+ #### Running the model on a single / multi GPU
227
+
228
+
229
+ ```python
230
+ # pip install accelerate
231
+ from transformers import AutoTokenizer, AutoModelForCausalLM
232
+ import torch
233
+
234
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
235
+ model = AutoModelForCausalLM.from_pretrained(
236
+ "google/gemma-2-9b-it",
237
+ device_map="auto",
238
+ torch_dtype=torch.bfloat16
239
+ )
240
+
241
+ input_text = "Write me a poem about Machine Learning."
242
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
243
+
244
+ outputs = model.generate(**input_ids)
245
+ print(tokenizer.decode(outputs[0]))
246
+ ```
247
+
248
+ <a name="precisions"></a>
249
+ #### Running the model on a GPU using different precisions
250
+
251
+ The native weights of this model were exported in `bfloat16` precision. You can use `float16`, which may be faster on certain hardware, indicating the `torch_dtype` when loading the model. For convenience, the `float16` revision of the repo contains a copy of the weights already converted to that precision.
252
+
253
+ 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.
254
+
255
+ * _Using `torch.float16`_
256
+
257
+ ```python
258
+ # pip install accelerate
259
+ from transformers import AutoTokenizer, AutoModelForCausalLM
260
+ import torch
261
+
262
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
263
+ model = AutoModelForCausalLM.from_pretrained(
264
+ "google/gemma-2-9b-it",
265
+ device_map="auto",
266
+ torch_dtype=torch.float16,
267
+ revision="float16",
268
+ )
269
+
270
+ input_text = "Write me a poem about Machine Learning."
271
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
272
+
273
+ outputs = model.generate(**input_ids)
274
+ print(tokenizer.decode(outputs[0]))
275
+ ```
276
+
277
+ * _Using `torch.bfloat16`_
278
+
279
+ ```python
280
+ # pip install accelerate
281
+ from transformers import AutoTokenizer, AutoModelForCausalLM
282
+
283
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
284
+ model = AutoModelForCausalLM.from_pretrained(
285
+ "google/gemma-2-9b-it",
286
+ device_map="auto",
287
+ torch_dtype=torch.bfloat16)
288
+
289
+ input_text = "Write me a poem about Machine Learning."
290
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
291
+
292
+ outputs = model.generate(**input_ids)
293
+ print(tokenizer.decode(outputs[0]))
294
+ ```
295
+
296
+ * _Upcasting to `torch.float32`_
297
+
298
+ ```python
299
+ # pip install accelerate
300
+ from transformers import AutoTokenizer, AutoModelForCausalLM
301
+
302
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
303
+ model = AutoModelForCausalLM.from_pretrained(
304
+ "google/gemma-2-9b-it",
305
+ device_map="auto")
306
+
307
+ input_text = "Write me a poem about Machine Learning."
308
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
309
+
310
+ outputs = model.generate(**input_ids)
311
+ print(tokenizer.decode(outputs[0]))
312
+ ```
313
+
314
+ #### Quantized Versions through `bitsandbytes`
315
+
316
+ * _Using 8-bit precision (int8)_
317
+
318
+ ```python
319
+ # pip install bitsandbytes accelerate
320
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
321
+
322
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
323
+
324
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
325
+ model = AutoModelForCausalLM.from_pretrained(
326
+ "google/gemma-2-9b-it",
327
+ quantization_config=quantization_config)
328
+
329
+ input_text = "Write me a poem about Machine Learning."
330
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
331
+
332
+ outputs = model.generate(**input_ids)
333
+ print(tokenizer.decode(outputs[0]))
334
+ ```
335
+
336
+ * _Using 4-bit precision_
337
+
338
+ ```python
339
+ # pip install bitsandbytes accelerate
340
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
341
+
342
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True)
343
+
344
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
345
+ model = AutoModelForCausalLM.from_pretrained(
346
+ "google/gemma-2-9b-it",
347
+ quantization_config=quantization_config)
348
+
349
+ input_text = "Write me a poem about Machine Learning."
350
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
351
+
352
+ outputs = model.generate(**input_ids)
353
+ print(tokenizer.decode(outputs[0]))
354
+ ```
355
+
356
+
357
+ #### Other optimizations
358
+
359
+ * _Flash Attention 2_
360
+
361
+ First make sure to install `flash-attn` in your environment `pip install flash-attn`
362
+
363
+ ```diff
364
+ model = AutoModelForCausalLM.from_pretrained(
365
+ model_id,
366
+ torch_dtype=torch.float16,
367
+ + attn_implementation="flash_attention_2"
368
+ ).to(0)
369
+ ```
370
+
371
+ ### Chat Template
372
+
373
+ The instruction-tuned models use a chat template that must be adhered to for conversational use.
374
+ The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
375
+
376
+ Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
377
+
378
+ ```py
379
+ from transformers import AutoTokenizer, AutoModelForCausalLM
380
+ import transformers
381
+ import torch
382
+
383
+ model_id = "google/gemma-2-9b-it"
384
+ dtype = torch.bfloat16
385
+
386
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
387
+ model = AutoModelForCausalLM.from_pretrained(
388
+ model_id,
389
+ device_map="cuda",
390
+ torch_dtype=dtype,)
391
+
392
+ chat = [
393
+ { "role": "user", "content": "Write a hello world program" },
394
+ ]
395
+ prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
396
+ ```
397
+
398
+ At this point, the prompt contains the following text:
399
+
400
+ ```
401
+ <bos><start_of_turn>user
402
+ Write a hello world program<end_of_turn>
403
+ <start_of_turn>model
404
+ ```
405
+
406
+ As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
407
+ (either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
408
+ the `<end_of_turn>` token.
409
+
410
+ You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
411
+ chat template.
412
+
413
+ After the prompt is ready, generation can be performed like this:
414
+
415
+ ```py
416
+ inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
417
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
418
+ print(tokenizer.decode(outputs[0]))
419
+ ```
420
+
421
+ ### Inputs and outputs
422
+
423
+ * **Input:** Text string, such as a question, a prompt, or a document to be
424
+ summarized.
425
+ * **Output:** Generated English-language text in response to the input, such
426
+ as an answer to a question, or a summary of a document.
427
+
428
+ ### Citation
429
+
430
+ ```none
431
+ @article{gemma_2024,
432
+ title={Gemma},
433
+ url={https://www.kaggle.com/m/3301},
434
+ DOI={10.34740/KAGGLE/M/3301},
435
+ publisher={Kaggle},
436
+ author={Gemma Team},
437
+ year={2024}
438
+ }
439
+ ```
440
+
441
+ ## Model Data
442
+
443
+ Data used for model training and how the data was processed.
444
+
445
+ ### Training Dataset
446
+
447
+ These models were trained on a dataset of text data that includes a wide variety of sources. The 27B model was trained with 13 trillion tokens and the 9B model was trained with 8 trillion tokens.
448
+ Here are the key components:
449
+
450
+ * Web Documents: A diverse collection of web text ensures the model is exposed
451
+ to a broad range of linguistic styles, topics, and vocabulary. Primarily
452
+ English-language content.
453
+ * Code: Exposing the model to code helps it to learn the syntax and patterns of
454
+ programming languages, which improves its ability to generate code or
455
+ understand code-related questions.
456
+ * Mathematics: Training on mathematical text helps the model learn logical
457
+ reasoning, symbolic representation, and to address mathematical queries.
458
+
459
+ The combination of these diverse data sources is crucial for training a powerful
460
+ language model that can handle a wide variety of different tasks and text
461
+ formats.
462
+
463
+ ### Data Preprocessing
464
+
465
+ Here are the key data cleaning and filtering methods applied to the training
466
+ data:
467
+
468
+ * CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
469
+ applied at multiple stages in the data preparation process to ensure the
470
+ exclusion of harmful and illegal content.
471
+ * Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
472
+ reliable, automated techniques were used to filter out certain personal
473
+ information and other sensitive data from training sets.
474
+ * Additional methods: Filtering based on content quality and safety in line with
475
+ [our policies][safety-policies].
476
+
477
+ ## Implementation Information
478
+
479
+ Details about the model internals.
480
+
481
+ ### Hardware
482
+
483
+ Gemma was trained using the latest generation of
484
+ [Tensor Processing Unit (TPU)][tpu] hardware (TPUv5p).
485
+
486
+ Training large language models requires significant computational power. TPUs,
487
+ designed specifically for matrix operations common in machine learning, offer
488
+ several advantages in this domain:
489
+
490
+ * Performance: TPUs are specifically designed to handle the massive computations
491
+ involved in training LLMs. They can speed up training considerably compared to
492
+ CPUs.
493
+ * Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
494
+ for the handling of large models and batch sizes during training. This can
495
+ lead to better model quality.
496
+ * Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
497
+ handling the growing complexity of large foundation models. You can distribute
498
+ training across multiple TPU devices for faster and more efficient processing.
499
+ * Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
500
+ solution for training large models compared to CPU-based infrastructure,
501
+ especially when considering the time and resources saved due to faster
502
+ training.
503
+ * These advantages are aligned with
504
+ [Google's commitments to operate sustainably][sustainability].
505
+
506
+ ### Software
507
+
508
+ Training was done using [JAX][jax] and [ML Pathways][ml-pathways].
509
+
510
+ JAX allows researchers to take advantage of the latest generation of hardware,
511
+ including TPUs, for faster and more efficient training of large models.
512
+
513
+ ML Pathways is Google's latest effort to build artificially intelligent systems
514
+ capable of generalizing across multiple tasks. This is specially suitable for
515
+ [foundation models][foundation-models], including large language models like
516
+ these ones.
517
+
518
+ Together, JAX and ML Pathways are used as described in the
519
+ [paper about the Gemini family of models][gemini-2-paper]; "the 'single
520
+ controller' programming model of Jax and Pathways allows a single Python
521
+ process to orchestrate the entire training run, dramatically simplifying the
522
+ development workflow."
523
+
524
+ ## Evaluation
525
+
526
+ Model evaluation metrics and results.
527
+
528
+ ### Benchmark Results
529
+
530
+ These models were evaluated against a large collection of different datasets and
531
+ metrics to cover different aspects of text generation:
532
+
533
+ | Benchmark | Metric | Gemma PT 9B | Gemma PT 27B |
534
+ | ------------------------------ | ------------- | ----------- | ------------ |
535
+ | [MMLU][mmlu] | 5-shot, top-1 | 71.3 | 75.2 |
536
+ | [HellaSwag][hellaswag] | 10-shot | 81.9 | 86.4 |
537
+ | [PIQA][piqa] | 0-shot | 81.7 | 83.2 |
538
+ | [SocialIQA][socialiqa] | 0-shot | 53.4 | 53.7 |
539
+ | [BoolQ][boolq] | 0-shot | 84.2 | 84.8 |
540
+ | [WinoGrande][winogrande] | partial score | 80.6 | 83.7 |
541
+ | [ARC-e][arc] | 0-shot | 88.0 | 88.6 |
542
+ | [ARC-c][arc] | 25-shot | 68.4 | 71.4 |
543
+ | [TriviaQA][triviaqa] | 5-shot | 76.6 | 83.7 |
544
+ | [Natural Questions][naturalq] | 5-shot | 29.2 | 34.5 |
545
+ | [HumanEval][humaneval] | pass@1 | 40.2 | 51.8 |
546
+ | [MBPP][mbpp] | 3-shot | 52.4 | 62.6 |
547
+ | [GSM8K][gsm8k] | 5-shot, maj@1 | 68.6 | 74.0 |
548
+ | [MATH][math] | 4-shot | 36.6 | 42.3 |
549
+ | [AGIEval][agieval] | 3-5-shot | 52.8 | 55.1 |
550
+ | [BIG-Bench][big-bench] | 3-shot, CoT | 68.2 | 74.9 |
551
+ | ------------------------------ | ------------- | ----------- | ------------ |
552
+
553
+ ## Ethics and Safety
554
+
555
+ Ethics and safety evaluation approach and results.
556
+
557
+ ### Evaluation Approach
558
+
559
+ Our evaluation methods include structured evaluations and internal red-teaming
560
+ testing of relevant content policies. Red-teaming was conducted by a number of
561
+ different teams, each with different goals and human evaluation metrics. These
562
+ models were evaluated against a number of different categories relevant to
563
+ ethics and safety, including:
564
+
565
+ * Text-to-Text Content Safety: Human evaluation on prompts covering safety
566
+ policies including child sexual abuse and exploitation, harassment, violence
567
+ and gore, and hate speech.
568
+ * Text-to-Text Representational Harms: Benchmark against relevant academic
569
+ datasets such as [WinoBias][winobias] and [BBQ Dataset][bbq].
570
+ * Memorization: Automated evaluation of memorization of training data, including
571
+ the risk of personally identifiable information exposure.
572
+ * Large-scale harm: Tests for "dangerous capabilities," such as chemical,
573
+ biological, radiological, and nuclear (CBRN) risks.
574
+
575
+ ### Evaluation Results
576
+
577
+ The results of ethics and safety evaluations are within acceptable thresholds
578
+ for meeting [internal policies][safety-policies] for categories such as child
579
+ safety, content safety, representational harms, memorization, large-scale harms.
580
+ On top of robust internal evaluations, the results of well-known safety
581
+ benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
582
+ are shown here.
583
+
584
+ #### Gemma 2.0
585
+
586
+ | Benchmark | Metric | Gemma 2 IT 9B | Gemma 2 IT 27B |
587
+ | ------------------------ | ------------- | --------------- | ---------------- |
588
+ | [RealToxicity][realtox] | average | 8.25 | 8.84 |
589
+ | [CrowS-Pairs][crows] | top-1 | 37.47 | 36.67 |
590
+ | [BBQ Ambig][bbq] | 1-shot, top-1 | 88.58 | 85.99 |
591
+ | [BBQ Disambig][bbq] | top-1 | 82.67 | 86.94 |
592
+ | [Winogender][winogender] | top-1 | 79.17 | 77.22 |
593
+ | [TruthfulQA][truthfulqa] | | 50.27 | 51.60 |
594
+ | [Winobias 1_2][winobias] | | 78.09 | 81.94 |
595
+ | [Winobias 2_2][winobias] | | 95.32 | 97.22 |
596
+ | [Toxigen][toxigen] | | 39.30 | 38.42 |
597
+ | ------------------------ | ------------- | --------------- | ---------------- |
598
+
599
+ ## Usage and Limitations
600
+
601
+ These models have certain limitations that users should be aware of.
602
+
603
+ ### Intended Usage
604
+
605
+ Open Large Language Models (LLMs) have a wide range of applications across
606
+ various industries and domains. The following list of potential uses is not
607
+ comprehensive. The purpose of this list is to provide contextual information
608
+ about the possible use-cases that the model creators considered as part of model
609
+ training and development.
610
+
611
+ * Content Creation and Communication
612
+ * Text Generation: These models can be used to generate creative text formats
613
+ such as poems, scripts, code, marketing copy, and email drafts.
614
+ * Chatbots and Conversational AI: Power conversational interfaces for customer
615
+ service, virtual assistants, or interactive applications.
616
+ * Text Summarization: Generate concise summaries of a text corpus, research
617
+ papers, or reports.
618
+ * Research and Education
619
+ * Natural Language Processing (NLP) Research: These models can serve as a
620
+ foundation for researchers to experiment with NLP techniques, develop
621
+ algorithms, and contribute to the advancement of the field.
622
+ * Language Learning Tools: Support interactive language learning experiences,
623
+ aiding in grammar correction or providing writing practice.
624
+ * Knowledge Exploration: Assist researchers in exploring large bodies of text
625
+ by generating summaries or answering questions about specific topics.
626
+
627
+ ### Limitations
628
+
629
+ * Training Data
630
+ * The quality and diversity of the training data significantly influence the
631
+ model's capabilities. Biases or gaps in the training data can lead to
632
+ limitations in the model's responses.
633
+ * The scope of the training dataset determines the subject areas the model can
634
+ handle effectively.
635
+ * Context and Task Complexity
636
+ * LLMs are better at tasks that can be framed with clear prompts and
637
+ instructions. Open-ended or highly complex tasks might be challenging.
638
+ * A model's performance can be influenced by the amount of context provided
639
+ (longer context generally leads to better outputs, up to a certain point).
640
+ * Language Ambiguity and Nuance
641
+ * Natural language is inherently complex. LLMs might struggle to grasp subtle
642
+ nuances, sarcasm, or figurative language.
643
+ * Factual Accuracy
644
+ * LLMs generate responses based on information they learned from their
645
+ training datasets, but they are not knowledge bases. They may generate
646
+ incorrect or outdated factual statements.
647
+ * Common Sense
648
+ * LLMs rely on statistical patterns in language. They might lack the ability
649
+ to apply common sense reasoning in certain situations.
650
+
651
+ ### Ethical Considerations and Risks
652
+
653
+ The development of large language models (LLMs) raises several ethical concerns.
654
+ In creating an open model, we have carefully considered the following:
655
+
656
+ * Bias and Fairness
657
+ * LLMs trained on large-scale, real-world text data can reflect socio-cultural
658
+ biases embedded in the training material. These models underwent careful
659
+ scrutiny, input data pre-processing described and posterior evaluations
660
+ reported in this card.
661
+ * Misinformation and Misuse
662
+ * LLMs can be misused to generate text that is false, misleading, or harmful.
663
+ * Guidelines are provided for responsible use with the model, see the
664
+ [Responsible Generative AI Toolkit][rai-toolkit].
665
+ * Transparency and Accountability:
666
+ * This model card summarizes details on the models' architecture,
667
+ capabilities, limitations, and evaluation processes.
668
+ * A responsibly developed open model offers the opportunity to share
669
+ innovation by making LLM technology accessible to developers and researchers
670
+ across the AI ecosystem.
671
+
672
+ Risks identified and mitigations:
673
+
674
+ * Perpetuation of biases: It's encouraged to perform continuous monitoring
675
+ (using evaluation metrics, human review) and the exploration of de-biasing
676
+ techniques during model training, fine-tuning, and other use cases.
677
+ * Generation of harmful content: Mechanisms and guidelines for content safety
678
+ are essential. Developers are encouraged to exercise caution and implement
679
+ appropriate content safety safeguards based on their specific product policies
680
+ and application use cases.
681
+ * Misuse for malicious purposes: Technical limitations and developer and
682
+ end-user education can help mitigate against malicious applications of LLMs.
683
+ Educational resources and reporting mechanisms for users to flag misuse are
684
+ provided. Prohibited uses of Gemma models are outlined in the
685
+ [Gemma Prohibited Use Policy][prohibited-use].
686
+ * Privacy violations: Models were trained on data filtered for removal of PII
687
+ (Personally Identifiable Information). Developers are encouraged to adhere to
688
+ privacy regulations with privacy-preserving techniques.
689
+
690
+ ### Benefits
691
+
692
+ At the time of release, this family of models provides high-performance open
693
+ large language model implementations designed from the ground up for Responsible
694
+ AI development compared to similarly sized models.
695
+
696
+ Using the benchmark evaluation metrics described in this document, these models
697
+ have shown to provide superior performance to other, comparably-sized open model
698
+ alternatives.
699
+
700
+ [rai-toolkit]: https://ai.google.dev/responsible
701
+ [kaggle-gemma]: https://www.kaggle.com/models/google/gemma-2
702
+ [terms]: https://ai.google.dev/gemma/terms
703
+ [vertex-mg-gemma]: https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/335
704
+ [sensitive-info]: https://cloud.google.com/dlp/docs/high-sensitivity-infotypes-reference
705
+ [safety-policies]: https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11
706
+ [prohibited-use]: https://ai.google.dev/gemma/prohibited_use_policy
707
+ [tpu]: https://cloud.google.com/tpu/docs/intro-to-tpu
708
+ [sustainability]: https://sustainability.google/operating-sustainably/
709
+ [jax]: https://github.com/google/jax
710
+ [ml-pathways]: https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/
711
+ [sustainability]: https://sustainability.google/operating-sustainably/
712
+ [foundation-models]: https://ai.google/discover/foundation-models/
713
+ [gemini-2-paper]: https://goo.gle/gemma2report
714
+ [mmlu]: https://arxiv.org/abs/2009.03300
715
+ [hellaswag]: https://arxiv.org/abs/1905.07830
716
+ [piqa]: https://arxiv.org/abs/1911.11641
717
+ [socialiqa]: https://arxiv.org/abs/1904.09728
718
+ [boolq]: https://arxiv.org/abs/1905.10044
719
+ [winogrande]: https://arxiv.org/abs/1907.10641
720
+ [commonsenseqa]: https://arxiv.org/abs/1811.00937
721
+ [openbookqa]: https://arxiv.org/abs/1809.02789
722
+ [arc]: https://arxiv.org/abs/1911.01547
723
+ [triviaqa]: https://arxiv.org/abs/1705.03551
724
+ [naturalq]: https://github.com/google-research-datasets/natural-questions
725
+ [humaneval]: https://arxiv.org/abs/2107.03374
726
+ [mbpp]: https://arxiv.org/abs/2108.07732
727
+ [gsm8k]: https://arxiv.org/abs/2110.14168
728
+ [realtox]: https://arxiv.org/abs/2009.11462
729
+ [bold]: https://arxiv.org/abs/2101.11718
730
+ [crows]: https://aclanthology.org/2020.emnlp-main.154/
731
+ [bbq]: https://arxiv.org/abs/2110.08193v2
732
+ [winogender]: https://arxiv.org/abs/1804.09301
733
+ [truthfulqa]: https://arxiv.org/abs/2109.07958
734
+ [winobias]: https://arxiv.org/abs/1804.06876
735
+ [math]: https://arxiv.org/abs/2103.03874
736
+ [agieval]: https://arxiv.org/abs/2304.06364
737
+ [big-bench]: https://arxiv.org/abs/2206.04615
738
+ [toxigen]: https://arxiv.org/abs/2203.09509