Update README.md
Browse files
README.md
CHANGED
@@ -1 +1,67 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
license: apache-2.0
|
5 |
+
base_model: mistralai/Mixtral-8x7B-v0.1
|
6 |
+
inference:
|
7 |
+
parameters:
|
8 |
+
temperature: 0.5
|
9 |
+
widget:
|
10 |
+
- messages:
|
11 |
+
- role: user
|
12 |
+
content: What is your favorite condiment?
|
13 |
+
|
14 |
+
---
|
15 |
+
# Model Card for Mixtral-8x7B
|
16 |
+
|
17 |
+
## Instruction format
|
18 |
+
|
19 |
+
This format must be strictly respected, otherwise the model will generate sub-optimal outputs.
|
20 |
+
|
21 |
+
The template used to build a prompt for the Instruct model is defined as follows:
|
22 |
+
```
|
23 |
+
<s> [INST] Instruction [/INST] Model answer</s> [INST] Follow-up instruction [/INST]
|
24 |
+
```
|
25 |
+
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.
|
26 |
+
|
27 |
+
As reference, here is the pseudo-code used to tokenize instructions during fine-tuning:
|
28 |
+
```python
|
29 |
+
def tokenize(text):
|
30 |
+
return tok.encode(text, add_special_tokens=False)
|
31 |
+
|
32 |
+
[BOS_ID] +
|
33 |
+
tokenize("[INST]") + tokenize(USER_MESSAGE_1) + tokenize("[/INST]") +
|
34 |
+
tokenize(BOT_MESSAGE_1) + [EOS_ID] +
|
35 |
+
…
|
36 |
+
tokenize("[INST]") + tokenize(USER_MESSAGE_N) + tokenize("[/INST]") +
|
37 |
+
tokenize(BOT_MESSAGE_N) + [EOS_ID]
|
38 |
+
```
|
39 |
+
|
40 |
+
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.
|
41 |
+
|
42 |
+
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.
|
43 |
+
|
44 |
+
<details>
|
45 |
+
<summary> Click to expand </summary>
|
46 |
+
|
47 |
+
```diff
|
48 |
+
+ import torch
|
49 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
50 |
+
|
51 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
52 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
53 |
+
|
54 |
+
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
55 |
+
|
56 |
+
messages = [
|
57 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
58 |
+
{"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!"},
|
59 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
60 |
+
]
|
61 |
+
|
62 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
63 |
+
|
64 |
+
outputs = model.generate(input_ids, max_new_tokens=20)
|
65 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
66 |
+
```
|
67 |
+
</details>
|