Lin-K76 commited on
Commit
cd7369f
·
verified ·
1 Parent(s): 2239eb6

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +200 -0
README.md ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - fp8
4
+ - vllm
5
+ license: apache-2.0
6
+ language:
7
+ - en
8
+ ---
9
+
10
+ # Mistral-Nemo-Instruct-2407-FP8
11
+
12
+ ## Model Overview
13
+ - **Model Architecture:** Meta-Llama-3
14
+ - **Input:** Text
15
+ - **Output:** Text
16
+ - **Model Optimizations:**
17
+ - **Weight quantization:** FP8
18
+ - **Activation quantization:** FP8
19
+ - **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.
20
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
21
+ - **Release Date:** 7/18/2024
22
+ - **Version:** 1.0
23
+ - **License(s):** [apache-2.0](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md)
24
+ - **Model Developers:** Neural Magic
25
+
26
+ Quantized version of [Mistral-Nemo-Instruct-2407](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407).
27
+ 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.
28
+
29
+ ### Model Optimizations
30
+
31
+ This model was obtained by quantizing the weights and activations of [Mistral-Nemo-Instruct-2407](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407) to FP8 data type, ready for inference with vLLM >= 0.5.0.
32
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
33
+
34
+ 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.
35
+ [AutoFP8](https://github.com/neuralmagic/AutoFP8) is used for quantization with 512 sequences of UltraChat.
36
+
37
+ ## Deployment
38
+
39
+ ### Use with vLLM
40
+
41
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
42
+
43
+ ```python
44
+ from vllm import LLM, SamplingParams
45
+ from transformers import AutoTokenizer
46
+
47
+ model_id = "neuralmagic/Mistral-Nemo-Instruct-2407-FP8"
48
+
49
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
50
+
51
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
52
+
53
+ messages = [
54
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
55
+ {"role": "user", "content": "Who are you?"},
56
+ ]
57
+
58
+ prompts = tokenizer.apply_chat_template(messages, tokenize=False)
59
+
60
+ llm = LLM(model=model_id)
61
+
62
+ outputs = llm.generate(prompts, sampling_params)
63
+
64
+ generated_text = outputs[0].outputs[0].text
65
+ print(generated_text)
66
+ ```
67
+
68
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
69
+
70
+ ## Creation
71
+
72
+ 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.
73
+ 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.
74
+
75
+ ```python
76
+ from datasets import load_dataset
77
+ from transformers import AutoTokenizer
78
+
79
+ from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
80
+
81
+ pretrained_model_dir = "meta-llama/Mistral-Nemo-Instruct-2407"
82
+ quantized_model_dir = "Mistral-Nemo-Instruct-2407-FP8"
83
+
84
+ tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
85
+ tokenizer.pad_token = tokenizer.eos_token
86
+
87
+ ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
88
+ examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
89
+ examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
90
+
91
+ quantize_config = BaseQuantizeConfig(
92
+ quant_method="fp8",
93
+ activation_scheme="static"
94
+ ignore_patterns=["re:.*lm_head"],
95
+ )
96
+
97
+ model = AutoFP8ForCausalLM.from_pretrained(
98
+ pretrained_model_dir, quantize_config=quantize_config
99
+ )
100
+
101
+ model.quantize(examples)
102
+ model.save_quantized(quantized_model_dir)
103
+ ```
104
+
105
+ ## Evaluation
106
+
107
+ 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:
108
+ ```
109
+ lm_eval \
110
+ --model vllm \
111
+ --model_args pretrained="neuralmagic/Mistral-Nemo-Instruct-2407-FP8",dtype=auto,gpu_memory_utilization=0.4,max_model_len=4096 \
112
+ --tasks openllm \
113
+ --batch_size auto
114
+ ```
115
+
116
+ ### Accuracy
117
+
118
+ #### Open LLM Leaderboard evaluation scores
119
+ <table>
120
+ <tr>
121
+ <td><strong>Benchmark</strong>
122
+ </td>
123
+ <td><strong>Mistral-Nemo-Instruct-2407 </strong>
124
+ </td>
125
+ <td><strong>Mistral-Nemo-Instruct-2407-FP8(this model)</strong>
126
+ </td>
127
+ <td><strong>Recovery</strong>
128
+ </td>
129
+ </tr>
130
+ <tr>
131
+ <td>MMLU (5-shot)
132
+ </td>
133
+ <td>66.60
134
+ </td>
135
+ <td>66.27
136
+ </td>
137
+ <td>99.50%
138
+ </td>
139
+ </tr>
140
+ <tr>
141
+ <td>ARC Challenge (25-shot)
142
+ </td>
143
+ <td>62.54
144
+ </td>
145
+ <td>61.77
146
+ </td>
147
+ <td>98.76%
148
+ </td>
149
+ </tr>
150
+ <tr>
151
+ <td>GSM-8K (5-shot, strict-match)
152
+ </td>
153
+ <td>75.96
154
+ </td>
155
+ <td>73.99
156
+ </td>
157
+ <td>97.40%
158
+ </td>
159
+ </tr>
160
+ <tr>
161
+ <td>Hellaswag (10-shot)
162
+ </td>
163
+ <td>78.83
164
+ </td>
165
+ <td>78.56
166
+ </td>
167
+ <td>99.65%
168
+ </td>
169
+ </tr>
170
+ <tr>
171
+ <td>Winogrande (5-shot)
172
+ </td>
173
+ <td>75.93
174
+ </td>
175
+ <td>76.40
176
+ </td>
177
+ <td>100.6%
178
+ </td>
179
+ </tr>
180
+ <tr>
181
+ <td>TruthfulQA (0-shot)
182
+ </td>
183
+ <td>52.44
184
+ </td>
185
+ <td>52.35
186
+ </td>
187
+ <td>99.82%
188
+ </td>
189
+ </tr>
190
+ <tr>
191
+ <td><strong>Average</strong>
192
+ </td>
193
+ <td><strong>68.71</strong>
194
+ </td>
195
+ <td><strong>68.22</strong>
196
+ </td>
197
+ <td><strong>99.28%</strong>
198
+ </td>
199
+ </tr>
200
+ </table>