Lin-K76 commited on
Commit
96e85de
·
verified ·
1 Parent(s): d08d0f6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +149 -66
README.md CHANGED
@@ -7,19 +7,66 @@ tags:
7
  # Mistral-7B-Instruct-v0.3-FP8
8
 
9
  ## Model Overview
10
- * <h3 style="display: inline;">Model Architecture:</h3> Based on and identical to the Mistral-7B-Instruct-v0.3 architecture
11
- * <h3 style="display: inline;">Model Optimizations:</h3> Weights and activations quantized to FP8
12
- * <h3 style="display: inline;">Release Date:</h3> June 26, 2024
13
- * <h3 style="display: inline;">Model Developers:</h3> Neural Magic
 
 
 
 
 
 
 
14
 
15
- Mistral-7B-Instruct-v0.3-FP8 quantized to FP8 weights and activations using per-tensor quantization through the [AutoFP8 repository](https://github.com/neuralmagic/AutoFP8), ready for inference with vLLM >= 0.5.0.
16
- Calibrated with 10 repeats of each token in the tokenizer in random order to achieve 99% performance recovery on the Open LLM Benchmark evaluations.
17
- Reduces space on disk by ~50%.
18
- Part of the [FP8 LLMs for vLLM collection](https://huggingface.co/collections/neuralmagic/fp8-llms-for-vllm-666742ed2b78b7ac8df13127).
19
 
 
20
 
21
- ## Usage and Creation
22
- Produced using AutoFP8 with random tokens as calibration, based on [AutoFP8 with calibration samples from ultrachat](https://github.com/neuralmagic/AutoFP8/blob/147fa4d9e1a90ef8a93f96fc7d9c33056ddc017a/example_dataset.py).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  ```python
25
  from datasets import load_dataset
@@ -64,63 +111,99 @@ quantized_model_dir = f"{final_model_dir}-FP8"
64
  model.save_quantized(quantized_model_dir)
65
  ```
66
 
67
- Evaluated through vLLM with the following script:
68
 
 
69
  ```
70
- #!/bin/bash
71
-
72
- # Example usage:
73
- # CUDA_VISIBLE_DEVICES=0 ./eval_openllm.sh "neuralmagic/Mistral-7B-Instruct-v0.3-FP8" "tensor_parallel_size=1,max_model_len=4096,add_bos_token=True,gpu_memory_utilization=0.7"
74
-
75
- export MODEL_DIR=${1}
76
- export MODEL_ARGS=${2}
77
-
78
- declare -A tasks_fewshot=(
79
- ["arc_challenge"]=25
80
- ["winogrande"]=5
81
- ["truthfulqa_mc2"]=0
82
- ["hellaswag"]=10
83
- ["mmlu"]=5
84
- ["gsm8k"]=5
85
- )
86
-
87
- declare -A batch_sizes=(
88
- ["arc_challenge"]="auto"
89
- ["winogrande"]="auto"
90
- ["truthfulqa_mc2"]="auto"
91
- ["hellaswag"]="auto"
92
- ["mmlu"]=1
93
- ["gsm8k"]="auto"
94
- )
95
-
96
- for TASK in "${!tasks_fewshot[@]}"; do
97
- NUM_FEWSHOT=${tasks_fewshot[$TASK]}
98
- BATCH_SIZE=${batch_sizes[$TASK]}
99
- lm_eval --model vllm \
100
- --model_args pretrained=$MODEL_DIR,$MODEL_ARGS \
101
- --tasks ${TASK} \
102
- --num_fewshot ${NUM_FEWSHOT} \
103
- --write_out \
104
- --show_config \
105
- --device cuda \
106
- --batch_size ${BATCH_SIZE} \
107
- --output_path="results/${TASK}"
108
- done
109
  ```
110
 
111
- ## Evaluation
112
-
113
- Evaluated on the Open LLM Leaderboard evaluations through vLLM.
114
-
115
- ### Open LLM Leaderboard evaluation scores
116
- | | Mistral-7B-Instruct-v0.3 | neuralmagic/Mistral-7B-Instruct-v0.3-FP8<br>(this model) |
117
- | :------------------: | :----------------------: | :------------------------------------------------: |
118
- | arc-c<br>25-shot | 63.57 | 63.73 |
119
- | hellaswag<br>10-shot | 84.76 | 84.52 |
120
- | mmlu<br>5-shot | 61.84 | 61.63 |
121
- | truthfulqa<br>0-shot | 59.37 | 59.40 |
122
- | winogrande<br>5-shot | 79.40 | 78.30 |
123
- | gsm8k<br>5-shot | 49.05 | 47.54 |
124
- | **Average<br>Accuracy** | **66.33** | **65.85** |
125
- | **Recovery** | **100%** | **99.28%** |
126
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # Mistral-7B-Instruct-v0.3-FP8
8
 
9
  ## Model Overview
10
+ - **Model Architecture:** Mistral-7B-Instruct-v0.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-7B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-7B-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/26/2024
19
+ - **Version:** 1.0
20
+ - **Model Developers:** Neural Magic
21
 
22
+ Quantized version of [Mistral-7B-Instruct-v0.3](mistralai/Mistral-7B-Instruct-v0.3).
23
+ It achieves an average score of 65.85 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 66.33.
 
 
24
 
25
+ ### Model Optimizations
26
 
27
+ This model was obtained by quantizing the weights and activations of [Mistral-7B-Instruct-v0.3](mistralai/Mistral-7B-Instruct-v0.3) 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 10 repeats of every token in random order.
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/Mistral-7B-Instruct-v0.3-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
+ ## Creation
67
+
68
+ 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.
69
+ 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.
70
 
71
  ```python
72
  from datasets import load_dataset
 
111
  model.save_quantized(quantized_model_dir)
112
  ```
113
 
114
+ ## Evaluation
115
 
116
+ 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:
117
  ```
118
+ lm_eval \
119
+ --model vllm \
120
+ --model_args pretrained="neuralmagic/Mistral-7B-Instruct-v0.3-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
121
+ --tasks openllm \
122
+ --batch_size auto
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  ```
124
 
125
+ ### Accuracy
126
+
127
+ #### Open LLM Leaderboard evaluation scores
128
+ <table>
129
+ <tr>
130
+ <td><strong>Benchmark</strong>
131
+ </td>
132
+ <td><strong>Mistral-7B-Instruct-v0.3</strong>
133
+ </td>
134
+ <td><strong>Mistral-7B-Instruct-v0.3-FP8(this model)</strong>
135
+ </td>
136
+ <td><strong>Recovery</strong>
137
+ </td>
138
+ </tr>
139
+ <tr>
140
+ <td>MMLU (5-shot)
141
+ </td>
142
+ <td>61.84
143
+ </td>
144
+ <td>61.63
145
+ </td>
146
+ <td>99.66%
147
+ </td>
148
+ </tr>
149
+ <tr>
150
+ <td>ARC Challenge (25-shot)
151
+ </td>
152
+ <td>63.57
153
+ </td>
154
+ <td>63.73
155
+ </td>
156
+ <td>100.2%
157
+ </td>
158
+ </tr>
159
+ <tr>
160
+ <td>GSM-8K (5-shot, strict-match)
161
+ </td>
162
+ <td>49.05
163
+ </td>
164
+ <td>47.54
165
+ </td>
166
+ <td>96.92%
167
+ </td>
168
+ </tr>
169
+ <tr>
170
+ <td>Hellaswag (10-shot)
171
+ </td>
172
+ <td>84.76
173
+ </td>
174
+ <td>84.52
175
+ </td>
176
+ <td>99.71%
177
+ </td>
178
+ </tr>
179
+ <tr>
180
+ <td>Winogrande (5-shot)
181
+ </td>
182
+ <td>79.40
183
+ </td>
184
+ <td>78.30
185
+ </td>
186
+ <td>98.61%
187
+ </td>
188
+ </tr>
189
+ <tr>
190
+ <td>TruthfulQA (0-shot)
191
+ </td>
192
+ <td>59.37
193
+ </td>
194
+ <td>59.40
195
+ </td>
196
+ <td>100.0%
197
+ </td>
198
+ </tr>
199
+ <tr>
200
+ <td><strong>Average</strong>
201
+ </td>
202
+ <td><strong>66.33</strong>
203
+ </td>
204
+ <td><strong>65.85</strong>
205
+ </td>
206
+ <td><strong>99.28%</strong>
207
+ </td>
208
+ </tr>
209
+ </table>