rainjay commited on
Commit
c663ea8
1 Parent(s): cbb229a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +523 -102
README.md CHANGED
@@ -1,201 +1,622 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
 
 
 
 
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
 
 
 
 
 
 
 
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
 
 
57
 
58
- ## Bias, Risks, and Limitations
 
 
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
69
 
70
- ## How to Get Started with the Model
 
 
 
 
 
71
 
72
- Use the code below to get started with the model.
 
73
 
74
- [More Information Needed]
 
 
75
 
76
- ## Training Details
 
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
 
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
 
 
 
87
 
88
- #### Preprocessing [optional]
 
89
 
90
- [More Information Needed]
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
 
 
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
 
96
 
97
- #### Speeds, Sizes, Times [optional]
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
 
 
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
112
 
113
- [More Information Needed]
 
 
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
 
 
 
 
 
 
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
130
 
131
- #### Summary
132
 
 
 
133
 
 
 
 
 
 
 
134
 
135
- ## Model Examination [optional]
 
 
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
 
154
 
155
- ### Model Architecture and Objective
 
 
 
 
 
156
 
157
- [More Information Needed]
 
 
 
 
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
 
 
 
 
162
 
163
- #### Hardware
 
 
164
 
165
- [More Information Needed]
 
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
 
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
 
 
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
 
 
 
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
 
190
 
191
- [More Information Needed]
 
 
 
 
 
 
 
192
 
193
- ## Model Card Authors [optional]
 
 
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
 
198
 
199
- [More Information Needed]
 
 
 
 
 
 
 
200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: transformers
3
+ widget:
4
+ - messages:
5
+ - role: user
6
+ content: How does the brain work?
7
+ inference:
8
+ parameters:
9
+ max_new_tokens: 200
10
+ extra_gated_heading: Access Gemma on Hugging Face
11
+ extra_gated_prompt: >-
12
+ To access Gemma on Hugging Face, you’re required to review and agree to
13
+ Google’s usage license. To do this, please ensure you’re logged-in to Hugging
14
+ Face and click below. Requests are processed immediately.
15
+ extra_gated_button_content: Acknowledge license
16
+ license: gemma
17
  ---
18
 
19
+ # Fork from google/gemma-1.1-7b-it
20
 
21
+ ## 4-bit Quantization
22
+ ```python
23
+ nf4_config = BitsAndBytesConfig(load_in_4bit=True,
24
+ bnb_4bit_use_double_quant=True,
25
+ bnb_4bit_compute_dtype=torch.bfloat16,
26
+ bnb_4bit_quant_type="nf4")
27
+ ```
28
 
29
+ # Gemma Model Card
30
 
31
+ **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
32
 
33
+ This model card corresponds to the latest 7B instruct version of the Gemma model. Here you can find other models in the Gemma family:
34
 
35
+ | | Base | Instruct |
36
+ |----|----------------------------------------------------|----------------------------------------------------------------------|
37
+ | 2B | [gemma-2b](https://huggingface.co/google/gemma-2b) | [gemma-1.1-2b-it](https://huggingface.co/google/gemma-1.1-2b-it) |
38
+ | 7B | [gemma-7b](https://huggingface.co/google/gemma-7b) | [**gemma-1.1-7b-it**](https://huggingface.co/google/gemma-1.1-7b-it) |
39
 
40
+ **Release Notes**
41
 
42
+ This is Gemma 1.1 7B (IT), an update over the original instruction-tuned Gemma release.
43
 
44
+ Gemma 1.1 was trained using a novel RLHF method, leading to substantial gains on quality, coding capabilities, factuality, instruction following and multi-turn conversation quality. We also fixed a bug in multi-turn conversations, and made sure that model responses don't always start with `"Sure,"`.
 
 
 
 
 
 
45
 
46
+ We believe this release represents an improvement for most use cases, but we encourage users to test in their particular applications. The previous model [will continue to be available in the same repo](https://huggingface.co/google/gemma-7b-it). We appreciate the enthusiastic adoption of Gemma, and we continue to welcome all feedback from the community.
47
 
48
+ **Resources and Technical Documentation**:
49
 
50
+ * [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)
51
+ * [Gemma on Kaggle](https://www.kaggle.com/models/google/gemma)
52
+ * [Gemma on Vertex Model Garden](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/335)
53
 
54
+ **Terms of Use**: [Terms](https://www.kaggle.com/models/google/gemma/license/consent)
55
 
56
+ **Authors**: Google
57
 
58
+ ## Model Information
59
 
60
+ Summary description and brief definition of inputs and outputs.
61
 
62
+ ### Description
63
 
64
+ Gemma is a family of lightweight, state-of-the-art open models from Google,
65
+ built from the same research and technology used to create the Gemini models.
66
+ They are text-to-text, decoder-only large language models, available in English,
67
+ with open weights, pre-trained variants, and instruction-tuned variants. Gemma
68
+ models are well-suited for a variety of text generation tasks, including
69
+ question answering, summarization, and reasoning. Their relatively small size
70
+ makes it possible to deploy them in environments with limited resources such as
71
+ a laptop, desktop or your own cloud infrastructure, democratizing access to
72
+ state of the art AI models and helping foster innovation for everyone.
73
 
74
+ ### Usage
75
 
76
+ 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.
77
 
78
+ #### Running the model on a CPU
79
 
80
+ As explained below, we recommend `torch.bfloat16` as the default dtype. You can use [a different precision](#precisions) if necessary.
81
 
82
+ ```python
83
+ from transformers import AutoTokenizer, AutoModelForCausalLM
84
+ import torch
85
 
86
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
87
+ model = AutoModelForCausalLM.from_pretrained(
88
+ "google/gemma-1.1-7b-it",
89
+ torch_dtype=torch.bfloat16
90
+ )
91
 
92
+ input_text = "Write me a poem about Machine Learning."
93
+ input_ids = tokenizer(input_text, return_tensors="pt")
94
 
95
+ outputs = model.generate(**input_ids, max_new_tokens=50)
96
+ print(tokenizer.decode(outputs[0]))
97
+ ```
98
 
99
+ #### Running the model on a single / multi GPU
100
 
 
101
 
102
+ ```python
103
+ # pip install accelerate
104
+ from transformers import AutoTokenizer, AutoModelForCausalLM
105
+ import torch
106
 
107
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
108
+ model = AutoModelForCausalLM.from_pretrained(
109
+ "google/gemma-1.1-7b-it",
110
+ device_map="auto",
111
+ torch_dtype=torch.bfloat16
112
+ )
113
 
114
+ input_text = "Write me a poem about Machine Learning."
115
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
116
 
117
+ outputs = model.generate(**input_ids)
118
+ print(tokenizer.decode(outputs[0]))
119
+ ```
120
 
121
+ <a name="precisions"></a>
122
+ #### Running the model on a GPU using different precisions
123
 
124
+ 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.
125
 
126
+ 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.
127
 
128
+ * _Using `torch.float16`_
129
 
130
+ ```python
131
+ # pip install accelerate
132
+ from transformers import AutoTokenizer, AutoModelForCausalLM
133
+ import torch
134
 
135
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
136
+ model = AutoModelForCausalLM.from_pretrained(
137
+ "google/gemma-1.1-7b-it",
138
+ device_map="auto",
139
+ torch_dtype=torch.float16,
140
+ revision="float16",
141
+ )
142
 
143
+ input_text = "Write me a poem about Machine Learning."
144
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
145
 
146
+ outputs = model.generate(**input_ids)
147
+ print(tokenizer.decode(outputs[0]))
148
+ ```
149
 
150
+ * _Using `torch.bfloat16`_
151
 
152
+ ```python
153
+ # pip install accelerate
154
+ from transformers import AutoTokenizer, AutoModelForCausalLM
155
+ import torch
156
 
157
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it")
158
+ model = AutoModelForCausalLM.from_pretrained(
159
+ "google/gemma-1.1-7b-it",
160
+ device_map="auto",
161
+ torch_dtype=torch.bfloat16
162
+ )
163
 
164
+ input_text = "Write me a poem about Machine Learning."
165
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
166
 
167
+ outputs = model.generate(**input_ids)
168
+ print(tokenizer.decode(outputs[0]))
169
+ ```
170
 
171
+ * _Upcasting to `torch.float32`_
172
 
173
+ ```python
174
+ # pip install accelerate
175
+ from transformers import AutoTokenizer, AutoModelForCausalLM
176
+
177
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
178
+ model = AutoModelForCausalLM.from_pretrained(
179
+ "google/gemma-1.1-7b-it",
180
+ device_map="auto"
181
+ )
182
+
183
+ input_text = "Write me a poem about Machine Learning."
184
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
185
+
186
+ outputs = model.generate(**input_ids)
187
+ print(tokenizer.decode(outputs[0]))
188
+ ```
189
+
190
+ #### Quantized Versions through `bitsandbytes`
191
+
192
+ * _Using 8-bit precision (int8)_
193
+
194
+ ```python
195
+ # pip install bitsandbytes accelerate
196
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
197
+
198
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
199
+
200
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
201
+ model = AutoModelForCausalLM.from_pretrained(
202
+ "google/gemma-1.1-7b-it",
203
+ quantization_config=quantization_config
204
+ )
205
+
206
+ input_text = "Write me a poem about Machine Learning."
207
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
208
+
209
+ outputs = model.generate(**input_ids)
210
+ print(tokenizer.decode(outputs[0]))
211
+ ```
212
+
213
+ * _Using 4-bit precision_
214
 
215
+ ```python
216
+ # pip install bitsandbytes accelerate
217
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
218
 
219
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True)
220
 
221
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-7b-it")
222
+ model = AutoModelForCausalLM.from_pretrained(
223
+ "google/gemma-1.1-7b-it",
224
+ quantization_config=quantization_config
225
+ )
226
 
227
+ input_text = "Write me a poem about Machine Learning."
228
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
229
 
230
+ outputs = model.generate(**input_ids)
231
+ print(tokenizer.decode(outputs[0]))
232
+ ```
233
 
 
234
 
235
+ #### Other optimizations
236
 
237
+ * _Flash Attention 2_
238
 
239
+ First make sure to install `flash-attn` in your environment `pip install flash-attn`
240
 
241
+ ```diff
242
+ model = AutoModelForCausalLM.from_pretrained(
243
+ model_id,
244
+ torch_dtype=torch.float16,
245
+ + attn_implementation="flash_attention_2"
246
+ ).to(0)
247
+ ```
248
 
249
+ #### Running the model in JAX / Flax
250
 
251
+ Use the `flax` branch of the repository:
252
 
253
+ ```python
254
+ import jax.numpy as jnp
255
+ from transformers import AutoTokenizer, FlaxGemmaForCausalLM
256
 
257
+ model_id = "google/gemma-1.1-7b-it"
258
 
259
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
260
+ tokenizer.padding_side = "left"
261
 
262
+ model, params = FlaxGemmaForCausalLM.from_pretrained(
263
+ model_id,
264
+ dtype=jnp.bfloat16,
265
+ revision="flax",
266
+ _do_init=False,
267
+ )
268
 
269
+ inputs = tokenizer("Valencia and Málaga are", return_tensors="np", padding=True)
270
+ output = model.generate(**inputs, params=params, max_new_tokens=20, do_sample=False)
271
+ output_text = tokenizer.batch_decode(output.sequences, skip_special_tokens=True)
272
+ ```
273
 
274
+ [Check this notebook](https://colab.research.google.com/github/sanchit-gandhi/notebooks/blob/main/jax_gemma.ipynb) for a comprehensive walkthrough on how to parallelize JAX inference.
275
 
 
276
 
277
+ ### Chat Template
278
 
279
+ The instruction-tuned models use a chat template that must be adhered to for conversational use.
280
+ The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
281
 
282
+ Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
283
 
284
+ ```py
285
+ from transformers import AutoTokenizer, AutoModelForCausalLM
286
+ import transformers
287
+ import torch
 
288
 
289
+ model_id = "google/gemma-1.1-7b-it"
290
+ dtype = torch.bfloat16
291
 
292
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
293
+ model = AutoModelForCausalLM.from_pretrained(
294
+ model_id,
295
+ device_map="cuda",
296
+ torch_dtype=dtype,
297
+ )
298
 
299
+ chat = [
300
+ { "role": "user", "content": "Write a hello world program" },
301
+ ]
302
+ prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
303
+ ```
304
 
305
+ At this point, the prompt contains the following text:
306
 
307
+ ```
308
+ <bos><start_of_turn>user
309
+ Write a hello world program<end_of_turn>
310
+ <start_of_turn>model
311
+ ```
312
 
313
+ As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
314
+ (either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
315
+ the `<end_of_turn>` token.
316
 
317
+ You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
318
+ chat template.
319
 
320
+ After the prompt is ready, generation can be performed like this:
321
 
322
+ ```py
323
+ inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
324
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
325
+ ```
326
 
327
+ ### Fine-tuning
328
 
329
+ You can find some fine-tuning scripts under the [`examples/` directory](https://huggingface.co/google/gemma-7b/tree/main/examples) of [`google/gemma-7b`](https://huggingface.co/google/gemma-7b) repository. To adapt them to this model, simply change the model-id to `google/gemma-1.1-7b-it`.
330
 
331
+ We provide:
332
 
333
+ * A script to perform Supervised Fine-Tuning (SFT) on UltraChat dataset using QLoRA
334
+ * A script to perform SFT using FSDP on TPU devices
335
+ * A notebook that you can run on a free-tier Google Colab instance to perform SFT on the English quotes dataset
336
 
337
+ ### Inputs and outputs
338
 
339
+ * **Input:** Text string, such as a question, a prompt, or a document to be
340
+ summarized.
341
+ * **Output:** Generated English-language text in response to the input, such
342
+ as an answer to a question, or a summary of a document.
343
 
344
+ ## Model Data
345
 
346
+ Data used for model training and how the data was processed.
347
 
348
+ ### Training Dataset
349
 
350
+ These models were trained on a dataset of text data that includes a wide variety
351
+ of sources, totaling 6 trillion tokens. Here are the key components:
352
 
353
+ * Web Documents: A diverse collection of web text ensures the model is exposed
354
+ to a broad range of linguistic styles, topics, and vocabulary. Primarily
355
+ English-language content.
356
+ * Code: Exposing the model to code helps it to learn the syntax and patterns of
357
+ programming languages, which improves its ability to generate code or
358
+ understand code-related questions.
359
+ * Mathematics: Training on mathematical text helps the model learn logical
360
+ reasoning, symbolic representation, and to address mathematical queries.
361
 
362
+ The combination of these diverse data sources is crucial for training a powerful
363
+ language model that can handle a wide variety of different tasks and text
364
+ formats.
365
 
366
+ ### Data Preprocessing
367
 
368
+ Here are the key data cleaning and filtering methods applied to the training
369
+ data:
370
 
371
+ * CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
372
+ applied at multiple stages in the data preparation process to ensure the
373
+ exclusion of harmful and illegal content
374
+ * Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
375
+ reliable, automated techniques were used to filter out certain personal
376
+ information and other sensitive data from training sets.
377
+ * Additional methods: Filtering based on content quality and safely in line with
378
+ [our policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11).
379
 
380
+ ## Implementation Information
381
+
382
+ Details about the model internals.
383
+
384
+ ### Hardware
385
+
386
+ Gemma was trained using the latest generation of
387
+ [Tensor Processing Unit (TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv5e).
388
+
389
+ Training large language models requires significant computational power. TPUs,
390
+ designed specifically for matrix operations common in machine learning, offer
391
+ several advantages in this domain:
392
+
393
+ * Performance: TPUs are specifically designed to handle the massive computations
394
+ involved in training LLMs. They can speed up training considerably compared to
395
+ CPUs.
396
+ * Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
397
+ for the handling of large models and batch sizes during training. This can
398
+ lead to better model quality.
399
+ * Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
400
+ handling the growing complexity of large foundation models. You can distribute
401
+ training across multiple TPU devices for faster and more efficient processing.
402
+ * Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
403
+ solution for training large models compared to CPU-based infrastructure,
404
+ especially when considering the time and resources saved due to faster
405
+ training.
406
+ * These advantages are aligned with
407
+ [Google's commitments to operate sustainably](https://sustainability.google/operating-sustainably/).
408
+
409
+ ### Software
410
+
411
+ Training was done using [JAX](https://github.com/google/jax) and [ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/ml-pathways).
412
+
413
+ JAX allows researchers to take advantage of the latest generation of hardware,
414
+ including TPUs, for faster and more efficient training of large models.
415
+
416
+ ML Pathways is Google's latest effort to build artificially intelligent systems
417
+ capable of generalizing across multiple tasks. This is specially suitable for
418
+ [foundation models](https://ai.google/discover/foundation-models/), including large language models like
419
+ these ones.
420
+
421
+ Together, JAX and ML Pathways are used as described in the
422
+ [paper about the Gemini family of models](https://arxiv.org/abs/2312.11805); "the 'single
423
+ controller' programming model of Jax and Pathways allows a single Python
424
+ process to orchestrate the entire training run, dramatically simplifying the
425
+ development workflow."
426
+
427
+ ## Evaluation
428
 
429
+ Model evaluation metrics and results.
430
+
431
+ ### Benchmark Results
432
+
433
+ The pre-trained base models were evaluated against a large collection of different datasets and
434
+ metrics to cover different aspects of text generation:
435
+
436
+ | Benchmark | Metric | Gemma PT 2B | Gemma PT 7B |
437
+ | ------------------------------ | ------------- | ----------- | ----------- |
438
+ | [MMLU](https://arxiv.org/abs/2009.03300) | 5-shot, top-1 | 42.3 | 64.3 |
439
+ | [HellaSwag](https://arxiv.org/abs/1905.07830) | 0-shot | 71.4 | 81.2 |
440
+ | [PIQA](https://arxiv.org/abs/1911.11641) | 0-shot | 77.3 | 81.2 |
441
+ | [SocialIQA](https://arxiv.org/abs/1904.09728) | 0-shot | 49.7 | 51.8 |
442
+ | [BoolQ](https://arxiv.org/abs/1905.10044) | 0-shot | 69.4 | 83.2 |
443
+ | [WinoGrande](https://arxiv.org/abs/1907.10641) | partial score | 65.4 | 72.3 |
444
+ | [CommonsenseQA](https://arxiv.org/abs/1811.00937) | 7-shot | 65.3 | 71.3 |
445
+ | [OpenBookQA](https://arxiv.org/abs/1809.02789) | | 47.8 | 52.8 |
446
+ | [ARC-e](https://arxiv.org/abs/1911.01547) | | 73.2 | 81.5 |
447
+ | [ARC-c](https://arxiv.org/abs/1911.01547) | | 42.1 | 53.2 |
448
+ | [TriviaQA](https://arxiv.org/abs/1705.03551) | 5-shot | 53.2 | 63.4 |
449
+ | [Natural Questions](https://github.com/google-research-datasets/natural-questions) | 5-shot | 12.5 | 23.0 |
450
+ | [HumanEval](https://arxiv.org/abs/2107.03374) | pass@1 | 22.0 | 32.3 |
451
+ | [MBPP](https://arxiv.org/abs/2108.07732) | 3-shot | 29.2 | 44.4 |
452
+ | [GSM8K](https://arxiv.org/abs/2110.14168) | maj@1 | 17.7 | 46.4 |
453
+ | [MATH](https://arxiv.org/abs/2108.07732) | 4-shot | 11.8 | 24.3 |
454
+ | [AGIEval](https://arxiv.org/abs/2304.06364) | | 24.2 | 41.7 |
455
+ | [BIG-Bench](https://arxiv.org/abs/2206.04615) | | 35.2 | 55.1 |
456
+ | ------------------------------ | ------------- | ----------- | ----------- |
457
+ | **Average** | | **44.9** | **56.4** |
458
+
459
+ ## Ethics and Safety
460
+
461
+ Ethics and safety evaluation approach and results.
462
+
463
+ ### Evaluation Approach
464
+
465
+ Our evaluation methods include structured evaluations and internal red-teaming
466
+ testing of relevant content policies. Red-teaming was conducted by a number of
467
+ different teams, each with different goals and human evaluation metrics. These
468
+ models were evaluated against a number of different categories relevant to
469
+ ethics and safety, including:
470
+
471
+ * Text-to-Text Content Safety: Human evaluation on prompts covering safety
472
+ policies including child sexual abuse and exploitation, harassment, violence
473
+ and gore, and hate speech.
474
+ * Text-to-Text Representational Harms: Benchmark against relevant academic
475
+ datasets such as [WinoBias](https://arxiv.org/abs/1804.06876) and [BBQ Dataset](https://arxiv.org/abs/2110.08193v2).
476
+ * Memorization: Automated evaluation of memorization of training data, including
477
+ the risk of personally identifiable information exposure.
478
+ * Large-scale harm: Tests for "dangerous capabilities," such as chemical,
479
+ biological, radiological, and nuclear (CBRN) risks.
480
+
481
+ ### Evaluation Results
482
+
483
+ The results of ethics and safety evaluations are within acceptable thresholds
484
+ for meeting [internal policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11) for categories such as child
485
+ safety, content safety, representational harms, memorization, large-scale harms.
486
+ On top of robust internal evaluations, the results of well known safety
487
+ benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
488
+ are shown here.
489
+
490
+ #### Gemma 1.0
491
+
492
+ | Benchmark | Metric | Gemma 1.0 IT 2B | Gemma 1.0 IT 7B |
493
+ | ------------------------ | ------------- | --------------- | --------------- |
494
+ | [RealToxicity][realtox] | average | 6.86 | 7.90 |
495
+ | [BOLD][bold] | | 45.57 | 49.08 |
496
+ | [CrowS-Pairs][crows] | top-1 | 45.82 | 51.33 |
497
+ | [BBQ Ambig][bbq] | 1-shot, top-1 | 62.58 | 92.54 |
498
+ | [BBQ Disambig][bbq] | top-1 | 54.62 | 71.99 |
499
+ | [Winogender][winogender] | top-1 | 51.25 | 54.17 |
500
+ | [TruthfulQA][truthfulqa] | | 44.84 | 31.81 |
501
+ | [Winobias 1_2][winobias] | | 56.12 | 59.09 |
502
+ | [Winobias 2_2][winobias] | | 91.10 | 92.23 |
503
+ | [Toxigen][toxigen] | | 29.77 | 39.59 |
504
+ | ------------------------ | ------------- | --------------- | --------------- |
505
+
506
+ #### Gemma 1.1
507
+
508
+ | Benchmark | Metric | Gemma 1.1 IT 2B | Gemma 1.1 IT 7B |
509
+ | ------------------------ | ------------- | --------------- | --------------- |
510
+ | [RealToxicity][realtox] | average | 7.03 | 8.04 |
511
+ | [BOLD][bold] | | 47.76 | |
512
+ | [CrowS-Pairs][crows] | top-1 | 45.89 | 49.67 |
513
+ | [BBQ Ambig][bbq] | 1-shot, top-1 | 58.97 | 86.06 |
514
+ | [BBQ Disambig][bbq] | top-1 | 53.90 | 85.08 |
515
+ | [Winogender][winogender] | top-1 | 50.14 | 57.64 |
516
+ | [TruthfulQA][truthfulqa] | | 44.24 | 45.34 |
517
+ | [Winobias 1_2][winobias] | | 55.93 | 59.22 |
518
+ | [Winobias 2_2][winobias] | | 89.46 | 89.2 |
519
+ | [Toxigen][toxigen] | | 29.64 | 38.75 |
520
+ | ------------------------ | ------------- | --------------- | --------------- |
521
+
522
+
523
+ ## Usage and Limitations
524
+
525
+ These models have certain limitations that users should be aware of.
526
+
527
+ ### Intended Usage
528
+
529
+ Open Large Language Models (LLMs) have a wide range of applications across
530
+ various industries and domains. The following list of potential uses is not
531
+ comprehensive. The purpose of this list is to provide contextual information
532
+ about the possible use-cases that the model creators considered as part of model
533
+ training and development.
534
+
535
+ * Content Creation and Communication
536
+ * Text Generation: These models can be used to generate creative text formats
537
+ such as poems, scripts, code, marketing copy, and email drafts.
538
+ * Chatbots and Conversational AI: Power conversational interfaces for customer
539
+ service, virtual assistants, or interactive applications.
540
+ * Text Summarization: Generate concise summaries of a text corpus, research
541
+ papers, or reports.
542
+ * Research and Education
543
+ * Natural Language Processing (NLP) Research: These models can serve as a
544
+ foundation for researchers to experiment with NLP techniques, develop
545
+ algorithms, and contribute to the advancement of the field.
546
+ * Language Learning Tools: Support interactive language learning experiences,
547
+ aiding in grammar correction or providing writing practice.
548
+ * Knowledge Exploration: Assist researchers in exploring large bodies of text
549
+ by generating summaries or answering questions about specific topics.
550
+
551
+ ### Limitations
552
+
553
+ * Training Data
554
+ * The quality and diversity of the training data significantly influence the
555
+ model's capabilities. Biases or gaps in the training data can lead to
556
+ limitations in the model's responses.
557
+ * The scope of the training dataset determines the subject areas the model can
558
+ handle effectively.
559
+ * Context and Task Complexity
560
+ * LLMs are better at tasks that can be framed with clear prompts and
561
+ instructions. Open-ended or highly complex tasks might be challenging.
562
+ * A model's performance can be influenced by the amount of context provided
563
+ (longer context generally leads to better outputs, up to a certain point).
564
+ * Language Ambiguity and Nuance
565
+ * Natural language is inherently complex. LLMs might struggle to grasp subtle
566
+ nuances, sarcasm, or figurative language.
567
+ * Factual Accuracy
568
+ * LLMs generate responses based on information they learned from their
569
+ training datasets, but they are not knowledge bases. They may generate
570
+ incorrect or outdated factual statements.
571
+ * Common Sense
572
+ * LLMs rely on statistical patterns in language. They might lack the ability
573
+ to apply common sense reasoning in certain situations.
574
+
575
+ ### Ethical Considerations and Risks
576
+
577
+ The development of large language models (LLMs) raises several ethical concerns.
578
+ In creating an open model, we have carefully considered the following:
579
+
580
+ * Bias and Fairness
581
+ * LLMs trained on large-scale, real-world text data can reflect socio-cultural
582
+ biases embedded in the training material. These models underwent careful
583
+ scrutiny, input data pre-processing described and posterior evaluations
584
+ reported in this card.
585
+ * Misinformation and Misuse
586
+ * LLMs can be misused to generate text that is false, misleading, or harmful.
587
+ * Guidelines are provided for responsible use with the model, see the
588
+ [Responsible Generative AI Toolkit](http://ai.google.dev/gemma/responsible).
589
+ * Transparency and Accountability:
590
+ * This model card summarizes details on the models' architecture,
591
+ capabilities, limitations, and evaluation processes.
592
+ * A responsibly developed open model offers the opportunity to share
593
+ innovation by making LLM technology accessible to developers and researchers
594
+ across the AI ecosystem.
595
+
596
+ Risks identified and mitigations:
597
+
598
+ * Perpetuation of biases: It's encouraged to perform continuous monitoring
599
+ (using evaluation metrics, human review) and the exploration of de-biasing
600
+ techniques during model training, fine-tuning, and other use cases.
601
+ * Generation of harmful content: Mechanisms and guidelines for content safety
602
+ are essential. Developers are encouraged to exercise caution and implement
603
+ appropriate content safety safeguards based on their specific product policies
604
+ and application use cases.
605
+ * Misuse for malicious purposes: Technical limitations and developer and
606
+ end-user education can help mitigate against malicious applications of LLMs.
607
+ Educational resources and reporting mechanisms for users to flag misuse are
608
+ provided. Prohibited uses of Gemma models are outlined in the
609
+ [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy).
610
+ * Privacy violations: Models were trained on data filtered for removal of PII
611
+ (Personally Identifiable Information). Developers are encouraged to adhere to
612
+ privacy regulations with privacy-preserving techniques.
613
+
614
+ ### Benefits
615
+
616
+ At the time of release, this family of models provides high-performance open
617
+ large language model implementations designed from the ground up for Responsible
618
+ AI development compared to similarly sized models.
619
+
620
+ Using the benchmark evaluation metrics described in this document, these models
621
+ have shown to provide superior performance to other, comparably-sized open model
622
+ alternatives.