ybelkada commited on
Commit
5a1a6cb
·
1 Parent(s): a37e3ed

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +88 -1
README.md CHANGED
@@ -13,7 +13,7 @@ The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mi
13
  For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
14
 
15
  ## Warning
16
- This repo contains weights that are compatible with [vLLM](https://github.com/vllm-project/vllm) serving of the model. 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.
17
 
18
  ## Instruction format
19
 
@@ -40,6 +40,93 @@ tokenize(BOT_MESSAGE_N) + [EOS_ID]
40
 
41
  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.
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ## Limitations
44
 
45
  The Mixtral-8x7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
 
13
  For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/).
14
 
15
  ## Warning
16
+ 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.
17
 
18
  ## Instruction format
19
 
 
40
 
41
  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.
42
 
43
+ ## Run the model
44
+
45
+ ```python
46
+ from transformers import AutoModelForCausalLM, AutoTokenizer
47
+
48
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
49
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
50
+
51
+ model = AutoModelForCausalLM.from_pretrained(model_id)
52
+
53
+ text = "Hello my name is"
54
+ inputs = tokenizer(text, return_tensors="pt")
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 = "mistralai/Mixtral-8x7B-Instruct-v0.1"
74
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
75
+
76
+ + model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16).to(0)
77
+
78
+ text = "Hello my name is"
79
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
80
+
81
+ outputs = model.generate(**inputs, max_new_tokens=20)
82
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
83
+ ```
84
+ </details>
85
+
86
+ ### Lower precision using (8-bit & 4-bit) using `bitsandbytes`
87
+
88
+ <details>
89
+ <summary> Click to expand </summary>
90
+
91
+ ```diff
92
+ + import torch
93
+ from transformers import AutoModelForCausalLM, AutoTokenizer
94
+
95
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
96
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
97
+
98
+ + model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
99
+
100
+ text = "Hello my name is"
101
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
102
+
103
+ outputs = model.generate(**inputs, max_new_tokens=20)
104
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
105
+ ```
106
+ </details>
107
+
108
+ ### Load the model with Flash Attention 2
109
+
110
+ <details>
111
+ <summary> Click to expand </summary>
112
+
113
+ ```diff
114
+ + import torch
115
+ from transformers import AutoModelForCausalLM, AutoTokenizer
116
+
117
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
118
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
119
+
120
+ + model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True)
121
+
122
+ text = "Hello my name is"
123
+ + inputs = tokenizer(text, return_tensors="pt").to(0)
124
+
125
+ outputs = model.generate(**inputs, max_new_tokens=20)
126
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
127
+ ```
128
+ </details>
129
+
130
  ## Limitations
131
 
132
  The Mixtral-8x7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.