dangvansam commited on
Commit
0a4e6ee
·
verified ·
1 Parent(s): a522955

Update README.md

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