alexmarques commited on
Commit
8b65aea
1 Parent(s): b892d70

Create README.md

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