Guillermo Alfaro commited on
Commit
80be61a
·
1 Parent(s): 196e37f

remove verbose

Browse files
Files changed (1) hide show
  1. README.md +0 -522
README.md DELETED
@@ -1,522 +0,0 @@
1
- ---
2
- license: gemma
3
- library_name: transformers
4
- pipeline_tag: text-generation
5
- extra_gated_heading: Access Gemma on Hugging Face
6
- extra_gated_prompt: >-
7
- To access Gemma on Hugging Face, you’re required to review and agree to
8
- Google’s usage license. To do this, please ensure you’re logged in to Hugging
9
- Face and click below. Requests are processed immediately.
10
- extra_gated_button_content: Acknowledge license
11
- tags:
12
- - conversational
13
- ---
14
-
15
-
16
- # Gemma 2 model card
17
-
18
- **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
19
-
20
- **Resources and Technical Documentation**:
21
-
22
- * [Responsible Generative AI Toolkit][rai-toolkit]
23
- * [Gemma on Kaggle][kaggle-gemma]
24
- * [Gemma on Vertex Model Garden][vertex-mg-gemma]
25
-
26
- **Terms of Use**: [Terms](https://www.kaggle.com/models/google/gemma/license/consent/verify/huggingface?returnModelRepoId=google/gemma-2-9b-it)
27
-
28
- **Authors**: Google
29
-
30
- ## Model Information
31
-
32
- Summary description and brief definition of inputs and outputs.
33
-
34
- ### Description
35
-
36
- Gemma is a family of lightweight, state-of-the-art open models from Google,
37
- built from the same research and technology used to create the Gemini models.
38
- They are text-to-text, decoder-only large language models, available in English,
39
- with open weights for both pre-trained variants and instruction-tuned variants.
40
- Gemma models are well-suited for a variety of text generation tasks, including
41
- question answering, summarization, and reasoning. Their relatively small size
42
- makes it possible to deploy them in environments with limited resources such as
43
- a laptop, desktop or your own cloud infrastructure, democratizing access to
44
- state of the art AI models and helping foster innovation for everyone.
45
-
46
- ### Usage
47
-
48
- 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.
49
-
50
-
51
- #### Running the model on a single / multi GPU
52
-
53
-
54
- ```python
55
- # pip install accelerate
56
- from transformers import AutoTokenizer, AutoModelForCausalLM
57
- import torch
58
-
59
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
60
- model = AutoModelForCausalLM.from_pretrained(
61
- "google/gemma-2-9b-it",
62
- device_map="auto",
63
- torch_dtype=torch.bfloat16
64
- )
65
-
66
- input_text = "Write me a poem about Machine Learning."
67
- input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
68
-
69
- outputs = model.generate(**input_ids)
70
- print(tokenizer.decode(outputs[0]))
71
- ```
72
-
73
- <a name="precisions"></a>
74
- #### Running the model on a GPU using different precisions
75
-
76
- The native weights of this model were exported in `bfloat16` precision.
77
-
78
- 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.
79
-
80
- * _Upcasting to `torch.float32`_
81
-
82
- ```python
83
- # pip install accelerate
84
- from transformers import AutoTokenizer, AutoModelForCausalLM
85
-
86
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
87
- model = AutoModelForCausalLM.from_pretrained(
88
- "google/gemma-2-9b-it",
89
- device_map="auto")
90
-
91
- input_text = "Write me a poem about Machine Learning."
92
- input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
93
-
94
- outputs = model.generate(**input_ids)
95
- print(tokenizer.decode(outputs[0]))
96
- ```
97
-
98
- #### Quantized Versions through `bitsandbytes`
99
-
100
- * _Using 8-bit precision (int8)_
101
-
102
- ```python
103
- # pip install bitsandbytes accelerate
104
- from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
105
-
106
- quantization_config = BitsAndBytesConfig(load_in_8bit=True)
107
-
108
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
109
- model = AutoModelForCausalLM.from_pretrained(
110
- "google/gemma-2-9b-it",
111
- quantization_config=quantization_config)
112
-
113
- input_text = "Write me a poem about Machine Learning."
114
- input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
115
-
116
- outputs = model.generate(**input_ids)
117
- print(tokenizer.decode(outputs[0]))
118
- ```
119
-
120
- * _Using 4-bit precision_
121
-
122
- ```python
123
- # pip install bitsandbytes accelerate
124
- from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
125
-
126
- quantization_config = BitsAndBytesConfig(load_in_4bit=True)
127
-
128
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
129
- model = AutoModelForCausalLM.from_pretrained(
130
- "google/gemma-2-9b-it",
131
- quantization_config=quantization_config)
132
-
133
- input_text = "Write me a poem about Machine Learning."
134
- input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
135
-
136
- outputs = model.generate(**input_ids)
137
- print(tokenizer.decode(outputs[0]))
138
- ```
139
-
140
-
141
- #### Other optimizations
142
-
143
- * _Flash Attention 2_
144
-
145
- First make sure to install `flash-attn` in your environment `pip install flash-attn`
146
-
147
- ```diff
148
- model = AutoModelForCausalLM.from_pretrained(
149
- model_id,
150
- torch_dtype=torch.float16,
151
- + attn_implementation="flash_attention_2"
152
- ).to(0)
153
- ```
154
-
155
- ### Chat Template
156
-
157
- The instruction-tuned models use a chat template that must be adhered to for conversational use.
158
- The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
159
-
160
- Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
161
-
162
- ```py
163
- from transformers import AutoTokenizer, AutoModelForCausalLM
164
- import transformers
165
- import torch
166
-
167
- model_id = "google/gemma-2-9b-it"
168
- dtype = torch.bfloat16
169
-
170
- tokenizer = AutoTokenizer.from_pretrained(model_id)
171
- model = AutoModelForCausalLM.from_pretrained(
172
- model_id,
173
- device_map="cuda",
174
- torch_dtype=dtype,)
175
-
176
- chat = [
177
- { "role": "user", "content": "Write a hello world program" },
178
- ]
179
- prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
180
- ```
181
-
182
- At this point, the prompt contains the following text:
183
-
184
- ```
185
- <bos><start_of_turn>user
186
- Write a hello world program<end_of_turn>
187
- <start_of_turn>model
188
- ```
189
-
190
- As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
191
- (either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
192
- the `<end_of_turn>` token.
193
-
194
- You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
195
- chat template.
196
-
197
- After the prompt is ready, generation can be performed like this:
198
-
199
- ```py
200
- inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
201
- outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
202
- print(tokenizer.decode(outputs[0]))
203
- ```
204
-
205
- ### Inputs and outputs
206
-
207
- * **Input:** Text string, such as a question, a prompt, or a document to be
208
- summarized.
209
- * **Output:** Generated English-language text in response to the input, such
210
- as an answer to a question, or a summary of a document.
211
-
212
- ### Citation
213
-
214
- ```none
215
- @article{gemma_2024,
216
- title={Gemma},
217
- url={https://www.kaggle.com/m/3301},
218
- DOI={10.34740/KAGGLE/M/3301},
219
- publisher={Kaggle},
220
- author={Gemma Team},
221
- year={2024}
222
- }
223
- ```
224
-
225
- ## Model Data
226
-
227
- Data used for model training and how the data was processed.
228
-
229
- ### Training Dataset
230
-
231
- 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.
232
- Here are the key components:
233
-
234
- * Web Documents: A diverse collection of web text ensures the model is exposed
235
- to a broad range of linguistic styles, topics, and vocabulary. Primarily
236
- English-language content.
237
- * Code: Exposing the model to code helps it to learn the syntax and patterns of
238
- programming languages, which improves its ability to generate code or
239
- understand code-related questions.
240
- * Mathematics: Training on mathematical text helps the model learn logical
241
- reasoning, symbolic representation, and to address mathematical queries.
242
-
243
- The combination of these diverse data sources is crucial for training a powerful
244
- language model that can handle a wide variety of different tasks and text
245
- formats.
246
-
247
- ### Data Preprocessing
248
-
249
- Here are the key data cleaning and filtering methods applied to the training
250
- data:
251
-
252
- * CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
253
- applied at multiple stages in the data preparation process to ensure the
254
- exclusion of harmful and illegal content.
255
- * Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
256
- reliable, automated techniques were used to filter out certain personal
257
- information and other sensitive data from training sets.
258
- * Additional methods: Filtering based on content quality and safety in line with
259
- [our policies][safety-policies].
260
-
261
- ## Implementation Information
262
-
263
- Details about the model internals.
264
-
265
- ### Hardware
266
-
267
- Gemma was trained using the latest generation of
268
- [Tensor Processing Unit (TPU)][tpu] hardware (TPUv5p).
269
-
270
- Training large language models requires significant computational power. TPUs,
271
- designed specifically for matrix operations common in machine learning, offer
272
- several advantages in this domain:
273
-
274
- * Performance: TPUs are specifically designed to handle the massive computations
275
- involved in training LLMs. They can speed up training considerably compared to
276
- CPUs.
277
- * Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
278
- for the handling of large models and batch sizes during training. This can
279
- lead to better model quality.
280
- * Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
281
- handling the growing complexity of large foundation models. You can distribute
282
- training across multiple TPU devices for faster and more efficient processing.
283
- * Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
284
- solution for training large models compared to CPU-based infrastructure,
285
- especially when considering the time and resources saved due to faster
286
- training.
287
- * These advantages are aligned with
288
- [Google's commitments to operate sustainably][sustainability].
289
-
290
- ### Software
291
-
292
- Training was done using [JAX][jax] and [ML Pathways][ml-pathways].
293
-
294
- JAX allows researchers to take advantage of the latest generation of hardware,
295
- including TPUs, for faster and more efficient training of large models.
296
-
297
- ML Pathways is Google's latest effort to build artificially intelligent systems
298
- capable of generalizing across multiple tasks. This is specially suitable for
299
- [foundation models][foundation-models], including large language models like
300
- these ones.
301
-
302
- Together, JAX and ML Pathways are used as described in the
303
- [paper about the Gemini family of models][gemini-2-paper]; "the 'single
304
- controller' programming model of Jax and Pathways allows a single Python
305
- process to orchestrate the entire training run, dramatically simplifying the
306
- development workflow."
307
-
308
- ## Evaluation
309
-
310
- Model evaluation metrics and results.
311
-
312
- ### Benchmark Results
313
-
314
- These models were evaluated against a large collection of different datasets and
315
- metrics to cover different aspects of text generation:
316
-
317
- | Benchmark | Metric | Gemma PT 9B | Gemma PT 27B |
318
- | ------------------------------ | ------------- | ----------- | ------------ |
319
- | [MMLU][mmlu] | 5-shot, top-1 | 71.3 | 75.2 |
320
- | [HellaSwag][hellaswag] | 10-shot | 81.9 | 86.4 |
321
- | [PIQA][piqa] | 0-shot | 81.7 | 83.2 |
322
- | [SocialIQA][socialiqa] | 0-shot | 53.4 | 53.7 |
323
- | [BoolQ][boolq] | 0-shot | 84.2 | 84.8 |
324
- | [WinoGrande][winogrande] | partial score | 80.6 | 83.7 |
325
- | [ARC-e][arc] | 0-shot | 88.0 | 88.6 |
326
- | [ARC-c][arc] | 25-shot | 68.4 | 71.4 |
327
- | [TriviaQA][triviaqa] | 5-shot | 76.6 | 83.7 |
328
- | [Natural Questions][naturalq] | 5-shot | 29.2 | 34.5 |
329
- | [HumanEval][humaneval] | pass@1 | 40.2 | 51.8 |
330
- | [MBPP][mbpp] | 3-shot | 52.4 | 62.6 |
331
- | [GSM8K][gsm8k] | 5-shot, maj@1 | 68.6 | 74.0 |
332
- | [MATH][math] | 4-shot | 36.6 | 42.3 |
333
- | [AGIEval][agieval] | 3-5-shot | 52.8 | 55.1 |
334
- | [BIG-Bench][big-bench] | 3-shot, CoT | 68.2 | 74.9 |
335
- | ------------------------------ | ------------- | ----------- | ------------ |
336
-
337
- ## Ethics and Safety
338
-
339
- Ethics and safety evaluation approach and results.
340
-
341
- ### Evaluation Approach
342
-
343
- Our evaluation methods include structured evaluations and internal red-teaming
344
- testing of relevant content policies. Red-teaming was conducted by a number of
345
- different teams, each with different goals and human evaluation metrics. These
346
- models were evaluated against a number of different categories relevant to
347
- ethics and safety, including:
348
-
349
- * Text-to-Text Content Safety: Human evaluation on prompts covering safety
350
- policies including child sexual abuse and exploitation, harassment, violence
351
- and gore, and hate speech.
352
- * Text-to-Text Representational Harms: Benchmark against relevant academic
353
- datasets such as [WinoBias][winobias] and [BBQ Dataset][bbq].
354
- * Memorization: Automated evaluation of memorization of training data, including
355
- the risk of personally identifiable information exposure.
356
- * Large-scale harm: Tests for "dangerous capabilities," such as chemical,
357
- biological, radiological, and nuclear (CBRN) risks.
358
-
359
- ### Evaluation Results
360
-
361
- The results of ethics and safety evaluations are within acceptable thresholds
362
- for meeting [internal policies][safety-policies] for categories such as child
363
- safety, content safety, representational harms, memorization, large-scale harms.
364
- On top of robust internal evaluations, the results of well-known safety
365
- benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
366
- are shown here.
367
-
368
- #### Gemma 2.0
369
-
370
- | Benchmark | Metric | Gemma 2 IT 9B | Gemma 2 IT 27B |
371
- | ------------------------ | ------------- | --------------- | ---------------- |
372
- | [RealToxicity][realtox] | average | 8.25 | 8.84 |
373
- | [CrowS-Pairs][crows] | top-1 | 37.47 | 36.67 |
374
- | [BBQ Ambig][bbq] | 1-shot, top-1 | 88.58 | 85.99 |
375
- | [BBQ Disambig][bbq] | top-1 | 82.67 | 86.94 |
376
- | [Winogender][winogender] | top-1 | 79.17 | 77.22 |
377
- | [TruthfulQA][truthfulqa] | | 50.27 | 51.60 |
378
- | [Winobias 1_2][winobias] | | 78.09 | 81.94 |
379
- | [Winobias 2_2][winobias] | | 95.32 | 97.22 |
380
- | [Toxigen][toxigen] | | 39.30 | 38.42 |
381
- | ------------------------ | ------------- | --------------- | ---------------- |
382
-
383
- ## Usage and Limitations
384
-
385
- These models have certain limitations that users should be aware of.
386
-
387
- ### Intended Usage
388
-
389
- Open Large Language Models (LLMs) have a wide range of applications across
390
- various industries and domains. The following list of potential uses is not
391
- comprehensive. The purpose of this list is to provide contextual information
392
- about the possible use-cases that the model creators considered as part of model
393
- training and development.
394
-
395
- * Content Creation and Communication
396
- * Text Generation: These models can be used to generate creative text formats
397
- such as poems, scripts, code, marketing copy, and email drafts.
398
- * Chatbots and Conversational AI: Power conversational interfaces for customer
399
- service, virtual assistants, or interactive applications.
400
- * Text Summarization: Generate concise summaries of a text corpus, research
401
- papers, or reports.
402
- * Research and Education
403
- * Natural Language Processing (NLP) Research: These models can serve as a
404
- foundation for researchers to experiment with NLP techniques, develop
405
- algorithms, and contribute to the advancement of the field.
406
- * Language Learning Tools: Support interactive language learning experiences,
407
- aiding in grammar correction or providing writing practice.
408
- * Knowledge Exploration: Assist researchers in exploring large bodies of text
409
- by generating summaries or answering questions about specific topics.
410
-
411
- ### Limitations
412
-
413
- * Training Data
414
- * The quality and diversity of the training data significantly influence the
415
- model's capabilities. Biases or gaps in the training data can lead to
416
- limitations in the model's responses.
417
- * The scope of the training dataset determines the subject areas the model can
418
- handle effectively.
419
- * Context and Task Complexity
420
- * LLMs are better at tasks that can be framed with clear prompts and
421
- instructions. Open-ended or highly complex tasks might be challenging.
422
- * A model's performance can be influenced by the amount of context provided
423
- (longer context generally leads to better outputs, up to a certain point).
424
- * Language Ambiguity and Nuance
425
- * Natural language is inherently complex. LLMs might struggle to grasp subtle
426
- nuances, sarcasm, or figurative language.
427
- * Factual Accuracy
428
- * LLMs generate responses based on information they learned from their
429
- training datasets, but they are not knowledge bases. They may generate
430
- incorrect or outdated factual statements.
431
- * Common Sense
432
- * LLMs rely on statistical patterns in language. They might lack the ability
433
- to apply common sense reasoning in certain situations.
434
-
435
- ### Ethical Considerations and Risks
436
-
437
- The development of large language models (LLMs) raises several ethical concerns.
438
- In creating an open model, we have carefully considered the following:
439
-
440
- * Bias and Fairness
441
- * LLMs trained on large-scale, real-world text data can reflect socio-cultural
442
- biases embedded in the training material. These models underwent careful
443
- scrutiny, input data pre-processing described and posterior evaluations
444
- reported in this card.
445
- * Misinformation and Misuse
446
- * LLMs can be misused to generate text that is false, misleading, or harmful.
447
- * Guidelines are provided for responsible use with the model, see the
448
- [Responsible Generative AI Toolkit][rai-toolkit].
449
- * Transparency and Accountability:
450
- * This model card summarizes details on the models' architecture,
451
- capabilities, limitations, and evaluation processes.
452
- * A responsibly developed open model offers the opportunity to share
453
- innovation by making LLM technology accessible to developers and researchers
454
- across the AI ecosystem.
455
-
456
- Risks identified and mitigations:
457
-
458
- * Perpetuation of biases: It's encouraged to perform continuous monitoring
459
- (using evaluation metrics, human review) and the exploration of de-biasing
460
- techniques during model training, fine-tuning, and other use cases.
461
- * Generation of harmful content: Mechanisms and guidelines for content safety
462
- are essential. Developers are encouraged to exercise caution and implement
463
- appropriate content safety safeguards based on their specific product policies
464
- and application use cases.
465
- * Misuse for malicious purposes: Technical limitations and developer and
466
- end-user education can help mitigate against malicious applications of LLMs.
467
- Educational resources and reporting mechanisms for users to flag misuse are
468
- provided. Prohibited uses of Gemma models are outlined in the
469
- [Gemma Prohibited Use Policy][prohibited-use].
470
- * Privacy violations: Models were trained on data filtered for removal of PII
471
- (Personally Identifiable Information). Developers are encouraged to adhere to
472
- privacy regulations with privacy-preserving techniques.
473
-
474
- ### Benefits
475
-
476
- At the time of release, this family of models provides high-performance open
477
- large language model implementations designed from the ground up for Responsible
478
- AI development compared to similarly sized models.
479
-
480
- Using the benchmark evaluation metrics described in this document, these models
481
- have shown to provide superior performance to other, comparably-sized open model
482
- alternatives.
483
-
484
- [rai-toolkit]: https://ai.google.dev/responsible
485
- [kaggle-gemma]: https://www.kaggle.com/models/google/gemma-2
486
- [terms]: https://ai.google.dev/gemma/terms
487
- [vertex-mg-gemma]: https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/335
488
- [sensitive-info]: https://cloud.google.com/dlp/docs/high-sensitivity-infotypes-reference
489
- [safety-policies]: https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11
490
- [prohibited-use]: https://ai.google.dev/gemma/prohibited_use_policy
491
- [tpu]: https://cloud.google.com/tpu/docs/intro-to-tpu
492
- [sustainability]: https://sustainability.google/operating-sustainably/
493
- [jax]: https://github.com/google/jax
494
- [ml-pathways]: https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/
495
- [sustainability]: https://sustainability.google/operating-sustainably/
496
- [foundation-models]: https://ai.google/discover/foundation-models/
497
- [gemini-2-paper]: https://goo.gle/gemma2report
498
- [mmlu]: https://arxiv.org/abs/2009.03300
499
- [hellaswag]: https://arxiv.org/abs/1905.07830
500
- [piqa]: https://arxiv.org/abs/1911.11641
501
- [socialiqa]: https://arxiv.org/abs/1904.09728
502
- [boolq]: https://arxiv.org/abs/1905.10044
503
- [winogrande]: https://arxiv.org/abs/1907.10641
504
- [commonsenseqa]: https://arxiv.org/abs/1811.00937
505
- [openbookqa]: https://arxiv.org/abs/1809.02789
506
- [arc]: https://arxiv.org/abs/1911.01547
507
- [triviaqa]: https://arxiv.org/abs/1705.03551
508
- [naturalq]: https://github.com/google-research-datasets/natural-questions
509
- [humaneval]: https://arxiv.org/abs/2107.03374
510
- [mbpp]: https://arxiv.org/abs/2108.07732
511
- [gsm8k]: https://arxiv.org/abs/2110.14168
512
- [realtox]: https://arxiv.org/abs/2009.11462
513
- [bold]: https://arxiv.org/abs/2101.11718
514
- [crows]: https://aclanthology.org/2020.emnlp-main.154/
515
- [bbq]: https://arxiv.org/abs/2110.08193v2
516
- [winogender]: https://arxiv.org/abs/1804.09301
517
- [truthfulqa]: https://arxiv.org/abs/2109.07958
518
- [winobias]: https://arxiv.org/abs/1804.06876
519
- [math]: https://arxiv.org/abs/2103.03874
520
- [agieval]: https://arxiv.org/abs/2304.06364
521
- [big-bench]: https://arxiv.org/abs/2206.04615
522
- [toxigen]: https://arxiv.org/abs/2203.09509