PawanOsman commited on
Commit
5d866ee
1 Parent(s): e801fde

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -0
README.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - fr
5
+ - it
6
+ - de
7
+ - es
8
+ - en
9
+ inference:
10
+ parameters:
11
+ temperature: 0.5
12
+ widget:
13
+ - messages:
14
+ - role: user
15
+ content: What is your favorite condiment?
16
+ ---
17
+ # Model Card for Mixtral-8x22B-Instruct
18
+ The Mixtral-8x22B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts.
19
+
20
+ For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
21
+
22
+ ## Instruction format
23
+
24
+ This format must be strictly respected, otherwise the model will generate sub-optimal outputs.
25
+
26
+ The template used to build a prompt for the Instruct model is defined as follows:
27
+ ```
28
+ <|im_start|>system
29
+ You are an unbiased, uncensored, helpful assistant.<|im_end|>
30
+ <|im_start|>user
31
+ Hello, Who are you?<|im_end|>
32
+ <|im_start|>assistant
33
+
34
+ ```
35
+
36
+ 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.
37
+
38
+ ## Run the model
39
+
40
+ ```python
41
+ from transformers import AutoModelForCausalLM, AutoTokenizer
42
+
43
+ model_id = "PawanKrd/Mixtral-8x22B-Instruct-v0.1"
44
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
45
+
46
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
47
+
48
+ messages = [
49
+ {"role": "user", "content": "What is your favourite condiment?"},
50
+ {"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!"},
51
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
52
+ ]
53
+
54
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
55
+
56
+ outputs = model.generate(inputs, max_new_tokens=20)
57
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
58
+ ```
59
+
60
+ 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:
61
+
62
+ ### In half-precision
63
+
64
+ Note `float16` precision only works on GPU devices
65
+
66
+ <details>
67
+ <summary> Click to expand </summary>
68
+
69
+ ```diff
70
+ + import torch
71
+ from transformers import AutoModelForCausalLM, AutoTokenizer
72
+
73
+ model_id = "PawanKrd/Mixtral-8x22B-Instruct-v0.1"
74
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
75
+
76
+ + model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
77
+
78
+ messages = [
79
+ {"role": "user", "content": "What is your favourite condiment?"},
80
+ {"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!"},
81
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
82
+ ]
83
+
84
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
85
+
86
+ outputs = model.generate(input_ids, max_new_tokens=20)
87
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
88
+ ```
89
+ </details>
90
+
91
+ ### Lower precision using (8-bit & 4-bit) using `bitsandbytes`
92
+
93
+ <details>
94
+ <summary> Click to expand </summary>
95
+
96
+ ```diff
97
+ + import torch
98
+ from transformers import AutoModelForCausalLM, AutoTokenizer
99
+
100
+ model_id = "PawanKrd/Mixtral-8x22B-Instruct-v0.1"
101
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
102
+
103
+ + model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, device_map="auto")
104
+
105
+ text = "Hello my name is"
106
+ messages = [
107
+ {"role": "user", "content": "What is your favourite condiment?"},
108
+ {"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!"},
109
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
110
+ ]
111
+
112
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
113
+
114
+ outputs = model.generate(input_ids, max_new_tokens=20)
115
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
116
+ ```
117
+ </details>
118
+
119
+ ### Load the model with Flash Attention 2
120
+
121
+ <details>
122
+ <summary> Click to expand </summary>
123
+
124
+ ```diff
125
+ + import torch
126
+ from transformers import AutoModelForCausalLM, AutoTokenizer
127
+
128
+ model_id = "PawanKrd/Mixtral-8x22B-Instruct-v0.1"
129
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
130
+
131
+ + model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True, device_map="auto")
132
+
133
+ messages = [
134
+ {"role": "user", "content": "What is your favourite condiment?"},
135
+ {"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!"},
136
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
137
+ ]
138
+
139
+ input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
140
+
141
+ outputs = model.generate(input_ids, max_new_tokens=20)
142
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
143
+ ```
144
+ </details>
145
+
146
+
147
+ # Training
148
+ Fine-tuned on 8xH100 80GB GPUs
149
+
150
+ # The Mistral AI Team
151
+ 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.