tjake commited on
Commit
1fe9e91
1 Parent(s): c5099c2

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. README.md +204 -0
  2. config.json +25 -0
  3. model.safetensors +3 -0
  4. tokenizer.json +0 -0
  5. tokenizer_config.json +0 -0
README.md ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: mistralai/Mistral-7B-v0.3
4
+ 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>.
5
+ ---
6
+
7
+ # Quantized Version of mistralai/Mistral-7B-Instruct-v0.3
8
+
9
+ This model is a quantized variant of the mistralai/Mistral-7B-Instruct-v0.3 model, optimized for use with Jlama, a Java-based inference engine. The quantization process reduces the model's size and improves inference speed, while maintaining high accuracy for efficient deployment in production environments.
10
+
11
+ For more information on Jlama, visit the [Jlama GitHub repository](https://github.com/tjake/jlama).
12
+
13
+ ---
14
+
15
+
16
+
17
+ # Model Card for Mistral-7B-Instruct-v0.3
18
+
19
+ The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
20
+
21
+ 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)
22
+ - Extended vocabulary to 32768
23
+ - Supports v3 Tokenizer
24
+ - Supports function calling
25
+
26
+ ## Installation
27
+
28
+ 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.
29
+
30
+ ```
31
+ pip install mistral_inference
32
+ ```
33
+
34
+ ## Download
35
+
36
+ ```py
37
+ from huggingface_hub import snapshot_download
38
+ from pathlib import Path
39
+
40
+ mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
41
+ mistral_models_path.mkdir(parents=True, exist_ok=True)
42
+
43
+ snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
44
+ ```
45
+
46
+ ### Chat
47
+
48
+ After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
49
+
50
+ ```
51
+ mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
52
+ ```
53
+
54
+ ### Instruct following
55
+
56
+ ```py
57
+ from mistral_inference.transformer import Transformer
58
+ from mistral_inference.generate import generate
59
+
60
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
61
+ from mistral_common.protocol.instruct.messages import UserMessage
62
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
63
+
64
+
65
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
66
+ model = Transformer.from_folder(mistral_models_path)
67
+
68
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
69
+
70
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
71
+
72
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
73
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
74
+
75
+ print(result)
76
+ ```
77
+
78
+ ### Function calling
79
+
80
+ ```py
81
+ from mistral_common.protocol.instruct.tool_calls import Function, Tool
82
+ from mistral_inference.transformer import Transformer
83
+ from mistral_inference.generate import generate
84
+
85
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
86
+ from mistral_common.protocol.instruct.messages import UserMessage
87
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
88
+
89
+
90
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
91
+ model = Transformer.from_folder(mistral_models_path)
92
+
93
+ completion_request = ChatCompletionRequest(
94
+ tools=[
95
+ Tool(
96
+ function=Function(
97
+ name="get_current_weather",
98
+ description="Get the current weather",
99
+ parameters={
100
+ "type": "object",
101
+ "properties": {
102
+ "location": {
103
+ "type": "string",
104
+ "description": "The city and state, e.g. San Francisco, CA",
105
+ },
106
+ "format": {
107
+ "type": "string",
108
+ "enum": ["celsius", "fahrenheit"],
109
+ "description": "The temperature unit to use. Infer this from the users location.",
110
+ },
111
+ },
112
+ "required": ["location", "format"],
113
+ },
114
+ )
115
+ )
116
+ ],
117
+ messages=[
118
+ UserMessage(content="What's the weather like today in Paris?"),
119
+ ],
120
+ )
121
+
122
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
123
+
124
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
125
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
126
+
127
+ print(result)
128
+ ```
129
+
130
+ ## Generate with `transformers`
131
+
132
+ If you want to use Hugging Face `transformers` to generate text, you can do something like this.
133
+
134
+ ```py
135
+ from transformers import pipeline
136
+
137
+ messages = [
138
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
139
+ {"role": "user", "content": "Who are you?"},
140
+ ]
141
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
142
+ chatbot(messages)
143
+ ```
144
+
145
+
146
+ ## Function calling with `transformers`
147
+
148
+ To use this example, you'll need `transformers` version 4.42.0 or higher. Please see the
149
+ [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling)
150
+ in the `transformers` docs for more information.
151
+
152
+ ```python
153
+ from transformers import AutoModelForCausalLM, AutoTokenizer
154
+ import torch
155
+
156
+ model_id = "mistralai/Mistral-7B-Instruct-v0.3"
157
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
158
+
159
+ def get_current_weather(location: str, format: str):
160
+ """
161
+ Get the current weather
162
+
163
+ Args:
164
+ location: The city and state, e.g. San Francisco, CA
165
+ format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
166
+ """
167
+ pass
168
+
169
+ conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
170
+ tools = [get_current_weather]
171
+
172
+
173
+ # format and tokenize the tool use prompt
174
+ inputs = tokenizer.apply_chat_template(
175
+ conversation,
176
+ tools=tools,
177
+ add_generation_prompt=True,
178
+ return_dict=True,
179
+ return_tensors="pt",
180
+ )
181
+
182
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
183
+
184
+ inputs.to(model.device)
185
+ outputs = model.generate(**inputs, max_new_tokens=1000)
186
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
187
+ ```
188
+
189
+ Note that, for reasons of space, this example does not show a complete cycle of calling a tool and adding the tool call and tool
190
+ results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
191
+ see the [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling),
192
+ and note that Mistral **does** use tool call IDs, so these must be included in your tool calls and tool results. They should be
193
+ exactly 9 alphanumeric characters.
194
+
195
+
196
+ ## Limitations
197
+
198
+ The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
199
+ It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
200
+ make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
201
+
202
+ ## The Mistral AI Team
203
+
204
+ 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
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MistralForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 1,
7
+ "eos_token_id": 2,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 4096,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 14336,
12
+ "max_position_embeddings": 32768,
13
+ "model_type": "mistral",
14
+ "num_attention_heads": 32,
15
+ "num_hidden_layers": 32,
16
+ "num_key_value_heads": 8,
17
+ "rms_norm_eps": 1e-05,
18
+ "rope_theta": 1000000.0,
19
+ "sliding_window": null,
20
+ "tie_word_embeddings": false,
21
+ "torch_dtype": "bfloat16",
22
+ "transformers_version": "4.42.0.dev0",
23
+ "use_cache": true,
24
+ "vocab_size": 32768
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e11b6808d92dd800050285b981b6f354d1c643eb916c0bf83ac2cf2d6b10008
3
+ size 4530440515
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff