alexmarques commited on
Commit
ce07504
·
verified ·
1 Parent(s): f4d7cbf

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +208 -0
README.md ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text-generation
3
+ tags:
4
+ - int8
5
+ - vllm
6
+ license: gemma
7
+ ---
8
+
9
+ # gemma-2-2b-it-quantized.w8a16
10
+
11
+ ## Model Overview
12
+ - **Model Architecture:** Gemma 2
13
+ - **Input:** Text
14
+ - **Output:** Text
15
+ - **Model Optimizations:**
16
+ - **Weight quantization:** INT8
17
+ - **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [gemma-2-2b](https://huggingface.co/google/gemma-2-2b), this is a pre-trained base model that can be used as is or specialized to specific domains.
18
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
19
+ - **Release Date:** 8/13/2024
20
+ - **Version:** 1.0
21
+ - **License(s):** [gemma](https://ai.google.dev/gemma/terms)
22
+ - **Model Developers:** Neural Magic
23
+
24
+ Quantized version of [gemma-2-2b](https://huggingface.co/google/gemma-2-2b).
25
+ It achieves an average score of 52.03 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 52.16.
26
+
27
+ ### Model Optimizations
28
+
29
+ This model was obtained by quantizing the weights of [gemma-2-2b](https://huggingface.co/google/gemma-2-2b) to INT8 data type.
30
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
31
+
32
+ Only the weights of the linear operators within transformers blocks are quantized. Symmetric per-channel quantization is applied, in which a linear scaling per output dimension maps the INT8 and floating point representations of the quantized weights.
33
+ The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library. GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
34
+
35
+ ## Deployment
36
+
37
+ ### Use with vLLM
38
+
39
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
40
+
41
+ ```python
42
+ from vllm import LLM, SamplingParams
43
+ from transformers import AutoTokenizer
44
+
45
+ model_id = "neuralmagic/gemma-2-2b-quantized.w8a16"
46
+
47
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
50
+
51
+ messages = [
52
+ {"role": "user", "content": "Who are you? Please respond in pirate speak!"},
53
+ ]
54
+
55
+ prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
56
+
57
+ llm = LLM(model=model_id)
58
+
59
+ outputs = llm.generate(prompts, sampling_params)
60
+
61
+ generated_text = outputs[0].outputs[0].text
62
+ print(generated_text)
63
+ ```
64
+
65
+ vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
66
+
67
+ ## Creation
68
+
69
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
70
+
71
+ ```python
72
+ from transformers import AutoTokenizer
73
+ from datasets import Dataset
74
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
75
+ from llmcompressor.modifiers.quantization import GPTQModifier
76
+ import random
77
+
78
+ model_id = "google/gemma-2-2b"
79
+
80
+ num_samples = 256
81
+ max_seq_len = 8192
82
+
83
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
84
+
85
+ max_token_id = len(tokenizer.get_vocab()) - 1
86
+ input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
87
+ attention_mask = num_samples * [max_seq_len * [1]]
88
+ ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
89
+
90
+ recipe = GPTQModifier(
91
+ targets="Linear",
92
+ scheme="W8A16",
93
+ ignore=["lm_head"],
94
+ dampening_frac=0.01,
95
+ )
96
+
97
+ model = SparseAutoModelForCausalLM.from_pretrained(
98
+ model_id,
99
+ device_map="auto",
100
+ trust_remote_code=True,
101
+ )
102
+
103
+ oneshot(
104
+ model=model,
105
+ dataset=ds,
106
+ recipe=recipe,
107
+ max_seq_length=max_seq_len,
108
+ num_calibration_samples=num_samples,
109
+ )
110
+ model.save_pretrained("gemma-2-2b-quantized.w8a16")
111
+ ```
112
+
113
+ ## Evaluation
114
+
115
+ The model was evaluated on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) leaderboard tasks (version 1) with the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/tree/383bbd54bc621086e05aa1b030d8d4d5635b25e6) (commit 383bbd54bc621086e05aa1b030d8d4d5635b25e6) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
116
+ ```
117
+ lm_eval \
118
+ --model vllm \
119
+ --model_args pretrained="neuralmagic/gemma-2-2b-quantized.w8a16",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
120
+ --tasks openllm \
121
+ --batch_size auto
122
+ ```
123
+
124
+ ### Accuracy
125
+
126
+ #### Open LLM Leaderboard evaluation scores
127
+ <table>
128
+ <tr>
129
+ <td><strong>Benchmark</strong>
130
+ </td>
131
+ <td><strong>gemma-2-2b</strong>
132
+ </td>
133
+ <td><strong>gemma-2-2b-quantized.w8a16 (this model)</strong>
134
+ </td>
135
+ <td><strong>Recovery</strong>
136
+ </td>
137
+ </tr>
138
+ <tr>
139
+ <td>MMLU (5-shot)
140
+ </td>
141
+ <td>53.01
142
+ </td>
143
+ <td>52.86
144
+ </td>
145
+ <td>99.7%
146
+ </td>
147
+ </tr>
148
+ <tr>
149
+ <td>ARC Challenge (25-shot)
150
+ </td>
151
+ <td>53.92
152
+ </td>
153
+ <td>54.27
154
+ </td>
155
+ <td>100.6%
156
+ </td>
157
+ </tr>
158
+ <tr>
159
+ <td>GSM-8K (5-shot, strict-match)
160
+ </td>
161
+ <td>24.03
162
+ </td>
163
+ <td>23.81
164
+ </td>
165
+ <td>99.1%
166
+ </td>
167
+ </tr>
168
+ <tr>
169
+ <td>Hellaswag (10-shot)
170
+ </td>
171
+ <td>74.74
172
+ </td>
173
+ <td>74.56
174
+ </td>
175
+ <td>99.8%
176
+ </td>
177
+ </tr>
178
+ <tr>
179
+ <td>Winogrande (5-shot)
180
+ </td>
181
+ <td>70.96
182
+ </td>
183
+ <td>70.56
184
+ </td>
185
+ <td>99.4%
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>TruthfulQA (0-shot)
190
+ </td>
191
+ <td>36.29
192
+ </td>
193
+ <td>36.15
194
+ </td>
195
+ <td>99.6%
196
+ </td>
197
+ </tr>
198
+ <tr>
199
+ <td><strong>Average</strong>
200
+ </td>
201
+ <td><strong>52.16</strong>
202
+ </td>
203
+ <td><strong>52.03</strong>
204
+ </td>
205
+ <td><strong>99.8%</strong>
206
+ </td>
207
+ </tr>
208
+ </table>