Update README.md (#224)
Browse files- Update README.md (fe95b00fbbd8d765d66350eba58a2c428f379ab9)
README.md
CHANGED
|
@@ -21,46 +21,54 @@ widget:
|
|
| 21 |
> [!CAUTION]
|
| 22 |
> ⚠️
|
| 23 |
> The `transformers` tokenizer might give incorrect results as it has not been tested by the Mistral team. To make sure that your encoding and decoding is correct, please use mistral-common as shown below:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
> 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!
|
| 63 |
-
|
| 64 |
|
| 65 |
---
|
| 66 |
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.
|
|
|
|
| 21 |
> [!CAUTION]
|
| 22 |
> ⚠️
|
| 23 |
> The `transformers` tokenizer might give incorrect results as it has not been tested by the Mistral team. To make sure that your encoding and decoding is correct, please use mistral-common as shown below:
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
```py
|
| 27 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
| 28 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
| 29 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
| 30 |
+
|
| 31 |
+
mistral_models_path = "MISTRAL_MODELS_PATH"
|
| 32 |
+
|
| 33 |
+
tokenizer = MistralTokenizer.v1()
|
| 34 |
+
|
| 35 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
|
| 36 |
+
|
| 37 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## Inference with `mistral_inference`
|
| 41 |
+
|
| 42 |
+
```py
|
| 43 |
+
from mistral_inference.model import Transformer
|
| 44 |
+
from mistral_inference.generate import generate
|
| 45 |
+
|
| 46 |
+
model = Transformer.from_folder(mistral_models_path)
|
| 47 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
| 48 |
+
|
| 49 |
+
result = tokenizer.decode(out_tokens[0])
|
| 50 |
+
|
| 51 |
+
print(result)
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Inference with hugging face `transformers`
|
| 55 |
+
|
| 56 |
+
```py
|
| 57 |
+
from transformers import AutoModelForCausalLM
|
| 58 |
+
|
| 59 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 60 |
+
model.to("cuda")
|
| 61 |
+
|
| 62 |
+
generated_ids = model.generate(tokens, max_new_tokens=1000, do_sample=True)
|
| 63 |
+
|
| 64 |
+
# decode with mistral tokenizer
|
| 65 |
+
result = tokenizer.decode(generated_ids[0].tolist())
|
| 66 |
+
print(result)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
> [!TIP]
|
| 70 |
> 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!
|
| 71 |
+
|
| 72 |
|
| 73 |
---
|
| 74 |
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.
|