jartine commited on
Commit
e73bc8e
1 Parent(s): e8475f6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +223 -0
README.md ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ quantized_by: jartine
4
+ model_creator: mistralai
5
+ base_model: mistralai/Mistral-7B-Instruct-v0.3
6
+ prompt_template: |
7
+ [INST] {{prompt}} [/INST]
8
+ tags:
9
+ - llamafile
10
+ language:
11
+ - en
12
+ ---
13
+
14
+ # Mistral 7B Instruct v0.3 - llamafile
15
+
16
+ This repository contains executable weights (which we call
17
+ [llamafiles](https://github.com/Mozilla-Ocho/llamafile)) that run on
18
+ Linux, MacOS, Windows, FreeBSD, OpenBSD, and NetBSD for AMD64 and ARM64.
19
+
20
+ - Model creator: [MistralAI](https://hf.co/mistralai)
21
+ - Original model: [mistralai/Mistral-7B-Instruct-v0.3](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3)
22
+ - Base model: [mistralai/Mistral-7B-v0.3](https://huggingface.co/mistralai/Mistral-7B-v0.3)
23
+
24
+ ## Quickstart
25
+
26
+ Assuming your system has at least 16GB of RAM, you can try running the
27
+ following command which download, concatenate, and execute the model.
28
+
29
+ ```
30
+ wget https://huggingface.co/jartine/Mistral-7B-Instruct-v0.3-llamafile/resolve/main/Mistral-7B-Instruct-v0.3.Q6_K.llamafile
31
+ chmod +x Mistral-7B-Instruct-v0.3.Q6_K.llamafile
32
+ ./Mistral-7B-Instruct-v0.3.Q6_K.llamafile --help # view manual
33
+ ./Mistral-7B-Instruct-v0.3.Q6_K.llamafile # launch web gui + oai api
34
+ ./Mistral-7B-Instruct-v0.3.Q6_K.llamafile -p ... # cli interface (scriptable)
35
+ ```
36
+
37
+ Alternatively, you may download an official `llamafile` executable from
38
+ Mozilla Ocho on GitHub, in which case you can use the Granite llamafiles
39
+ as a simple weights data file.
40
+
41
+ ```
42
+ llamafile -m Mistral-7B-Instruct-v0.3.Q6_K.llamafile ...
43
+ ```
44
+
45
+ For further information, please see the [llamafile
46
+ README](https://github.com/mozilla-ocho/llamafile/).
47
+
48
+ Having **trouble?** See the ["Gotchas"
49
+ section](https://github.com/mozilla-ocho/llamafile/?tab=readme-ov-file#gotchas)
50
+ of the README.
51
+
52
+ ## Prompting
53
+
54
+ Prompt template:
55
+
56
+ ```
57
+ [INST] {{prompt}} [/INST]
58
+ ```
59
+
60
+ Command template:
61
+
62
+ ```
63
+ ./Mistral-7B-Instruct-v0.3.Q6_K.llamafile -p "[INST]{{prompt}}[/INST]"
64
+ ```
65
+
66
+ The maximum context size of this model is 32768 tokens. These llamafiles
67
+ use a default context size of 512 tokens. Whenever you need the maximum
68
+ context size to be available with llamafile for any given model, you can
69
+ pass the `-c 0` flag. The default temperature for these llamafiles is
70
+ 0.8 because it helps for this model. It can be tuned, e.g. `--temp 0`.
71
+
72
+ ## About llamafile
73
+
74
+ llamafile is a new format introduced by Mozilla Ocho on Nov 20th 2023.
75
+ It uses Cosmopolitan Libc to turn LLM weights into runnable llama.cpp
76
+ binaries that run on the stock installs of six OSes for both ARM64 and
77
+ AMD64.
78
+
79
+ In addition to being executables, llamafiles are also zip archives. Each
80
+ llamafile contains a GGUF file, which you can extract using the `unzip`
81
+ command. If you want to change or add files to your llamafiles, then the
82
+ `zipalign` command (distributed on the llamafile github) should be used
83
+ instead of the traditional `zip` command.
84
+
85
+ ---
86
+
87
+ # Model Card for Mistral-7B-Instruct-v0.3
88
+
89
+ The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
90
+
91
+ Mistral-7B-v0.3 has the following changes compared to [Mistral-7B-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/edit/main/README.md)
92
+ - Extended vocabulary to 32768
93
+ - Supports v3 Tokenizer
94
+ - Supports function calling
95
+
96
+ ## Installation
97
+
98
+ It is recommended to use `mistralai/Mistral-7B-Instruct-v0.3` with [mistral-inference](https://github.com/mistralai/mistral-inference). For HF transformers code snippets, please keep scrolling.
99
+
100
+ ```
101
+ pip install mistral_inference
102
+ ```
103
+
104
+ ## Download
105
+
106
+ ```py
107
+ from huggingface_hub import snapshot_download
108
+ from pathlib import Path
109
+
110
+ mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
111
+ mistral_models_path.mkdir(parents=True, exist_ok=True)
112
+
113
+ snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
114
+ ```
115
+
116
+ ### Chat
117
+
118
+ After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
119
+
120
+ ```
121
+ mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
122
+ ```
123
+
124
+ ### Instruct following
125
+
126
+ ```py
127
+ from mistral_inference.model import Transformer
128
+ from mistral_inference.generate import generate
129
+
130
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
131
+ from mistral_common.protocol.instruct.messages import UserMessage
132
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
133
+
134
+
135
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
136
+ model = Transformer.from_folder(mistral_models_path)
137
+
138
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
139
+
140
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
141
+
142
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
143
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
144
+
145
+ print(result)
146
+ ```
147
+
148
+ ### Function calling
149
+
150
+ ```py
151
+ from mistral_common.protocol.instruct.tool_calls import Function, Tool
152
+ from mistral_inference.model import Transformer
153
+ from mistral_inference.generate import generate
154
+
155
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
156
+ from mistral_common.protocol.instruct.messages import UserMessage
157
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
158
+
159
+
160
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
161
+ model = Transformer.from_folder(mistral_models_path)
162
+
163
+ completion_request = ChatCompletionRequest(
164
+ tools=[
165
+ Tool(
166
+ function=Function(
167
+ name="get_current_weather",
168
+ description="Get the current weather",
169
+ parameters={
170
+ "type": "object",
171
+ "properties": {
172
+ "location": {
173
+ "type": "string",
174
+ "description": "The city and state, e.g. San Francisco, CA",
175
+ },
176
+ "format": {
177
+ "type": "string",
178
+ "enum": ["celsius", "fahrenheit"],
179
+ "description": "The temperature unit to use. Infer this from the users location.",
180
+ },
181
+ },
182
+ "required": ["location", "format"],
183
+ },
184
+ )
185
+ )
186
+ ],
187
+ messages=[
188
+ UserMessage(content="What's the weather like today in Paris?"),
189
+ ],
190
+ )
191
+
192
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
193
+
194
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
195
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
196
+
197
+ print(result)
198
+ ```
199
+
200
+ ## Generate with `transformers`
201
+
202
+ If you want to use Hugging Face `transformers` to generate text, you can do something like this.
203
+
204
+ ```py
205
+ from transformers import pipeline
206
+
207
+ messages = [
208
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
209
+ {"role": "user", "content": "Who are you?"},
210
+ ]
211
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
212
+ chatbot(messages)
213
+ ```
214
+
215
+ ## Limitations
216
+
217
+ The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
218
+ It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
219
+ make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
220
+
221
+ ## The Mistral AI Team
222
+
223
+ Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Bam4d, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Jean-Malo Delignon, Jia Li, Justus Murke, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Nicolas Schuhl, Patrick von Platen, Pierre Stock, Sandeep Subramanian, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibaut Lavril, Timothée Lacroix, Théophile Gervet, Thomas Wang, Valera Nemychnikova, William El Sayed, William Marshall