seungahdev commited on
Commit
60eff07
1 Parent(s): 60edcfd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +220 -0
README.md ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: mistralai/Mixtral-8x7B-v0.1
4
+ inference: false
5
+ model_link: https://huggingface.co/mistralai/Mixtral-8x7B-v0.1
6
+ model_name: mistralai/Mixtral-8x7B-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-v0.1 - FP8
20
+
21
+ - Model creator: [Mistral AI](https://huggingface.co/mistralai)
22
+ - Original model: [Mixtral-8x7B-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1)
23
+
24
+ ## Description
25
+
26
+ This repo contains the Mixtral-8x7B-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
+ registry.friendli.ai/trial \
74
+ --web-server-port 8000 \
75
+ --hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8
76
+ ```
77
+
78
+ ### Optimizing Inference Performance with Policy Search
79
+
80
+ To serve MoE models efficiently, it is required to run a policy search to explore the optimal execution policy:
81
+
82
+ ```sh
83
+ export POLICY_DIR=$PWD/policy
84
+
85
+ mkdir -p $POLICY_DIR
86
+
87
+ docker run \
88
+ --gpus '"device=0"' \
89
+ -p 8000:8000 \
90
+ -v ~/.cache/huggingface:/root/.cache/huggingface \
91
+ -v $POLICY_DIR:/policy \
92
+ -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
93
+ registry.friendli.ai/trial \
94
+ --web-server-port 8000 \
95
+ --hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8 \
96
+ --algo-policy-dir /policy \
97
+ --search-policy true
98
+ ```
99
+
100
+ When the optimal policy is successfully searched, the policy is compiled into a policy file and saved at `$POLICY_DIR`.
101
+ Now you can create an inference endpoint with this optimal policy as follows:
102
+
103
+ ```sh
104
+ docker run \
105
+ --gpus '"device=0"' \
106
+ -p 8000:8000 \
107
+ -v ~/.cache/huggingface:/root/.cache/huggingface \
108
+ -v $POLICY_DIR:/policy \
109
+ -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
110
+ registry.friendli.ai/trial \
111
+ --web-server-port 8000 \
112
+ --hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8 \
113
+ --algo-policy-dir /policy
114
+ ```
115
+
116
+ ---
117
+
118
+ # Original model card: MistralAI's Mixtral-8x7B v0.1
119
+
120
+ # Model Card for Mixtral-8x7B
121
+ The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts. The Mistral-8x7B outperforms Llama 2 70B on most benchmarks we tested.
122
+
123
+ For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
124
+
125
+ ## Warning
126
+ 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.
127
+
128
+ ## Run the model
129
+
130
+
131
+ ```python
132
+ from transformers import AutoModelForCausalLM, AutoTokenizer
133
+
134
+ model_id = "mistralai/Mixtral-8x7B-v0.1"
135
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
136
+
137
+ model = AutoModelForCausalLM.from_pretrained(model_id)
138
+
139
+ text = "Hello my name is"
140
+ inputs = tokenizer(text, return_tensors="pt")
141
+
142
+ outputs = model.generate(**inputs, max_new_tokens=20)
143
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
144
+ ```
145
+
146
+ 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:
147
+
148
+ ### In half-precision
149
+
150
+ Note `float16` precision only works on GPU devices
151
+
152
+ <details>
153
+ <summary> Click to expand </summary>
154
+
155
+ ```diff
156
+ + import torch
157
+ from transformers import AutoModelForCausalLM, AutoTokenizer
158
+
159
+ model_id = "mistralai/Mixtral-8x7B-v0.1"
160
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
161
+
162
+ + model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16).to(0)
163
+
164
+ text = "Hello my name is"
165
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
166
+
167
+ outputs = model.generate(**inputs, max_new_tokens=20)
168
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
169
+ ```
170
+ </details>
171
+
172
+ ### Lower precision using (8-bit & 4-bit) using `bitsandbytes`
173
+
174
+ <details>
175
+ <summary> Click to expand </summary>
176
+
177
+ ```diff
178
+ + import torch
179
+ from transformers import AutoModelForCausalLM, AutoTokenizer
180
+
181
+ model_id = "mistralai/Mixtral-8x7B-v0.1"
182
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
183
+
184
+ + model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
185
+
186
+ text = "Hello my name is"
187
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
188
+
189
+ outputs = model.generate(**inputs, max_new_tokens=20)
190
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
191
+ ```
192
+ </details>
193
+
194
+ ### Load the model with Flash Attention 2
195
+
196
+ <details>
197
+ <summary> Click to expand </summary>
198
+
199
+ ```diff
200
+ + import torch
201
+ from transformers import AutoModelForCausalLM, AutoTokenizer
202
+
203
+ model_id = "mistralai/Mixtral-8x7B-v0.1"
204
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
205
+
206
+ + model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True)
207
+
208
+ text = "Hello my name is"
209
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
210
+
211
+ outputs = model.generate(**inputs, max_new_tokens=20)
212
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
213
+ ```
214
+ </details>
215
+
216
+ ## Notice
217
+ Mixtral-8x7B is a pretrained base model and therefore does not have any moderation mechanisms.
218
+
219
+ # The Mistral AI Team
220
+ 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.