Lin-K76 commited on
Commit
f1b0386
·
verified ·
1 Parent(s): 92300e4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +222 -14
README.md CHANGED
@@ -7,22 +7,230 @@ tags:
7
  # Meta-Llama-3-8B-Instruct-FP8
8
 
9
  ## Model Overview
10
- Meta-Llama-3-8B-Instruct quantized to FP8 weights and activations using per-tensor quantization, ready for inference with vLLM >= 0.5.0.
 
 
 
 
 
 
 
 
 
 
11
 
12
- ## Usage and Creation
13
- Produced using [AutoFP8 with calibration samples from ultrachat](https://github.com/neuralmagic/AutoFP8/blob/147fa4d9e1a90ef8a93f96fc7d9c33056ddc017a/example_dataset.py).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  ## Evaluation
16
 
17
- ### Open LLM Leaderboard evaluation scores
18
- | | Meta-Llama-3-8B-Instruct | Meta-Llama-3-8B-Instruct-FP8<br>(this model) |
19
- | :------------------: | :----------------------: | :------------------------------------------------: |
20
- | arc-c<br>25-shot | 62.54 | 61.77 |
21
- | hellaswag<br>10-shot | 78.83 | 78.56 |
22
- | mmlu<br>5-shot | 66.60 | 66.27 |
23
- | truthfulqa<br>0-shot | 52.44 | 52.35 |
24
- | winogrande<br>5-shot | 75.93 | 76.4 |
25
- | gsm8k<br>5-shot | 75.96 | 73.99 |
26
- | **Average<br>Accuracy** | **68.71** | **68.22** |
27
- | **Recovery** | **100%** | **99.28%** |
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # Meta-Llama-3-8B-Instruct-FP8
8
 
9
  ## Model Overview
10
+ - **Model Architecture:** Meta-Llama-3
11
+ - **Input:** Text
12
+ - **Output:** Text
13
+ - **Model Optimizations:**
14
+ - **Weight quantization:** FP8
15
+ - **Activation quantization:** FP8
16
+ - **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-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:** 6/8/2024
19
+ - **Version:** 1.0
20
+ - **Model Developers:** Neural Magic
21
 
22
+ Quantized version of [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct).
23
+ It achieves an average score of 68.22 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 68.71.
24
+
25
+ ### Model Optimizations
26
+
27
+ This model was obtained by quantizing the weights and activations of [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) to FP8 data type, ready for inference with vLLM >= 0.5.0.
28
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
29
+
30
+ 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.
31
+ [AutoFP8](https://github.com/neuralmagic/AutoFP8) is used for quantization with 512 sequences of UltraChat.
32
+
33
+ ## Deployment
34
+
35
+ ### Use with vLLM
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-8B-Instruct-FP8"
44
+
45
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
46
+
47
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
48
+
49
+ messages = [
50
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
51
+ {"role": "user", "content": "Who are you?"},
52
+ ]
53
+
54
+ prompts = tokenizer.apply_chat_template(messages, tokenize=False)
55
+
56
+ llm = LLM(model=model_id)
57
+
58
+ outputs = llm.generate(prompts, sampling_params)
59
+
60
+ generated_text = outputs[0].outputs[0].text
61
+ print(generated_text)
62
+ ```
63
+
64
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
65
+
66
+ ### Use with transformers
67
+
68
+ This model is supported by Transformers leveraging the integration with the [AutoFP8](https://github.com/neuralmagic/AutoFP8) data format.
69
+ The following example contemplates how the model can be used using the `generate()` function.
70
+
71
+ ```python
72
+ from transformers import AutoTokenizer, AutoModelForCausalLM
73
+
74
+ model_id = "neuralmagic/Meta-Llama-3-8B-Instruct-FP8"
75
+
76
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
77
+ model = AutoModelForCausalLM.from_pretrained(
78
+ model_id,
79
+ torch_dtype="auto",
80
+ device_map="auto",
81
+ )
82
+
83
+ messages = [
84
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
85
+ {"role": "user", "content": "Who are you?"},
86
+ ]
87
+
88
+ input_ids = tokenizer.apply_chat_template(
89
+ messages,
90
+ add_generation_prompt=True,
91
+ return_tensors="pt"
92
+ ).to(model.device)
93
+
94
+ terminators = [
95
+ tokenizer.eos_token_id,
96
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
97
+ ]
98
+
99
+ outputs = model.generate(
100
+ input_ids,
101
+ max_new_tokens=256,
102
+ eos_token_id=terminators,
103
+ do_sample=True,
104
+ temperature=0.6,
105
+ top_p=0.9,
106
+ )
107
+ response = outputs[0][input_ids.shape[-1]:]
108
+ print(tokenizer.decode(response, skip_special_tokens=True))
109
+ ```
110
+
111
+ ## Creation
112
+
113
+ This model was created by applying [AutoFP8 with calibration samples from ultrachat](https://github.com/neuralmagic/AutoFP8/blob/147fa4d9e1a90ef8a93f96fc7d9c33056ddc017a/example_dataset.py), as presented in the code snipet below.
114
+ Although AutoFP8 was used for this particular model, Neural Magic is transitioning to using [llm-compressor](https://github.com/vllm-project/llm-compressor) which supports several quantization schemes and models not supported by AutoFP8.
115
+
116
+ ```python
117
+ from datasets import load_dataset
118
+ from transformers import AutoTokenizer
119
+
120
+ from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
121
+
122
+ pretrained_model_dir = "meta-llama/Meta-Llama-3-8B-Instruct"
123
+ quantized_model_dir = "Meta-Llama-3-8B-Instruct-FP8"
124
+
125
+ tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
126
+ tokenizer.pad_token = tokenizer.eos_token
127
+
128
+ ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
129
+ examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
130
+ examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
131
+
132
+ quantize_config = BaseQuantizeConfig(quant_method="fp8", activation_scheme="static")
133
+
134
+ model = AutoFP8ForCausalLM.from_pretrained(
135
+ pretrained_model_dir, quantize_config=quantize_config
136
+ )
137
+ model.quantize(examples)
138
+ model.save_quantized(quantized_model_dir)
139
+ ```
140
 
141
  ## Evaluation
142
 
143
+ 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:
144
+ ```
145
+ lm_eval \
146
+ --model vllm \
147
+ --model_args pretrained="neuralmagic/Meta-Llama-3-8B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
148
+ --tasks openllm \
149
+ --batch_size auto
150
+ ```
151
+
152
+ ### Accuracy
 
153
 
154
+ #### Open LLM Leaderboard evaluation scores
155
+ <table>
156
+ <tr>
157
+ <td><strong>Benchmark</strong>
158
+ </td>
159
+ <td><strong>Meta-Llama-3-8B-Instruct </strong>
160
+ </td>
161
+ <td><strong>Meta-Llama-3-8B-Instruct-FP8(this model)</strong>
162
+ </td>
163
+ <td><strong>Recovery</strong>
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>MMLU (5-shot)
168
+ </td>
169
+ <td>66.60
170
+ </td>
171
+ <td>66.27
172
+ </td>
173
+ <td>99.50%
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <td>ARC Challenge (25-shot)
178
+ </td>
179
+ <td>62.54
180
+ </td>
181
+ <td>61.77
182
+ </td>
183
+ <td>98.76%
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <td>GSM-8K (5-shot, strict-match)
188
+ </td>
189
+ <td>75.96
190
+ </td>
191
+ <td>73.99
192
+ </td>
193
+ <td>97.40%
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>Hellaswag (10-shot)
198
+ </td>
199
+ <td>78.83
200
+ </td>
201
+ <td>78.56
202
+ </td>
203
+ <td>99.65%
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td>Winogrande (5-shot)
208
+ </td>
209
+ <td>75.93
210
+ </td>
211
+ <td>76.40
212
+ </td>
213
+ <td>100.6%
214
+ </td>
215
+ </tr>
216
+ <tr>
217
+ <td>TruthfulQA (0-shot)
218
+ </td>
219
+ <td>52.44
220
+ </td>
221
+ <td>52.35
222
+ </td>
223
+ <td>99.82%
224
+ </td>
225
+ </tr>
226
+ <tr>
227
+ <td><strong>Average</strong>
228
+ </td>
229
+ <td><strong>68.71</strong>
230
+ </td>
231
+ <td><strong>68.22</strong>
232
+ </td>
233
+ <td><strong>99.28%</strong>
234
+ </td>
235
+ </tr>
236
+ </table>