RichardErkhov commited on
Commit
c3378e8
1 Parent(s): bd9ed29

uploaded readme

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