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|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- fr
|
4 |
+
- it
|
5 |
+
- de
|
6 |
+
- es
|
7 |
+
- en
|
8 |
+
license: apache-2.0
|
9 |
+
base_model: mistralai/Mixtral-8x7B-v0.1
|
10 |
+
inference:
|
11 |
+
parameters:
|
12 |
+
temperature: 0.5
|
13 |
+
widget:
|
14 |
+
- messages:
|
15 |
+
- role: user
|
16 |
+
content: What is your favorite condiment?
|
17 |
+
|
18 |
+
extra_gated_description: If you want to learn more about how we process your personal data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
|
19 |
+
---
|
20 |
+
|
21 |
+
# Quantized Version of mistralai/Mixtral-8x7B-Instruct-v0.1
|
22 |
+
|
23 |
+
This model is a quantized variant of the mistralai/Mixtral-8x7B-Instruct-v0.1 model, optimized for use with Jlama, a Java-based inference engine. The quantization process reduces the model's size and improves inference speed, while maintaining high accuracy for efficient deployment in production environments.
|
24 |
+
|
25 |
+
For more information on Jlama, visit the [Jlama GitHub repository](https://github.com/tjake/jlama).
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
|
30 |
+
# Model Card for Mixtral-8x7B
|
31 |
+
|
32 |
+
### Tokenization with `mistral-common`
|
33 |
+
|
34 |
+
```py
|
35 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
36 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
37 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
38 |
+
|
39 |
+
mistral_models_path = "MISTRAL_MODELS_PATH"
|
40 |
+
|
41 |
+
tokenizer = MistralTokenizer.v1()
|
42 |
+
|
43 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
|
44 |
+
|
45 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
46 |
+
```
|
47 |
+
|
48 |
+
## Inference with `mistral_inference`
|
49 |
+
|
50 |
+
```py
|
51 |
+
from mistral_inference.transformer import Transformer
|
52 |
+
from mistral_inference.generate import generate
|
53 |
+
|
54 |
+
model = Transformer.from_folder(mistral_models_path)
|
55 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
56 |
+
|
57 |
+
result = tokenizer.decode(out_tokens[0])
|
58 |
+
|
59 |
+
print(result)
|
60 |
+
```
|
61 |
+
|
62 |
+
## Inference with hugging face `transformers`
|
63 |
+
|
64 |
+
```py
|
65 |
+
from transformers import AutoModelForCausalLM
|
66 |
+
|
67 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
68 |
+
model.to("cuda")
|
69 |
+
|
70 |
+
generated_ids = model.generate(tokens, max_new_tokens=1000, do_sample=True)
|
71 |
+
|
72 |
+
# decode with mistral tokenizer
|
73 |
+
result = tokenizer.decode(generated_ids[0].tolist())
|
74 |
+
print(result)
|
75 |
+
```
|
76 |
+
|
77 |
+
> [!TIP]
|
78 |
+
> PRs to correct the transformers tokenizer so that it gives 1-to-1 the same results as the mistral-common reference implementation are very welcome!
|
79 |
+
|
80 |
+
|
81 |
+
---
|
82 |
+
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.
|
83 |
+
|
84 |
+
For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
|
85 |
+
|
86 |
+
## Warning
|
87 |
+
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.
|
88 |
+
|
89 |
+
## Instruction format
|
90 |
+
|
91 |
+
This format must be strictly respected, otherwise the model will generate sub-optimal outputs.
|
92 |
+
|
93 |
+
The template used to build a prompt for the Instruct model is defined as follows:
|
94 |
+
```
|
95 |
+
<s> [INST] Instruction [/INST] Model answer</s> [INST] Follow-up instruction [/INST]
|
96 |
+
```
|
97 |
+
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.
|
98 |
+
|
99 |
+
As reference, here is the pseudo-code used to tokenize instructions during fine-tuning:
|
100 |
+
```python
|
101 |
+
def tokenize(text):
|
102 |
+
return tok.encode(text, add_special_tokens=False)
|
103 |
+
|
104 |
+
[BOS_ID] +
|
105 |
+
tokenize("[INST]") + tokenize(USER_MESSAGE_1) + tokenize("[/INST]") +
|
106 |
+
tokenize(BOT_MESSAGE_1) + [EOS_ID] +
|
107 |
+
…
|
108 |
+
tokenize("[INST]") + tokenize(USER_MESSAGE_N) + tokenize("[/INST]") +
|
109 |
+
tokenize(BOT_MESSAGE_N) + [EOS_ID]
|
110 |
+
```
|
111 |
+
|
112 |
+
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.
|
113 |
+
|
114 |
+
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.
|
115 |
+
|
116 |
+
## Run the model
|
117 |
+
|
118 |
+
```python
|
119 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
120 |
+
|
121 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
122 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
123 |
+
|
124 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
125 |
+
|
126 |
+
messages = [
|
127 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
128 |
+
{"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!"},
|
129 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
130 |
+
]
|
131 |
+
|
132 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
133 |
+
|
134 |
+
outputs = model.generate(inputs, max_new_tokens=20)
|
135 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
136 |
+
```
|
137 |
+
|
138 |
+
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:
|
139 |
+
|
140 |
+
### In half-precision
|
141 |
+
|
142 |
+
Note `float16` precision only works on GPU devices
|
143 |
+
|
144 |
+
<details>
|
145 |
+
<summary> Click to expand </summary>
|
146 |
+
|
147 |
+
```diff
|
148 |
+
+ import torch
|
149 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
150 |
+
|
151 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
152 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
153 |
+
|
154 |
+
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
155 |
+
|
156 |
+
messages = [
|
157 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
158 |
+
{"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!"},
|
159 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
160 |
+
]
|
161 |
+
|
162 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
163 |
+
|
164 |
+
outputs = model.generate(input_ids, max_new_tokens=20)
|
165 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
166 |
+
```
|
167 |
+
</details>
|
168 |
+
|
169 |
+
### Lower precision using (8-bit & 4-bit) using `bitsandbytes`
|
170 |
+
|
171 |
+
<details>
|
172 |
+
<summary> Click to expand </summary>
|
173 |
+
|
174 |
+
```diff
|
175 |
+
+ import torch
|
176 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
177 |
+
|
178 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
179 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
180 |
+
|
181 |
+
+ model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, device_map="auto")
|
182 |
+
|
183 |
+
text = "Hello my name is"
|
184 |
+
messages = [
|
185 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
186 |
+
{"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!"},
|
187 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
188 |
+
]
|
189 |
+
|
190 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
191 |
+
|
192 |
+
outputs = model.generate(input_ids, max_new_tokens=20)
|
193 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
194 |
+
```
|
195 |
+
</details>
|
196 |
+
|
197 |
+
### Load the model with Flash Attention 2
|
198 |
+
|
199 |
+
<details>
|
200 |
+
<summary> Click to expand </summary>
|
201 |
+
|
202 |
+
```diff
|
203 |
+
+ import torch
|
204 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
205 |
+
|
206 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
207 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
208 |
+
|
209 |
+
+ model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True, device_map="auto")
|
210 |
+
|
211 |
+
messages = [
|
212 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
213 |
+
{"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!"},
|
214 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
215 |
+
]
|
216 |
+
|
217 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
218 |
+
|
219 |
+
outputs = model.generate(input_ids, max_new_tokens=20)
|
220 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
221 |
+
```
|
222 |
+
</details>
|
223 |
+
|
224 |
+
## Limitations
|
225 |
+
|
226 |
+
The Mixtral-8x7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
|
227 |
+
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
|
228 |
+
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
|
229 |
+
|
230 |
+
# The Mistral AI Team
|
231 |
+
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.
|
config.json
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"MixtralForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_dropout": 0.0,
|
6 |
+
"bos_token_id": 1,
|
7 |
+
"eos_token_id": 2,
|
8 |
+
"hidden_act": "silu",
|
9 |
+
"hidden_size": 4096,
|
10 |
+
"initializer_range": 0.02,
|
11 |
+
"intermediate_size": 14336,
|
12 |
+
"max_position_embeddings": 32768,
|
13 |
+
"model_type": "mixtral",
|
14 |
+
"num_attention_heads": 32,
|
15 |
+
"num_experts_per_tok": 2,
|
16 |
+
"num_hidden_layers": 32,
|
17 |
+
"num_key_value_heads": 8,
|
18 |
+
"num_local_experts": 8,
|
19 |
+
"output_router_logits": false,
|
20 |
+
"rms_norm_eps": 1e-05,
|
21 |
+
"rope_theta": 1000000.0,
|
22 |
+
"router_aux_loss_coef": 0.02,
|
23 |
+
"sliding_window": null,
|
24 |
+
"tie_word_embeddings": false,
|
25 |
+
"torch_dtype": "bfloat16",
|
26 |
+
"transformers_version": "4.36.0.dev0",
|
27 |
+
"use_cache": true,
|
28 |
+
"vocab_size": 32000
|
29 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7627a04d6907ba9f7571483bfd120cb268509e36b1749396f565ad0ac2c3d91b
|
3 |
+
size 29189860838
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"add_prefix_space": null,
|
5 |
+
"added_tokens_decoder": {
|
6 |
+
"0": {
|
7 |
+
"content": "<unk>",
|
8 |
+
"lstrip": false,
|
9 |
+
"normalized": false,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false,
|
12 |
+
"special": true
|
13 |
+
},
|
14 |
+
"1": {
|
15 |
+
"content": "<s>",
|
16 |
+
"lstrip": false,
|
17 |
+
"normalized": false,
|
18 |
+
"rstrip": false,
|
19 |
+
"single_word": false,
|
20 |
+
"special": true
|
21 |
+
},
|
22 |
+
"2": {
|
23 |
+
"content": "</s>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": false,
|
26 |
+
"rstrip": false,
|
27 |
+
"single_word": false,
|
28 |
+
"special": true
|
29 |
+
}
|
30 |
+
},
|
31 |
+
"additional_special_tokens": [],
|
32 |
+
"bos_token": "<s>",
|
33 |
+
"chat_template": "{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n{%- endif %}\n\n{{- bos_token }}\n{%- for message in loop_messages %}\n {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}\n {{- raise_exception('After the optional system message, conversation roles must alternate user/assistant/user/assistant/...') }}\n {%- endif %}\n {%- if message['role'] == 'user' %}\n {%- if loop.first and system_message is defined %}\n {{- ' [INST] ' + system_message + '\\n\\n' + message['content'] + ' [/INST]' }}\n {%- else %}\n {{- ' [INST] ' + message['content'] + ' [/INST]' }}\n {%- endif %}\n {%- elif message['role'] == 'assistant' %}\n {{- ' ' + message['content'] + eos_token}}\n {%- else %}\n {{- raise_exception('Only user and assistant roles are supported, with the exception of an initial optional system message!') }}\n {%- endif %}\n{%- endfor %}\n",
|
34 |
+
"clean_up_tokenization_spaces": false,
|
35 |
+
"eos_token": "</s>",
|
36 |
+
"legacy": false,
|
37 |
+
"model_max_length": 1000000000000000019884624838656,
|
38 |
+
"pad_token": null,
|
39 |
+
"sp_model_kwargs": {},
|
40 |
+
"spaces_between_special_tokens": false,
|
41 |
+
"tokenizer_class": "LlamaTokenizer",
|
42 |
+
"unk_token": "<unk>",
|
43 |
+
"use_default_system_prompt": false
|
44 |
+
}
|