Lin-K76 commited on
Commit
8193293
·
verified ·
1 Parent(s): c8f8c9b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +225 -0
README.md ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - fp8
4
+ - vllm
5
+ license: llama3.1
6
+ license_link: https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE
7
+ language:
8
+ - en
9
+ ---
10
+
11
+ # Meta-Llama-3.1-8B-Instruct-FP8-dynamic
12
+
13
+ ## Model Overview
14
+ - **Model Architecture:** Meta-Llama-3.1
15
+ - **Input:** Text
16
+ - **Output:** Text
17
+ - **Model Optimizations:**
18
+ - **Weight quantization:** FP8
19
+ - **Activation quantization:** FP8
20
+ - **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.
21
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
22
+ - **Release Date:** 7/23/2024
23
+ - **Version:** 1.0
24
+ - **License(s):** [llama3.1](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE)
25
+ - **Model Developers:** Neural Magic
26
+
27
+ Quantized version of [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct).
28
+ It achieves an average score of 68.77 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 69.33.
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights and activations of [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) to FP8 data type, ready for inference with vLLM built from source.
33
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
34
+
35
+ Only the weights and activations 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 FP8 representations of the quantized weights and activations. Activations are also quantized on a per-token dynamic basis.
36
+ [LLM Compressor](https://github.com/vllm-project/llm-compressor) is used for quantization with 512 sequences of UltraChat.
37
+
38
+ ## Deployment
39
+
40
+ ### Use with vLLM
41
+
42
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
43
+
44
+ ```python
45
+ from vllm import LLM, SamplingParams
46
+ from transformers import AutoTokenizer
47
+
48
+ model_id = "neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8-dynamic"
49
+
50
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
51
+
52
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
53
+
54
+ messages = [
55
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
56
+ {"role": "user", "content": "Who are you?"},
57
+ ]
58
+
59
+ prompts = tokenizer.apply_chat_template(messages, tokenize=False)
60
+
61
+ llm = LLM(model=model_id)
62
+
63
+ outputs = llm.generate(prompts, sampling_params)
64
+
65
+ generated_text = outputs[0].outputs[0].text
66
+ print(generated_text)
67
+ ```
68
+
69
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
70
+
71
+ ## Creation
72
+
73
+ This model was created by applying [LLM Compressor with calibration samples from UltraChat](https://github.com/vllm-project/llm-compressor/blob/sa/big_model_support/examples/big_model_offloading/big_model_w8a8_calibrate.py), as presented in the code snipet below.
74
+
75
+ ```python
76
+ import torch
77
+
78
+ from transformers import AutoTokenizer
79
+
80
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
81
+ from llmcompressor.transformers.compression.helpers import ( # noqa
82
+ calculate_offload_device_map,
83
+ custom_offload_device_map,
84
+ )
85
+
86
+ recipe = """
87
+ quant_stage:
88
+ quant_modifiers:
89
+ QuantizationModifier:
90
+ ignore: ["lm_head"]
91
+ config_groups:
92
+ group_0:
93
+ weights:
94
+ num_bits: 8
95
+ type: float
96
+ strategy: channel
97
+ dynamic: false
98
+ symmetric: true
99
+ input_activations:
100
+ num_bits: 8
101
+ type: float
102
+ strategy: token
103
+ dynamic: true
104
+ symmetric: true
105
+ targets: ["Linear"]
106
+ """
107
+
108
+ model_stub = "/meta-llama/Meta-Llama-3.1-70B-Instruct"
109
+ model_name = model_stub.split("/")[-1]
110
+
111
+ device_map = calculate_offload_device_map(
112
+ model_stub, reserve_for_hessians=False, num_gpus=1, torch_dtype=torch.float16
113
+ )
114
+
115
+ model = SparseAutoModelForCausalLM.from_pretrained(
116
+ model_stub, torch_dtype=torch.float16, device_map=device_map
117
+ )
118
+
119
+ output_dir = f"./{model_name}-FP8-dynamic"
120
+
121
+ oneshot(
122
+ model=model,
123
+ recipe=recipe,
124
+ output_dir=output_dir,
125
+ save_compressed=True,
126
+ tokenizer=AutoTokenizer.from_pretrained(model_stub),
127
+ )
128
+ ```
129
+
130
+ ## Evaluation
131
+
132
+ 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) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
133
+ ```
134
+ lm_eval \
135
+ --model vllm \
136
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8-dynamic",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
137
+ --tasks openllm \
138
+ --batch_size auto
139
+ ```
140
+
141
+ ### Accuracy
142
+
143
+ #### Open LLM Leaderboard evaluation scores
144
+ <table>
145
+ <tr>
146
+ <td><strong>Benchmark</strong>
147
+ </td>
148
+ <td><strong>Meta-Llama-3.1-8B-Instruct </strong>
149
+ </td>
150
+ <td><strong>Meta-Llama-3.1-8B-Instruct-FP8-dynamic(this model)</strong>
151
+ </td>
152
+ <td><strong>Recovery</strong>
153
+ </td>
154
+ </tr>
155
+ <tr>
156
+ <td>MMLU (5-shot)
157
+ </td>
158
+ <td>67.94
159
+ </td>
160
+ <td>68.09
161
+ </td>
162
+ <td>100.2%
163
+ </td>
164
+ </tr>
165
+ <tr>
166
+ <td>ARC Challenge (25-shot)
167
+ </td>
168
+ <td>60.41
169
+ </td>
170
+ <td>60.24
171
+ </td>
172
+ <td>99.72%
173
+ </td>
174
+ </tr>
175
+ <tr>
176
+ <td>GSM-8K (5-shot, strict-match)
177
+ </td>
178
+ <td>75.66
179
+ </td>
180
+ <td>74.22
181
+ </td>
182
+ <td>98.10%
183
+ </td>
184
+ </tr>
185
+ <tr>
186
+ <td>Hellaswag (10-shot)
187
+ </td>
188
+ <td>80.01
189
+ </td>
190
+ <td>79.68
191
+ </td>
192
+ <td>99.59%
193
+ </td>
194
+ </tr>
195
+ <tr>
196
+ <td>Winogrande (5-shot)
197
+ </td>
198
+ <td>77.90
199
+ </td>
200
+ <td>77.03
201
+ </td>
202
+ <td>98.88%
203
+ </td>
204
+ </tr>
205
+ <tr>
206
+ <td>TruthfulQA (0-shot)
207
+ </td>
208
+ <td>54.04
209
+ </td>
210
+ <td>53.37
211
+ </td>
212
+ <td>98.76%
213
+ </td>
214
+ </tr>
215
+ <tr>
216
+ <td><strong>Average</strong>
217
+ </td>
218
+ <td><strong>69.33</strong>
219
+ </td>
220
+ <td><strong>68.77</strong>
221
+ </td>
222
+ <td><strong>99.20%</strong>
223
+ </td>
224
+ </tr>
225
+ </table>