Lin-K76 commited on
Commit
919cfdf
1 Parent(s): 40021d5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +258 -0
README.md ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-70B-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-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
28
+ It achieves an average score of 77.75 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 78.67.
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights and activations of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-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-70B-Instruct-FP8"
49
+ number_gpus = 2
50
+
51
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
52
+
53
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
54
+
55
+ messages = [
56
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
57
+ {"role": "user", "content": "Who are you?"},
58
+ ]
59
+
60
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
61
+
62
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
63
+
64
+ outputs = llm.generate(prompts, sampling_params)
65
+
66
+ generated_text = outputs[0].outputs[0].text
67
+ print(generated_text)
68
+ ```
69
+
70
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
71
+
72
+ ## Creation
73
+
74
+ 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.
75
+
76
+ ```python
77
+ import torch
78
+ from datasets import load_dataset
79
+ from transformers import AutoTokenizer
80
+
81
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
82
+ from llmcompressor.transformers.compression.helpers import (
83
+ calculate_offload_device_map,
84
+ custom_offload_device_map,
85
+ )
86
+
87
+ recipe = """
88
+ quant_stage:
89
+ quant_modifiers:
90
+ QuantizationModifier:
91
+ ignore: ["lm_head"]
92
+ config_groups:
93
+ group_0:
94
+ weights:
95
+ num_bits: 8
96
+ type: float
97
+ strategy: tensor
98
+ dynamic: false
99
+ symmetric: true
100
+ input_activations:
101
+ num_bits: 8
102
+ type: float
103
+ strategy: tensor
104
+ dynamic: false
105
+ symmetric: true
106
+ targets: ["Linear"]
107
+ """
108
+
109
+ model_stub = "meta-llama/Meta-Llama-3.1-70B-Instruct"
110
+ model_name = model_stub.split("/")[-1]
111
+
112
+ device_map = calculate_offload_device_map(
113
+ model_stub, reserve_for_hessians=False, num_gpus=2, torch_dtype=torch.float16
114
+ )
115
+
116
+ model = SparseAutoModelForCausalLM.from_pretrained(
117
+ model_stub, torch_dtype=torch.float16, device_map=device_map
118
+ )
119
+ tokenizer = AutoTokenizer.from_pretrained(model_stub)
120
+
121
+ output_dir = f"./{model_name}-FP8"
122
+
123
+ DATASET_ID = "HuggingFaceH4/ultrachat_200k"
124
+ DATASET_SPLIT = "train_sft"
125
+ NUM_CALIBRATION_SAMPLES = 512
126
+ MAX_SEQUENCE_LENGTH = 4096
127
+
128
+ ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
129
+ ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
130
+
131
+ def preprocess(example):
132
+ return {
133
+ "text": tokenizer.apply_chat_template(
134
+ example["messages"],
135
+ tokenize=False,
136
+ )
137
+ }
138
+
139
+ ds = ds.map(preprocess)
140
+
141
+ def tokenize(sample):
142
+ return tokenizer(
143
+ sample["text"],
144
+ padding=False,
145
+ max_length=MAX_SEQUENCE_LENGTH,
146
+ truncation=True,
147
+ add_special_tokens=False,
148
+ )
149
+
150
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
151
+
152
+ oneshot(
153
+ model=model,
154
+ output_dir=output_dir,
155
+ dataset=ds,
156
+ recipe=recipe,
157
+ max_seq_length=MAX_SEQUENCE_LENGTH,
158
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
159
+ save_compressed=True,
160
+ )
161
+ ```
162
+
163
+ ## Evaluation
164
+
165
+ 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:
166
+ ```
167
+ lm_eval \
168
+ --model vllm \
169
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8",dtype=auto,tensor_parallel_size=2,gpu_memory_utilization=0.8,add_bos_token=True,max_model_len=4096 \
170
+ --tasks openllm \
171
+ --batch_size auto
172
+ ```
173
+
174
+ ### Accuracy
175
+
176
+ #### Open LLM Leaderboard evaluation scores
177
+ <table>
178
+ <tr>
179
+ <td><strong>Benchmark</strong>
180
+ </td>
181
+ <td><strong>Meta-Llama-3.1-70B-Instruct </strong>
182
+ </td>
183
+ <td><strong>Meta-Llama-3.1-70B-Instruct-FP8(this model)</strong>
184
+ </td>
185
+ <td><strong>Recovery</strong>
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>MMLU (5-shot)
190
+ </td>
191
+ <td>82.21
192
+ </td>
193
+ <td>82.24
194
+ </td>
195
+ <td>100.0%
196
+ </td>
197
+ </tr>
198
+ <tr>
199
+ <td>ARC Challenge (25-shot)
200
+ </td>
201
+ <td>70.65
202
+ </td>
203
+ <td>69.03
204
+ </td>
205
+ <td>97.71%
206
+ </td>
207
+ </tr>
208
+ <tr>
209
+ <td>GSM-8K (5-shot, strict-match)
210
+ </td>
211
+ <td>87.95
212
+ </td>
213
+ <td>86.50
214
+ </td>
215
+ <td>98.35%
216
+ </td>
217
+ </tr>
218
+ <tr>
219
+ <td>Hellaswag (10-shot)
220
+ </td>
221
+ <td>86.33
222
+ </td>
223
+ <td>85.67
224
+ </td>
225
+ <td>99.24%
226
+ </td>
227
+ </tr>
228
+ <tr>
229
+ <td>Winogrande (5-shot)
230
+ </td>
231
+ <td>85.00
232
+ </td>
233
+ <td>85.79
234
+ </td>
235
+ <td>100.9%
236
+ </td>
237
+ </tr>
238
+ <tr>
239
+ <td>TruthfulQA (0-shot)
240
+ </td>
241
+ <td>59.90
242
+ </td>
243
+ <td>57.24
244
+ </td>
245
+ <td>95.56%
246
+ </td>
247
+ </tr>
248
+ <tr>
249
+ <td><strong>Average</strong>
250
+ </td>
251
+ <td><strong>78.67</strong>
252
+ </td>
253
+ <td><strong>77.75</strong>
254
+ </td>
255
+ <td><strong>98.82%</strong>
256
+ </td>
257
+ </tr>
258
+ </table>