BRUNOPKGY7 commited on
Commit
f559e2b
·
verified ·
1 Parent(s): 780a8e3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +143 -3
README.md CHANGED
@@ -1,3 +1,143 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - finetuned
5
+ base_model: mistralai/Mistral-7B-v0.1
6
+ pipeline_tag: text-generation
7
+ inference: true
8
+ widget:
9
+ - messages:
10
+ - role: user
11
+ content: What is your favorite condiment?
12
+
13
+ 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>.
14
+ ---
15
+
16
+ # Model Card for Mistral-7B-Instruct-v0.1
17
+
18
+
19
+ ## Encode and Decode with `mistral_common`
20
+
21
+ ```py
22
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
23
+ from mistral_common.protocol.instruct.messages import UserMessage
24
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
25
+
26
+ mistral_models_path = "MISTRAL_MODELS_PATH"
27
+
28
+ tokenizer = MistralTokenizer.v1()
29
+
30
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
31
+
32
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
33
+ ```
34
+
35
+ ## Inference with `mistral_inference`
36
+
37
+ ```py
38
+ from mistral_inference.transformer import Transformer
39
+ from mistral_inference.generate import generate
40
+
41
+ model = Transformer.from_folder(mistral_models_path)
42
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
43
+
44
+ result = tokenizer.decode(out_tokens[0])
45
+
46
+ print(result)
47
+ ```
48
+
49
+ ## Inference with hugging face `transformers`
50
+
51
+ ```py
52
+ from transformers import AutoModelForCausalLM
53
+
54
+ model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
55
+ model.to("cuda")
56
+
57
+ generated_ids = model.generate(tokens, max_new_tokens=1000, do_sample=True)
58
+
59
+ # decode with mistral tokenizer
60
+ result = tokenizer.decode(generated_ids[0].tolist())
61
+ print(result)
62
+ ```
63
+
64
+ > [!TIP]
65
+ > 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!
66
+
67
+ ---
68
+
69
+ The Mistral-7B-Instruct-v0.1 Large Language Model (LLM) is a instruct fine-tuned version of the [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) generative text model using a variety of publicly available conversation datasets.
70
+
71
+ For full details of this model please read our [paper](https://arxiv.org/abs/2310.06825) and [release blog post](https://mistral.ai/news/announcing-mistral-7b/).
72
+
73
+ ## Instruction format
74
+
75
+ In order to leverage instruction fine-tuning, your prompt should be surrounded by `[INST]` and `[/INST]` tokens. The very first instruction should begin with a begin of sentence id. The next instructions should not. The assistant generation will be ended by the end-of-sentence token id.
76
+
77
+ E.g.
78
+ ```
79
+ text = "<s>[INST] What is your favourite condiment? [/INST]"
80
+ "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!</s> "
81
+ "[INST] Do you have mayonnaise recipes? [/INST]"
82
+ ```
83
+
84
+ This format is available as a [chat template](https://huggingface.co/docs/transformers/main/chat_templating) via the `apply_chat_template()` method:
85
+
86
+ ```python
87
+ from transformers import AutoModelForCausalLM, AutoTokenizer
88
+
89
+ device = "cuda" # the device to load the model onto
90
+
91
+ model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
92
+ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
93
+
94
+ messages = [
95
+ {"role": "user", "content": "What is your favourite condiment?"},
96
+ {"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!"},
97
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
98
+ ]
99
+
100
+ encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
101
+
102
+ model_inputs = encodeds.to(device)
103
+ model.to(device)
104
+
105
+ generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
106
+ decoded = tokenizer.batch_decode(generated_ids)
107
+ print(decoded[0])
108
+ ```
109
+
110
+ ## Model Architecture
111
+ This instruction model is based on Mistral-7B-v0.1, a transformer model with the following architecture choices:
112
+ - Grouped-Query Attention
113
+ - Sliding-Window Attention
114
+ - Byte-fallback BPE tokenizer
115
+
116
+ ## Troubleshooting
117
+ - If you see the following error:
118
+ ```
119
+ Traceback (most recent call last):
120
+ File "", line 1, in
121
+ File "/transformers/models/auto/auto_factory.py", line 482, in from_pretrained
122
+ config, kwargs = AutoConfig.from_pretrained(
123
+ File "/transformers/models/auto/configuration_auto.py", line 1022, in from_pretrained
124
+ config_class = CONFIG_MAPPING[config_dict["model_type"]]
125
+ File "/transformers/models/auto/configuration_auto.py", line 723, in getitem
126
+ raise KeyError(key)
127
+ KeyError: 'mistral'
128
+ ```
129
+
130
+ Installing transformers from source should solve the issue
131
+ pip install git+https://github.com/huggingface/transformers
132
+
133
+ This should not be required after transformers-v4.33.4.
134
+
135
+ ## Limitations
136
+
137
+ The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
138
+ It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
139
+ make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
140
+
141
+ ## The Mistral AI Team
142
+
143
+ Albert Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lélio Renard Lavaud, Lucile Saulnier, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed.