seungahdev commited on
Commit
13b58bb
1 Parent(s): 2ee8c13

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +268 -0
README.md CHANGED
@@ -1,3 +1,271 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ base_model: mistralai/Mixtral-8X7B-Instruct-v0.1
4
+ inference: false
5
+ model_link: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
6
+ model_name: mistralai/Mixtral-8x7B-Instruct-v0.1
7
+ pipeline_tag: text-generation
8
+ quantized_by: FriendliAI
9
+ tags:
10
+ - pretrained
11
  ---
12
+
13
+ <!-- header start -->
14
+ <p align="center">
15
+ <img src="https://i.imgur.com/mNM6Cai.png" width="100%" alt="Friendli Logo">
16
+ </p>
17
+ <!-- header end -->
18
+
19
+ # Mixtral-8x7B-Instruct-v0.1 - FP8
20
+
21
+ - Model creator: [Mistral AI](https://huggingface.co/mistralai)
22
+ - Original model: [Mixtral-8x7B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1)
23
+
24
+ ## Description
25
+
26
+ This repo contains the Mixtral-8x7B-Instruct-v0.1 model quantized to FP8 by FriendliAI, significantly enhancing its inference efficiency while maintaining high accuracy.
27
+ Note that FP8 is only supported by NVIDIA Ada, Hopper, and Blackwell GPU architectures.
28
+ Check out [FriendliAI documentation](https://docs.friendli.ai/) for more details.
29
+
30
+ ## Compatibility
31
+
32
+ This model is compatible with **[Friendli Container](https://friendli.ai/products/container/)**.
33
+
34
+ ## Prerequisites
35
+
36
+ - Before you begin, make sure you have signed up for [Friendli Suite](https://suite.friendli.ai/). **You can use Friendli Containers free of charge for four weeks.**
37
+ - Prepare a Personal Access Token following [this guide](#preparing-personal-access-token).
38
+ - Prepare a Friendli Container Secret following [this guide](#preparing-container-secret).
39
+
40
+ ### Preparing Personal Access Token
41
+
42
+ PAT (Personal Access Token) is the user credential for for logging into our container registry.
43
+
44
+ 1. Sign in [Friendli Suite](https://suite.friendli.ai/).
45
+ 2. Go to **[User Settings > Tokens](https://suite.friendli.ai/user-settings/tokens)** and click **'Create new token'**.
46
+ 3. Save your created token value.
47
+
48
+ ### Pulling Friendli Container Image
49
+
50
+ 1. Log in to the Docker client using the personal access token created as outlined in [this guide](#preparing-personal-access-token).
51
+
52
+ ```sh
53
+ export FRIENDLI_PAT="YOUR PAT"
54
+ docker login registry.friendli.ai -u $YOUR_EMAIL -p $FRIENDLI_PAT
55
+ ```
56
+
57
+ 2. Pull image
58
+
59
+ ```sh
60
+ docker pull registry.friendli.ai/trial
61
+ ```
62
+
63
+ ## Running Friendli Container
64
+
65
+ Once you've prepared the image of Friendli Container, you can launch it to create a serving endpoint.
66
+
67
+ ```sh
68
+ docker run \
69
+ --gpus '"device=0"' \
70
+ -p 8000:8000 \
71
+ -v ~/.cache/huggingface:/root/.cache/huggingface \
72
+ -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
73
+ -e HF_TOKEN="YOUR HUGGING FACE TOKEN" \
74
+ registry.friendli.ai/trial \
75
+ --web-server-port 8000 \
76
+ --hf-model-name FriendliAI/Mixtral-8x7B-Instruct-v0.1-fp8
77
+ ```
78
+
79
+ ### Optimizing Inference Performance with Policy Search
80
+
81
+ To serve MoE models efficiently, it is required to run a policy search to explore the optimal execution policy:
82
+
83
+ ```sh
84
+ export POLICY_DIR=$PWD/policy
85
+
86
+ mkdir -p $POLICY_DIR
87
+
88
+ docker run \
89
+ --gpus $GPU_ENUMERATION \
90
+ -p 8000:8000 \
91
+ -v ~/.cache/huggingface:/root/.cache/huggingface \
92
+ -v $POLICY_DIR:/policy \
93
+ -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
94
+ registry.friendli.ai/trial \
95
+ --web-server-port 8000 \
96
+ --hf-model-name FriendliAI/Mixtral-8x7B-Instruct-v0.1-fp8 \
97
+ --algo-policy-dir /policy \
98
+ --search-policy true
99
+ ```
100
+
101
+ When the optimal policy is successfully searched, the policy is compiled into a policy file and saved at `$POLICY_DIR`.
102
+ Now you can create an inference endpoint with this optimal policy as follows:
103
+
104
+ ```sh
105
+ docker run \
106
+ --gpus $GPU_ENUMERATION \
107
+ -p 8000:8000 \
108
+ -v ~/.cache/huggingface:/root/.cache/huggingface \
109
+ -v $POLICY_DIR:/policy \
110
+ -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
111
+ registry.friendli.ai/trial \
112
+ --web-server-port 8000 \
113
+ --hf-model-name FriendliAI/Mixtral-8x7B-Instruct-v0.1-fp8 \
114
+ --algo-policy-dir /policy
115
+ ```
116
+
117
+ ---
118
+
119
+ # Original model card: MistralAI's Mixtr-8x7B Instruct v0.1
120
+
121
+ # Mixtral-8x7B
122
+ The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts. The Mixtral-8x7B outperforms Llama 2 70B on most benchmarks we tested.
123
+
124
+ For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
125
+
126
+ ## Warning
127
+ This repo contains weights that are compatible with [vLLM](https://github.com/vllm-project/vllm) serving of the model as well as Hugging Face [transformers](https://github.com/huggingface/transformers) library. It is based on the original Mixtral [torrent release](magnet:?xt=urn:btih:5546272da9065eddeb6fcd7ffddeef5b75be79a7&dn=mixtral-8x7b-32kseqlen&tr=udp%3A%2F%http://2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=http%3A%2F%http://2Ftracker.openbittorrent.com%3A80%2Fannounce), but the file format and parameter names are different. Please note that model cannot (yet) be instantiated with HF.
128
+
129
+ ## Instruction format
130
+
131
+ This format must be strictly respected, otherwise the model will generate sub-optimal outputs.
132
+
133
+ The template used to build a prompt for the Instruct model is defined as follows:
134
+ ```
135
+ <s> [INST] Instruction [/INST] Model answer</s> [INST] Follow-up instruction [/INST]
136
+ ```
137
+ Note that `<s>` and `</s>` are special tokens for beginning of string (BOS) and end of string (EOS) while [INST] and [/INST] are regular strings.
138
+
139
+ As reference, here is the pseudo-code used to tokenize instructions during fine-tuning:
140
+ ```python
141
+ def tokenize(text):
142
+ return tok.encode(text, add_special_tokens=False)
143
+
144
+ [BOS_ID] +
145
+ tokenize("[INST]") + tokenize(USER_MESSAGE_1) + tokenize("[/INST]") +
146
+ tokenize(BOT_MESSAGE_1) + [EOS_ID] +
147
+
148
+ tokenize("[INST]") + tokenize(USER_MESSAGE_N) + tokenize("[/INST]") +
149
+ tokenize(BOT_MESSAGE_N) + [EOS_ID]
150
+ ```
151
+
152
+ In the pseudo-code above, note that the `tokenize` method should not add a BOS or EOS token automatically, but should add a prefix space.
153
+
154
+ In the Transformers library, one can use [chat templates](https://huggingface.co/docs/transformers/main/en/chat_templating) which make sure the right format is applied.
155
+
156
+ ## Run the model
157
+
158
+ ```python
159
+ from transformers import AutoModelForCausalLM, AutoTokenizer
160
+
161
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
162
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
163
+
164
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
165
+
166
+ messages = [
167
+ {"role": "user", "content": "What is your favourite condiment?"},
168
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
169
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
170
+ ]
171
+
172
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
173
+
174
+ outputs = model.generate(inputs, max_new_tokens=20)
175
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
176
+ ```
177
+
178
+ By default, transformers will load the model in full precision. Therefore you might be interested to further reduce down the memory requirements to run the model through the optimizations we offer in HF ecosystem:
179
+
180
+ ### In half-precision
181
+
182
+ Note `float16` precision only works on GPU devices
183
+
184
+ <details>
185
+ <summary> Click to expand </summary>
186
+
187
+ ```diff
188
+ + import torch
189
+ from transformers import AutoModelForCausalLM, AutoTokenizer
190
+
191
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
192
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
193
+
194
+ + model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
195
+
196
+ messages = [
197
+ {"role": "user", "content": "What is your favourite condiment?"},
198
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
199
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
200
+ ]
201
+
202
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
203
+
204
+ outputs = model.generate(input_ids, max_new_tokens=20)
205
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
206
+ ```
207
+ </details>
208
+
209
+ ### Lower precision using (8-bit & 4-bit) using `bitsandbytes`
210
+
211
+ <details>
212
+ <summary> Click to expand </summary>
213
+
214
+ ```diff
215
+ + import torch
216
+ from transformers import AutoModelForCausalLM, AutoTokenizer
217
+
218
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
219
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
220
+
221
+ + model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, device_map="auto")
222
+
223
+ text = "Hello my name is"
224
+ messages = [
225
+ {"role": "user", "content": "What is your favourite condiment?"},
226
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
227
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
228
+ ]
229
+
230
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
231
+
232
+ outputs = model.generate(input_ids, max_new_tokens=20)
233
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
234
+ ```
235
+ </details>
236
+
237
+ ### Load the model with Flash Attention 2
238
+
239
+ <details>
240
+ <summary> Click to expand </summary>
241
+
242
+ ```diff
243
+ + import torch
244
+ from transformers import AutoModelForCausalLM, AutoTokenizer
245
+
246
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
247
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
248
+
249
+ + model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True, device_map="auto")
250
+
251
+ messages = [
252
+ {"role": "user", "content": "What is your favourite condiment?"},
253
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
254
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
255
+ ]
256
+
257
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
258
+
259
+ outputs = model.generate(input_ids, max_new_tokens=20)
260
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
261
+ ```
262
+ </details>
263
+
264
+ ## Limitations
265
+
266
+ The Mixtral-8x7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
267
+ It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
268
+ make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
269
+
270
+ # The Mistral AI Team
271
+ Albert Jiang, Alexandre Sablayrolles, Arthur Mensch, Blanche Savary, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Emma Bou Hanna, Florian Bressand, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Lélio Renard Lavaud, Louis Ternon, Lucile Saulnier, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Théophile Gervet, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed.