alexmarques commited on
Commit
772fc46
·
verified ·
1 Parent(s): 13f2ee0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +216 -0
README.md ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text-generation
3
+ tags:
4
+ - int8
5
+ - vllm
6
+ license: gemma
7
+ base_model: google/gemma-2-9b-it
8
+ ---
9
+
10
+ # gemma-2-9b-it-quantized.w8a8
11
+
12
+ ## Model Overview
13
+ - **Model Architecture:** Gemma 2
14
+ - **Input:** Text
15
+ - **Output:** Text
16
+ - **Model Optimizations:**
17
+ - **Activation quantization:** INT8
18
+ - **Weight quantization:** INT8
19
+ - **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it), this models is intended for assistant-like chat.
20
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
21
+ - **Release Date:** 8/16/2024
22
+ - **Version:** 1.0
23
+ - **License(s):** [gemma](https://ai.google.dev/gemma/terms)
24
+ - **Model Developers:** Neural Magic
25
+
26
+ Quantized version of [gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it).
27
+ It achieves an average score of 73.71 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 73.80.
28
+
29
+ ### Model Optimizations
30
+
31
+ This model was obtained by quantizing the weights of [gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it) to INT8 data type.
32
+ This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x).
33
+ Weight quantization also reduces disk size requirements by approximately 50%.
34
+
35
+ Only weights and activations of the linear operators within transformers blocks are quantized.
36
+ Weights are quantized with a symmetric static per-channel scheme, where a fixed linear scaling factor is applied between INT8 and floating point representations for each output channel dimension.
37
+ Activations are quantized with a symmetric dynamic per-token scheme, computing a linear scaling factor at runtime for each token between INT8 and floating point representations.
38
+ 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.
39
+ GPTQ used a 1% damping factor and 256 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
40
+
41
+ ## Deployment
42
+
43
+ ### Use with vLLM
44
+
45
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
46
+
47
+ ```python
48
+ from vllm import LLM, SamplingParams
49
+ from transformers import AutoTokenizer
50
+
51
+ model_id = "neuralmagic/gemma-2-9b-it-quantized.w8a8"
52
+
53
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
54
+
55
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
56
+
57
+ messages = [
58
+ {"role": "user", "content": "Who are you? Please respond in pirate speak!"},
59
+ ]
60
+
61
+ prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
62
+
63
+ llm = LLM(model=model_id)
64
+
65
+ outputs = llm.generate(prompts, sampling_params)
66
+
67
+ generated_text = outputs[0].outputs[0].text
68
+ print(generated_text)
69
+ ```
70
+
71
+ vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
72
+
73
+ ## Creation
74
+
75
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
76
+
77
+ ```python
78
+ from transformers import AutoTokenizer
79
+ from datasets import load_dataset
80
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
81
+ from llmcompressor.modifiers.quantization import GPTQModifier
82
+
83
+ model_id = "google/gemma-2-9b-it"
84
+
85
+ num_samples = 256
86
+ max_seq_len = 8192
87
+
88
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
89
+
90
+ def preprocess_fn(example):
91
+ return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
92
+
93
+ ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
94
+ ds = ds.shuffle().select(range(num_samples))
95
+ ds = ds.map(preprocess_fn)
96
+
97
+ recipe = GPTQModifier(
98
+ sequential=True,
99
+ targets="Linear",
100
+ scheme="W8A8",
101
+ ignore=["lm_head"],
102
+ dampening_frac=0.01,
103
+ observer="mse"
104
+ )
105
+
106
+ model = SparseAutoModelForCausalLM.from_pretrained(
107
+ model_id,
108
+ device_map="auto",
109
+ )
110
+
111
+ oneshot(
112
+ model=model,
113
+ dataset=ds,
114
+ recipe=recipe,
115
+ max_seq_length=max_seq_len,
116
+ num_calibration_samples=num_samples,
117
+ )
118
+ model.save_pretrained("gemma-2-9b-it-quantized.w8a8")
119
+ ```
120
+
121
+ ## Evaluation
122
+
123
+ 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:
124
+ ```
125
+ lm_eval \
126
+ --model vllm \
127
+ --model_args pretrained="neuralmagic/gemma-2-9b-it-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
128
+ --tasks openllm \
129
+ --batch_size auto
130
+ ```
131
+
132
+ ### Accuracy
133
+
134
+ #### Open LLM Leaderboard evaluation scores
135
+ <table>
136
+ <tr>
137
+ <td><strong>Benchmark</strong>
138
+ </td>
139
+ <td><strong>gemma-2-9b-it</strong>
140
+ </td>
141
+ <td><strong>gemma-2-9b-it-quantized.w8a8 (this model)</strong>
142
+ </td>
143
+ <td><strong>Recovery</strong>
144
+ </td>
145
+ </tr>
146
+ <tr>
147
+ <td>MMLU (5-shot)
148
+ </td>
149
+ <td>72.29
150
+ </td>
151
+ <td>71.90
152
+ </td>
153
+ <td>99.5%
154
+ </td>
155
+ </tr>
156
+ <tr>
157
+ <td>ARC Challenge (25-shot)
158
+ </td>
159
+ <td>71.08
160
+ </td>
161
+ <td>71.42
162
+ </td>
163
+ <td>100.5%
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>GSM-8K (5-shot, strict-match)
168
+ </td>
169
+ <td>79.30
170
+ </td>
171
+ <td>78.85
172
+ </td>
173
+ <td>99.4%
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <td>Hellaswag (10-shot)
178
+ </td>
179
+ <td>81.93
180
+ </td>
181
+ <td>81.60
182
+ </td>
183
+ <td>99.6
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <td>Winogrande (5-shot)
188
+ </td>
189
+ <td>77.98
190
+ </td>
191
+ <td>78.37
192
+ </td>
193
+ <td>100.5%
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>TruthfulQA (0-shot)
198
+ </td>
199
+ <td>60.21
200
+ </td>
201
+ <td>60.12
202
+ </td>
203
+ <td>99.9%
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td><strong>Average</strong>
208
+ </td>
209
+ <td><strong>73.80</strong>
210
+ </td>
211
+ <td><strong>73.71</strong>
212
+ </td>
213
+ <td><strong>99.9%</strong>
214
+ </td>
215
+ </tr>
216
+ </table>