Lin-K76 commited on
Commit
c285c71
·
verified ·
1 Parent(s): 4d24bdf

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +257 -0
README.md ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.52 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-tensor quantization is applied, in which a single linear scaling maps the FP8 representations of the quantized weights and activations.
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"
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
+ from datasets import load_dataset
78
+ from transformers import AutoTokenizer
79
+
80
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
81
+ from llmcompressor.transformers.compression.helpers import (
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: tensor
97
+ dynamic: false
98
+ symmetric: true
99
+ input_activations:
100
+ num_bits: 8
101
+ type: float
102
+ strategy: tensor
103
+ dynamic: false
104
+ symmetric: true
105
+ targets: ["Linear"]
106
+ """
107
+
108
+ model_stub = "meta-llama/Meta-Llama-3.1-8B-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=2, torch_dtype=torch.float16
113
+ )
114
+
115
+ model = SparseAutoModelForCausalLM.from_pretrained(
116
+ model_stub, torch_dtype=torch.float16, device_map=device_map
117
+ )
118
+ tokenizer = AutoTokenizer.from_pretrained(model_stub)
119
+
120
+ output_dir = f"./{model_name}-FP8"
121
+
122
+ DATASET_ID = "HuggingFaceH4/ultrachat_200k"
123
+ DATASET_SPLIT = "train_sft"
124
+ NUM_CALIBRATION_SAMPLES = 512
125
+ MAX_SEQUENCE_LENGTH = 4096
126
+
127
+ ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
128
+ ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
129
+
130
+ def preprocess(example):
131
+ return {
132
+ "text": tokenizer.apply_chat_template(
133
+ example["messages"],
134
+ tokenize=False,
135
+ )
136
+ }
137
+
138
+ ds = ds.map(preprocess)
139
+
140
+ def tokenize(sample):
141
+ return tokenizer(
142
+ sample["text"],
143
+ padding=False,
144
+ max_length=MAX_SEQUENCE_LENGTH,
145
+ truncation=True,
146
+ add_special_tokens=False,
147
+ )
148
+
149
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
150
+
151
+ oneshot(
152
+ model=model,
153
+ output_dir=output_dir,
154
+ dataset=ds,
155
+ recipe=recipe,
156
+ max_seq_length=MAX_SEQUENCE_LENGTH,
157
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
158
+ save_compressed=True,
159
+ )
160
+ ```
161
+
162
+ ## Evaluation
163
+
164
+ 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:
165
+ ```
166
+ lm_eval \
167
+ --model vllm \
168
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
169
+ --tasks openllm \
170
+ --batch_size auto
171
+ ```
172
+
173
+ ### Accuracy
174
+
175
+ #### Open LLM Leaderboard evaluation scores
176
+ <table>
177
+ <tr>
178
+ <td><strong>Benchmark</strong>
179
+ </td>
180
+ <td><strong>Meta-Llama-3.1-8B-Instruct </strong>
181
+ </td>
182
+ <td><strong>Meta-Llama-3.1-8B-Instruct-FP8(this model)</strong>
183
+ </td>
184
+ <td><strong>Recovery</strong>
185
+ </td>
186
+ </tr>
187
+ <tr>
188
+ <td>MMLU (5-shot)
189
+ </td>
190
+ <td>67.94
191
+ </td>
192
+ <td>68.00
193
+ </td>
194
+ <td>100.0%
195
+ </td>
196
+ </tr>
197
+ <tr>
198
+ <td>ARC Challenge (25-shot)
199
+ </td>
200
+ <td>60.41
201
+ </td>
202
+ <td>59.39
203
+ </td>
204
+ <td>98.31%
205
+ </td>
206
+ </tr>
207
+ <tr>
208
+ <td>GSM-8K (5-shot, strict-match)
209
+ </td>
210
+ <td>75.66
211
+ </td>
212
+ <td>73.77
213
+ </td>
214
+ <td>97.50%
215
+ </td>
216
+ </tr>
217
+ <tr>
218
+ <td>Hellaswag (10-shot)
219
+ </td>
220
+ <td>80.01
221
+ </td>
222
+ <td>79.56
223
+ </td>
224
+ <td>99.44%
225
+ </td>
226
+ </tr>
227
+ <tr>
228
+ <td>Winogrande (5-shot)
229
+ </td>
230
+ <td>77.90
231
+ </td>
232
+ <td>77.58
233
+ </td>
234
+ <td>99.59%
235
+ </td>
236
+ </tr>
237
+ <tr>
238
+ <td>TruthfulQA (0-shot)
239
+ </td>
240
+ <td>54.04
241
+ </td>
242
+ <td>52.84
243
+ </td>
244
+ <td>97.78%
245
+ </td>
246
+ </tr>
247
+ <tr>
248
+ <td><strong>Average</strong>
249
+ </td>
250
+ <td><strong>69.33</strong>
251
+ </td>
252
+ <td><strong>68.52</strong>
253
+ </td>
254
+ <td><strong>98.84%</strong>
255
+ </td>
256
+ </tr>
257
+ </table>