chripto commited on
Commit
a69e26d
·
verified ·
1 Parent(s): 6f3906b

Update README.md

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