alexmarques commited on
Commit
257f5ca
1 Parent(s): 2f1d7c5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +218 -0
README.md ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - de
5
+ - fr
6
+ - it
7
+ - pt
8
+ - hi
9
+ - es
10
+ - th
11
+ pipeline_tag: text-generation
12
+ license: llama3.1
13
+ ---
14
+
15
+ # Meta-Llama-3.1-8B-quantized.w8a16
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Meta-Llama-3
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** INT8
23
+ - **Intended Use Cases:** Intended for commercial and research use multiple languages. Similarly to [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B), this models is intended for assistant-like chat.
24
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
25
+ - **Release Date:** 7/23/2024
26
+ - **Version:** 1.0
27
+ - **License(s):** Llama3.1
28
+ - **Model Developers:** Neural Magic
29
+
30
+ Quantized version of [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B).
31
+ It achieves an average score of 68.69 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 68.54.
32
+
33
+ ### Model Optimizations
34
+
35
+ This model was obtained by quantizing the weights of [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B) to INT8 data type.
36
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
37
+
38
+ 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.
39
+ 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.
40
+ GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
41
+
42
+
43
+ ## Deployment
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/Meta-Llama-3.1-8B-quantized.w8a16"
52
+ number_gpus = 1
53
+ max_model_len = 8192
54
+
55
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
56
+
57
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
58
+
59
+ messages = [
60
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
61
+ {"role": "user", "content": "Who are you?"},
62
+ ]
63
+
64
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
65
+
66
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
67
+
68
+ outputs = llm.generate(prompts, sampling_params)
69
+
70
+ generated_text = outputs[0].outputs[0].text
71
+ print(generated_text)
72
+ ```
73
+
74
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
75
+
76
+
77
+ ## Creation
78
+
79
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
80
+
81
+ ```python
82
+ from transformers import AutoTokenizer
83
+ from datasets import Dataset
84
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
85
+ from llmcompressor.modifiers.quantization import GPTQModifier
86
+ import random
87
+
88
+ model_id = "meta-llama/Meta-Llama-3.1-8B"
89
+
90
+ num_samples = 256
91
+ max_seq_len = 8192
92
+
93
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
94
+
95
+ max_token_id = len(tokenizer.get_vocab()) - 1
96
+ input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
97
+ attention_mask = num_samples * [max_seq_len * [1]]
98
+ ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
99
+
100
+ recipe = GPTQModifier(
101
+ targets="Linear",
102
+ scheme="W8A16",
103
+ ignore=["lm_head"],
104
+ dampening_frac=0.01,
105
+ )
106
+
107
+ model = SparseAutoModelForCausalLM.from_pretrained(
108
+ model_id,
109
+ device_map="auto",
110
+ trust_remote_code=True,
111
+ )
112
+
113
+ oneshot(
114
+ model=model,
115
+ dataset=ds,
116
+ recipe=recipe,
117
+ max_seq_length=max_seq_len,
118
+ num_calibration_samples=num_samples,
119
+ )
120
+ model.save_pretrained("Meta-Llama-3.1-8B-quantized.w8a16")
121
+ ```
122
+
123
+ ## Evaluation
124
+
125
+ 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:
126
+ ```
127
+ lm_eval \
128
+ --model vllm \
129
+ --model_args pretrained="neuralmagic/Meta-Llama-3-8B-quantized.w8a16",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
130
+ --tasks openllm \
131
+ --batch_size auto
132
+ ```
133
+
134
+ ### Accuracy
135
+
136
+ #### Open LLM Leaderboard evaluation scores
137
+ <table>
138
+ <tr>
139
+ <td><strong>Benchmark</strong>
140
+ </td>
141
+ <td><strong>Meta-Llama-3-8B </strong>
142
+ </td>
143
+ <td><strong>Meta-Llama-3-8B-quantized.w8a16(this model)</strong>
144
+ </td>
145
+ <td><strong>Recovery</strong>
146
+ </td>
147
+ </tr>
148
+ <tr>
149
+ <td>MMLU (5-shot)
150
+ </td>
151
+ <td>65.07
152
+ </td>
153
+ <td>65.44
154
+ </td>
155
+ <td>100.6%
156
+ </td>
157
+ </tr>
158
+ <tr>
159
+ <td>ARC Challenge (25-shot)
160
+ </td>
161
+ <td>58.11
162
+ </td>
163
+ <td>58.62
164
+ </td>
165
+ <td>100.9%
166
+ </td>
167
+ </tr>
168
+ <tr>
169
+ <td>GSM-8K (5-shot, strict-match)
170
+ </td>
171
+ <td>50.64
172
+ </td>
173
+ <td>49.66
174
+ </td>
175
+ <td>98.1%
176
+ </td>
177
+ </tr>
178
+ <tr>
179
+ <td>Hellaswag (10-shot)
180
+ </td>
181
+ <td>82.30
182
+ </td>
183
+ <td>82.21
184
+ </td>
185
+ <td>99.9%
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>Winogrande (5-shot)
190
+ </td>
191
+ <td>77.90
192
+ </td>
193
+ <td>78.06
194
+ </td>
195
+ <td>100.2%
196
+ </td>
197
+ </tr>
198
+ <tr>
199
+ <td>TruthfulQA (0-shot, mc2)
200
+ </td>
201
+ <td>44.15
202
+ </td>
203
+ <td>43.61
204
+ </td>
205
+ <td>98.8%
206
+ </td>
207
+ </tr>
208
+ <tr>
209
+ <td><strong>Average</strong>
210
+ </td>
211
+ <td><strong>63.03</strong>
212
+ </td>
213
+ <td><strong>62.93</strong>
214
+ </td>
215
+ <td><strong>99.8%</strong>
216
+ </td>
217
+ </tr>
218
+ </table>