RichardErkhov commited on
Commit
38828e6
·
verified ·
1 Parent(s): d164de7

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +673 -0
README.md ADDED
@@ -0,0 +1,673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-27b-it - GGUF
11
+ - Model creator: https://huggingface.co/google/
12
+ - Original model: https://huggingface.co/google/gemma-2-27b-it/
13
+
14
+
15
+ | Name | Quant method | Size |
16
+ | ---- | ---- | ---- |
17
+ | [gemma-2-27b-it.Q2_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q2_K.gguf) | Q2_K | 9.73GB |
18
+ | [gemma-2-27b-it.IQ3_XS.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.IQ3_XS.gguf) | IQ3_XS | 10.76GB |
19
+ | [gemma-2-27b-it.IQ3_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.IQ3_S.gguf) | IQ3_S | 11.33GB |
20
+ | [gemma-2-27b-it.Q3_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q3_K_S.gguf) | Q3_K_S | 11.33GB |
21
+ | [gemma-2-27b-it.IQ3_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.IQ3_M.gguf) | IQ3_M | 11.6GB |
22
+ | [gemma-2-27b-it.Q3_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q3_K.gguf) | Q3_K | 12.5GB |
23
+ | [gemma-2-27b-it.Q3_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q3_K_M.gguf) | Q3_K_M | 12.5GB |
24
+ | [gemma-2-27b-it.Q3_K_L.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q3_K_L.gguf) | Q3_K_L | 13.52GB |
25
+ | [gemma-2-27b-it.IQ4_XS.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.IQ4_XS.gguf) | IQ4_XS | 13.92GB |
26
+ | [gemma-2-27b-it.Q4_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q4_0.gguf) | Q4_0 | 14.56GB |
27
+ | [gemma-2-27b-it.IQ4_NL.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.IQ4_NL.gguf) | IQ4_NL | 14.65GB |
28
+ | [gemma-2-27b-it.Q4_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q4_K_S.gguf) | Q4_K_S | 14.66GB |
29
+ | [gemma-2-27b-it.Q4_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q4_K.gguf) | Q4_K | 15.5GB |
30
+ | [gemma-2-27b-it.Q4_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q4_K_M.gguf) | Q4_K_M | 15.5GB |
31
+ | [gemma-2-27b-it.Q4_1.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q4_1.gguf) | Q4_1 | 16.07GB |
32
+ | [gemma-2-27b-it.Q5_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q5_0.gguf) | Q5_0 | 17.59GB |
33
+ | [gemma-2-27b-it.Q5_K_S.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q5_K_S.gguf) | Q5_K_S | 17.59GB |
34
+ | [gemma-2-27b-it.Q5_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q5_K.gguf) | Q5_K | 18.08GB |
35
+ | [gemma-2-27b-it.Q5_K_M.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q5_K_M.gguf) | Q5_K_M | 18.08GB |
36
+ | [gemma-2-27b-it.Q5_1.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q5_1.gguf) | Q5_1 | 19.1GB |
37
+ | [gemma-2-27b-it.Q6_K.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q6_K.gguf) | Q6_K | 20.81GB |
38
+ | [gemma-2-27b-it.Q8_0.gguf](https://huggingface.co/RichardErkhov/google_-_gemma-2-27b-it-gguf/blob/main/gemma-2-27b-it.Q8_0.gguf) | Q8_0 | 26.95GB |
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
+ base_model: google/gemma-2-27b
55
+ ---
56
+
57
+
58
+
59
+ # Gemma 2 model card
60
+
61
+ **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
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-gemma]
68
+
69
+ **Terms of Use**: [Terms](https://www.kaggle.com/models/google/gemma/license/consent/verify/huggingface?returnModelRepoId=google/gemma-2-27b-it)
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-27b-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-27b-it")
129
+ model = AutoModelForCausalLM.from_pretrained(
130
+ "google/gemma-2-27b-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-27b-it")
167
+ model = AutoModelForCausalLM.from_pretrained(
168
+ "google/gemma-2-27b-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 27b --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-27b-it")
203
+ model = AutoModelForCausalLM.from_pretrained(
204
+ "google/gemma-2-27b-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-27b-it")
228
+ model = AutoModelForCausalLM.from_pretrained(
229
+ "google/gemma-2-27b-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 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-27b-it")
265
+ model = Gemma2ForCausalLM.from_pretrained("google/gemma-2-27b-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-27b-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
+
325
+ chat = [
326
+ { "role": "user", "content": "Write a hello world program" },
327
+ ]
328
+ prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
329
+ ```
330
+
331
+ At this point, the prompt contains the following text:
332
+
333
+ ```
334
+ <bos><start_of_turn>user
335
+ Write a hello world program<end_of_turn>
336
+ <start_of_turn>model
337
+ ```
338
+
339
+ As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
340
+ (either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
341
+ the `<end_of_turn>` token.
342
+
343
+ You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
344
+ chat template.
345
+
346
+ After the prompt is ready, generation can be performed like this:
347
+
348
+ ```py
349
+ inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
350
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
351
+ print(tokenizer.decode(outputs[0]))
352
+ ```
353
+
354
+ ### Inputs and outputs
355
+
356
+ * **Input:** Text string, such as a question, a prompt, or a document to be
357
+ summarized.
358
+ * **Output:** Generated English-language text in response to the input, such
359
+ as an answer to a question, or a summary of a document.
360
+
361
+ ### Citation
362
+
363
+ ```none
364
+ @article{gemma_2024,
365
+ title={Gemma},
366
+ url={https://www.kaggle.com/m/3301},
367
+ DOI={10.34740/KAGGLE/M/3301},
368
+ publisher={Kaggle},
369
+ author={Gemma Team},
370
+ year={2024}
371
+ }
372
+ ```
373
+
374
+ ## Model Data
375
+
376
+ Data used for model training and how the data was processed.
377
+
378
+ ### Training Dataset
379
+
380
+ These models were trained on a dataset of text data that includes a wide variety of sources. The 27B model was trained with 13 trillion tokens and the 9B model was trained with 8 trillion tokens.
381
+ Here are the key components:
382
+
383
+ * Web Documents: A diverse collection of web text ensures the model is exposed
384
+ to a broad range of linguistic styles, topics, and vocabulary. Primarily
385
+ English-language content.
386
+ * Code: Exposing the model to code helps it to learn the syntax and patterns of
387
+ programming languages, which improves its ability to generate code or
388
+ understand code-related questions.
389
+ * Mathematics: Training on mathematical text helps the model learn logical
390
+ reasoning, symbolic representation, and to address mathematical queries.
391
+
392
+ The combination of these diverse data sources is crucial for training a powerful
393
+ language model that can handle a wide variety of different tasks and text
394
+ formats.
395
+
396
+ ### Data Preprocessing
397
+
398
+ Here are the key data cleaning and filtering methods applied to the training
399
+ data:
400
+
401
+ * CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
402
+ applied at multiple stages in the data preparation process to ensure the
403
+ exclusion of harmful and illegal content.
404
+ * Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
405
+ reliable, automated techniques were used to filter out certain personal
406
+ information and other sensitive data from training sets.
407
+ * Additional methods: Filtering based on content quality and safety in line with
408
+ [our policies][safety-policies].
409
+
410
+ ## Implementation Information
411
+
412
+ Details about the model internals.
413
+
414
+ ### Hardware
415
+
416
+ Gemma was trained using the latest generation of
417
+ [Tensor Processing Unit (TPU)][tpu] hardware (TPUv5p).
418
+
419
+ Training large language models requires significant computational power. TPUs,
420
+ designed specifically for matrix operations common in machine learning, offer
421
+ several advantages in this domain:
422
+
423
+ * Performance: TPUs are specifically designed to handle the massive computations
424
+ involved in training LLMs. They can speed up training considerably compared to
425
+ CPUs.
426
+ * Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
427
+ for the handling of large models and batch sizes during training. This can
428
+ lead to better model quality.
429
+ * Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
430
+ handling the growing complexity of large foundation models. You can distribute
431
+ training across multiple TPU devices for faster and more efficient processing.
432
+ * Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
433
+ solution for training large models compared to CPU-based infrastructure,
434
+ especially when considering the time and resources saved due to faster
435
+ training.
436
+ * These advantages are aligned with
437
+ [Google's commitments to operate sustainably][sustainability].
438
+
439
+ ### Software
440
+
441
+ Training was done using [JAX][jax] and [ML Pathways][ml-pathways].
442
+
443
+ JAX allows researchers to take advantage of the latest generation of hardware,
444
+ including TPUs, for faster and more efficient training of large models.
445
+
446
+ ML Pathways is Google's latest effort to build artificially intelligent systems
447
+ capable of generalizing across multiple tasks. This is specially suitable for
448
+ [foundation models][foundation-models], including large language models like
449
+ these ones.
450
+
451
+ Together, JAX and ML Pathways are used as described in the
452
+ [paper about the Gemini family of models][gemini-2-paper]; "the 'single
453
+ controller' programming model of Jax and Pathways allows a single Python
454
+ process to orchestrate the entire training run, dramatically simplifying the
455
+ development workflow."
456
+
457
+ ## Evaluation
458
+
459
+ Model evaluation metrics and results.
460
+
461
+ ### Benchmark Results
462
+
463
+ These models were evaluated against a large collection of different datasets and
464
+ metrics to cover different aspects of text generation:
465
+
466
+ | Benchmark | Metric | Gemma PT 9B | Gemma PT 27B |
467
+ | ------------------------------ | ------------- | ----------- | ------------ |
468
+ | [MMLU][mmlu] | 5-shot, top-1 | 71.3 | 75.2 |
469
+ | [HellaSwag][hellaswag] | 10-shot | 81.9 | 86.4 |
470
+ | [PIQA][piqa] | 0-shot | 81.7 | 83.2 |
471
+ | [SocialIQA][socialiqa] | 0-shot | 53.4 | 53.7 |
472
+ | [BoolQ][boolq] | 0-shot | 84.2 | 84.8 |
473
+ | [WinoGrande][winogrande] | partial score | 80.6 | 83.7 |
474
+ | [ARC-e][arc] | 0-shot | 88.0 | 88.6 |
475
+ | [ARC-c][arc] | 25-shot | 68.4 | 71.4 |
476
+ | [TriviaQA][triviaqa] | 5-shot | 76.6 | 83.7 |
477
+ | [Natural Questions][naturalq] | 5-shot | 29.2 | 34.5 |
478
+ | [HumanEval][humaneval] | pass@1 | 40.2 | 51.8 |
479
+ | [MBPP][mbpp] | 3-shot | 52.4 | 62.6 |
480
+ | [GSM8K][gsm8k] | 5-shot, maj@1 | 68.6 | 74.0 |
481
+ | [MATH][math] | 4-shot | 36.6 | 42.3 |
482
+ | [AGIEval][agieval] | 3-5-shot | 52.8 | 55.1 |
483
+ | [BIG-Bench][big-bench] | 3-shot, CoT | 68.2 | 74.9 |
484
+ | ------------------------------ | ------------- | ----------- | ------------ |
485
+
486
+ ## Ethics and Safety
487
+
488
+ Ethics and safety evaluation approach and results.
489
+
490
+ ### Evaluation Approach
491
+
492
+ Our evaluation methods include structured evaluations and internal red-teaming
493
+ testing of relevant content policies. Red-teaming was conducted by a number of
494
+ different teams, each with different goals and human evaluation metrics. These
495
+ models were evaluated against a number of different categories relevant to
496
+ ethics and safety, including:
497
+
498
+ * Text-to-Text Content Safety: Human evaluation on prompts covering safety
499
+ policies including child sexual abuse and exploitation, harassment, violence
500
+ and gore, and hate speech.
501
+ * Text-to-Text Representational Harms: Benchmark against relevant academic
502
+ datasets such as [WinoBias][winobias] and [BBQ Dataset][bbq].
503
+ * Memorization: Automated evaluation of memorization of training data, including
504
+ the risk of personally identifiable information exposure.
505
+ * Large-scale harm: Tests for "dangerous capabilities," such as chemical,
506
+ biological, radiological, and nuclear (CBRN) risks.
507
+
508
+ ### Evaluation Results
509
+
510
+ The results of ethics and safety evaluations are within acceptable thresholds
511
+ for meeting [internal policies][safety-policies] for categories such as child
512
+ safety, content safety, representational harms, memorization, large-scale harms.
513
+ On top of robust internal evaluations, the results of well-known safety
514
+ benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
515
+ are shown here.
516
+
517
+ #### Gemma 2.0
518
+
519
+ | Benchmark | Metric | Gemma 2 IT 9B | Gemma 2 IT 27B |
520
+ | ------------------------ | ------------- | --------------- | ---------------- |
521
+ | [RealToxicity][realtox] | average | 8.25 | 8.84 |
522
+ | [CrowS-Pairs][crows] | top-1 | 37.47 | 36.67 |
523
+ | [BBQ Ambig][bbq] | 1-shot, top-1 | 88.58 | 85.99 |
524
+ | [BBQ Disambig][bbq] | top-1 | 82.67 | 86.94 |
525
+ | [Winogender][winogender] | top-1 | 79.17 | 77.22 |
526
+ | [TruthfulQA][truthfulqa] | | 50.27 | 51.60 |
527
+ | [Winobias 1_2][winobias] | | 78.09 | 81.94 |
528
+ | [Winobias 2_2][winobias] | | 95.32 | 97.22 |
529
+ | [Toxigen][toxigen] | | 39.30 | 38.42 |
530
+ | ------------------------ | ------------- | --------------- | ---------------- |
531
+
532
+ ## Usage and Limitations
533
+
534
+ These models have certain limitations that users should be aware of.
535
+
536
+ ### Intended Usage
537
+
538
+ Open Large Language Models (LLMs) have a wide range of applications across
539
+ various industries and domains. The following list of potential uses is not
540
+ comprehensive. The purpose of this list is to provide contextual information
541
+ about the possible use-cases that the model creators considered as part of model
542
+ training and development.
543
+
544
+ * Content Creation and Communication
545
+ * Text Generation: These models can be used to generate creative text formats
546
+ such as poems, scripts, code, marketing copy, and email drafts.
547
+ * Chatbots and Conversational AI: Power conversational interfaces for customer
548
+ service, virtual assistants, or interactive applications.
549
+ * Text Summarization: Generate concise summaries of a text corpus, research
550
+ papers, or reports.
551
+ * Research and Education
552
+ * Natural Language Processing (NLP) Research: These models can serve as a
553
+ foundation for researchers to experiment with NLP techniques, develop
554
+ algorithms, and contribute to the advancement of the field.
555
+ * Language Learning Tools: Support interactive language learning experiences,
556
+ aiding in grammar correction or providing writing practice.
557
+ * Knowledge Exploration: Assist researchers in exploring large bodies of text
558
+ by generating summaries or answering questions about specific topics.
559
+
560
+ ### Limitations
561
+
562
+ * Training Data
563
+ * The quality and diversity of the training data significantly influence the
564
+ model's capabilities. Biases or gaps in the training data can lead to
565
+ limitations in the model's responses.
566
+ * The scope of the training dataset determines the subject areas the model can
567
+ handle effectively.
568
+ * Context and Task Complexity
569
+ * LLMs are better at tasks that can be framed with clear prompts and
570
+ instructions. Open-ended or highly complex tasks might be challenging.
571
+ * A model's performance can be influenced by the amount of context provided
572
+ (longer context generally leads to better outputs, up to a certain point).
573
+ * Language Ambiguity and Nuance
574
+ * Natural language is inherently complex. LLMs might struggle to grasp subtle
575
+ nuances, sarcasm, or figurative language.
576
+ * Factual Accuracy
577
+ * LLMs generate responses based on information they learned from their
578
+ training datasets, but they are not knowledge bases. They may generate
579
+ incorrect or outdated factual statements.
580
+ * Common Sense
581
+ * LLMs rely on statistical patterns in language. They might lack the ability
582
+ to apply common sense reasoning in certain situations.
583
+
584
+ ### Ethical Considerations and Risks
585
+
586
+ The development of large language models (LLMs) raises several ethical concerns.
587
+ In creating an open model, we have carefully considered the following:
588
+
589
+ * Bias and Fairness
590
+ * LLMs trained on large-scale, real-world text data can reflect socio-cultural
591
+ biases embedded in the training material. These models underwent careful
592
+ scrutiny, input data pre-processing described and posterior evaluations
593
+ reported in this card.
594
+ * Misinformation and Misuse
595
+ * LLMs can be misused to generate text that is false, misleading, or harmful.
596
+ * Guidelines are provided for responsible use with the model, see the
597
+ [Responsible Generative AI Toolkit][rai-toolkit].
598
+ * Transparency and Accountability:
599
+ * This model card summarizes details on the models' architecture,
600
+ capabilities, limitations, and evaluation processes.
601
+ * A responsibly developed open model offers the opportunity to share
602
+ innovation by making LLM technology accessible to developers and researchers
603
+ across the AI ecosystem.
604
+
605
+ Risks identified and mitigations:
606
+
607
+ * Perpetuation of biases: It's encouraged to perform continuous monitoring
608
+ (using evaluation metrics, human review) and the exploration of de-biasing
609
+ techniques during model training, fine-tuning, and other use cases.
610
+ * Generation of harmful content: Mechanisms and guidelines for content safety
611
+ are essential. Developers are encouraged to exercise caution and implement
612
+ appropriate content safety safeguards based on their specific product policies
613
+ and application use cases.
614
+ * Misuse for malicious purposes: Technical limitations and developer and
615
+ end-user education can help mitigate against malicious applications of LLMs.
616
+ Educational resources and reporting mechanisms for users to flag misuse are
617
+ provided. Prohibited uses of Gemma models are outlined in the
618
+ [Gemma Prohibited Use Policy][prohibited-use].
619
+ * Privacy violations: Models were trained on data filtered for removal of PII
620
+ (Personally Identifiable Information). Developers are encouraged to adhere to
621
+ privacy regulations with privacy-preserving techniques.
622
+
623
+ ### Benefits
624
+
625
+ At the time of release, this family of models provides high-performance open
626
+ large language model implementations designed from the ground up for Responsible
627
+ AI development compared to similarly sized models.
628
+
629
+ Using the benchmark evaluation metrics described in this document, these models
630
+ have shown to provide superior performance to other, comparably-sized open model
631
+ alternatives.
632
+
633
+ [rai-toolkit]: https://ai.google.dev/responsible
634
+ [kaggle-gemma]: https://www.kaggle.com/models/google/gemma-2
635
+ [terms]: https://ai.google.dev/gemma/terms
636
+ [vertex-mg-gemma]: https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/335
637
+ [sensitive-info]: https://cloud.google.com/dlp/docs/high-sensitivity-infotypes-reference
638
+ [safety-policies]: https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11
639
+ [prohibited-use]: https://ai.google.dev/gemma/prohibited_use_policy
640
+ [tpu]: https://cloud.google.com/tpu/docs/intro-to-tpu
641
+ [sustainability]: https://sustainability.google/operating-sustainably/
642
+ [jax]: https://github.com/google/jax
643
+ [ml-pathways]: https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/
644
+ [sustainability]: https://sustainability.google/operating-sustainably/
645
+ [foundation-models]: https://ai.google/discover/foundation-models/
646
+ [gemini-2-paper]: https://goo.gle/gemma2report
647
+ [mmlu]: https://arxiv.org/abs/2009.03300
648
+ [hellaswag]: https://arxiv.org/abs/1905.07830
649
+ [piqa]: https://arxiv.org/abs/1911.11641
650
+ [socialiqa]: https://arxiv.org/abs/1904.09728
651
+ [boolq]: https://arxiv.org/abs/1905.10044
652
+ [winogrande]: https://arxiv.org/abs/1907.10641
653
+ [commonsenseqa]: https://arxiv.org/abs/1811.00937
654
+ [openbookqa]: https://arxiv.org/abs/1809.02789
655
+ [arc]: https://arxiv.org/abs/1911.01547
656
+ [triviaqa]: https://arxiv.org/abs/1705.03551
657
+ [naturalq]: https://github.com/google-research-datasets/natural-questions
658
+ [humaneval]: https://arxiv.org/abs/2107.03374
659
+ [mbpp]: https://arxiv.org/abs/2108.07732
660
+ [gsm8k]: https://arxiv.org/abs/2110.14168
661
+ [realtox]: https://arxiv.org/abs/2009.11462
662
+ [bold]: https://arxiv.org/abs/2101.11718
663
+ [crows]: https://aclanthology.org/2020.emnlp-main.154/
664
+ [bbq]: https://arxiv.org/abs/2110.08193v2
665
+ [winogender]: https://arxiv.org/abs/1804.09301
666
+ [truthfulqa]: https://arxiv.org/abs/2109.07958
667
+ [winobias]: https://arxiv.org/abs/1804.06876
668
+ [math]: https://arxiv.org/abs/2103.03874
669
+ [agieval]: https://arxiv.org/abs/2304.06364
670
+ [big-bench]: https://arxiv.org/abs/2206.04615
671
+ [toxigen]: https://arxiv.org/abs/2203.09509
672
+
673
+