nghiatrannnnnn commited on
Commit
2b09f8f
·
verified ·
1 Parent(s): a31d487

scorevision: push artifact

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