FuturisticVibes commited on
Commit
f5723ce
1 Parent(s): 60c65c3

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - es
6
+ - it
7
+ - de
8
+ - fr
9
+ ---
10
+
11
+ # Model Card for Mixtral-8x22B-Instruct-v0.1
12
+ The Mixtral-8x22B-Instruct-v0.1 Large Language Model (LLM) is an instruct fine-tuned version of the [Mixtral-8x22B-v0.1](https://huggingface.co/mistralai/Mixtral-8x22B-v0.1).
13
+
14
+ ## Run the model
15
+ ```python
16
+ from transformers import AutoModelForCausalLM
17
+ from mistral_common.protocol.instruct.messages import (
18
+ AssistantMessage,
19
+ UserMessage,
20
+ )
21
+ from mistral_common.protocol.instruct.tool_calls import (
22
+ Tool,
23
+ Function,
24
+ )
25
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
26
+ from mistral_common.tokens.instruct.normalize import ChatCompletionRequest
27
+
28
+ device = "cuda" # the device to load the model onto
29
+
30
+ tokenizer_v3 = MistralTokenizer.v3()
31
+
32
+ mistral_query = ChatCompletionRequest(
33
+ tools=[
34
+ Tool(
35
+ function=Function(
36
+ name="get_current_weather",
37
+ description="Get the current weather",
38
+ parameters={
39
+ "type": "object",
40
+ "properties": {
41
+ "location": {
42
+ "type": "string",
43
+ "description": "The city and state, e.g. San Francisco, CA",
44
+ },
45
+ "format": {
46
+ "type": "string",
47
+ "enum": ["celsius", "fahrenheit"],
48
+ "description": "The temperature unit to use. Infer this from the users location.",
49
+ },
50
+ },
51
+ "required": ["location", "format"],
52
+ },
53
+ )
54
+ )
55
+ ],
56
+ messages=[
57
+ UserMessage(content="What's the weather like today in Paris"),
58
+ ],
59
+ model="test",
60
+ )
61
+
62
+ encodeds = tokenizer_v3.encode_chat_completion(mistral_query).tokens
63
+ model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
64
+ model_inputs = encodeds.to(device)
65
+ model.to(device)
66
+
67
+ generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
68
+ sp_tokenizer = tokenizer_v3.instruct_tokenizer.tokenizer
69
+ decoded = sp_tokenizer.decode(generated_ids[0])
70
+ print(decoded)
71
+ ```
72
+ Alternatively, you can run this example with the Hugging Face tokenizer.
73
+ To use this example, you'll need transformers version 4.39.0 or higher.
74
+ ```console
75
+ pip install transformers==4.39.0
76
+ ```
77
+ ```python
78
+ from transformers import AutoModelForCausalLM, AutoTokenizer
79
+
80
+ model_id = "mistralai/Mixtral-8x22B-Instruct-v0.1"
81
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
82
+ conversation=[
83
+ {"role": "user", "content": "What's the weather like in Paris?"},
84
+ {
85
+ "role": "tool_calls",
86
+ "content": [
87
+ {
88
+ "name": "get_current_weather",
89
+ "arguments": {"location": "Paris, France", "format": "celsius"},
90
+
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ "role": "tool_results",
96
+ "content": {"content": 22}
97
+ },
98
+ {"role": "assistant", "content": "The current temperature in Paris, France is 22 degrees Celsius."},
99
+ {"role": "user", "content": "What about San Francisco?"}
100
+ ]
101
+
102
+
103
+ tools = [{"type": "function", "function": {"name":"get_current_weather", "description": "Get▁the▁current▁weather", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "format": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use. Infer this from the users location."}},"required":["location","format"]}}}]
104
+
105
+ # render the tool use prompt as a string:
106
+ tool_use_prompt = tokenizer.apply_chat_template(
107
+ conversation,
108
+ chat_template="tool_use",
109
+ tools=tools,
110
+ tokenize=False,
111
+ add_generation_prompt=True,
112
+
113
+ )
114
+ model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
115
+
116
+ inputs = tokenizer(tool_use_prompt, return_tensors="pt")
117
+
118
+ outputs = model.generate(**inputs, max_new_tokens=20)
119
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
120
+ ```
121
+
122
+ # Instruct tokenizer
123
+ The HuggingFace tokenizer included in this release should match our own. To compare:
124
+ `pip install mistral-common`
125
+
126
+ ```py
127
+ from mistral_common.protocol.instruct.messages import (
128
+ AssistantMessage,
129
+ UserMessage,
130
+ )
131
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
132
+ from mistral_common.tokens.instruct.normalize import ChatCompletionRequest
133
+
134
+ from transformers import AutoTokenizer
135
+
136
+ tokenizer_v3 = MistralTokenizer.v3()
137
+
138
+ mistral_query = ChatCompletionRequest(
139
+ messages=[
140
+ UserMessage(content="How many experts ?"),
141
+ AssistantMessage(content="8"),
142
+ UserMessage(content="How big ?"),
143
+ AssistantMessage(content="22B"),
144
+ UserMessage(content="Noice 🎉 !"),
145
+ ],
146
+ model="test",
147
+ )
148
+ hf_messages = mistral_query.model_dump()['messages']
149
+
150
+ tokenized_mistral = tokenizer_v3.encode_chat_completion(mistral_query).tokens
151
+
152
+ tokenizer_hf = AutoTokenizer.from_pretrained('mistralai/Mixtral-8x22B-Instruct-v0.1')
153
+ tokenized_hf = tokenizer_hf.apply_chat_template(hf_messages, tokenize=True)
154
+
155
+ assert tokenized_hf == tokenized_mistral
156
+ ```
157
+
158
+ # Function calling and special tokens
159
+ This tokenizer includes more special tokens, related to function calling :
160
+ - [TOOL_CALLS]
161
+ - [AVAILABLE_TOOLS]
162
+ - [/AVAILABLE_TOOLS]
163
+ - [TOOL_RESULTS]
164
+ - [/TOOL_RESULTS]
165
+
166
+ If you want to use this model with function calling, please be sure to apply it similarly to what is done in our [SentencePieceTokenizerV3](https://github.com/mistralai/mistral-common/blob/main/src/mistral_common/tokens/tokenizers/sentencepiece.py#L299).
167
+
168
+ # The Mistral AI Team
169
+ Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux,
170
+ Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault,
171
+ Blanche Savary, Bam4d, Caroline Feldman, Devendra Singh Chaplot,
172
+ Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger,
173
+ Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona,
174
+ Jean-Malo Delignon, Jia Li, Justus Murke, Louis Martin, Louis Ternon,
175
+ Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat,
176
+ Marie Torelli, Marie-Anne Lachaux, Nicolas Schuhl, Patrick von Platen,
177
+ Pierre Stock, Sandeep Subramanian, Sophia Yang, Szymon Antoniak, Teven Le Scao,
178
+ Thibaut Lavril, Timothée Lacroix, Théophile Gervet, Thomas Wang,
179
+ Valera Nemychnikova, William El Sayed, William Marshall
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MixtralForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 1,
7
+ "eos_token_id": 2,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 6144,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 16384,
12
+ "max_position_embeddings": 65536,
13
+ "model_type": "mixtral",
14
+ "num_attention_heads": 48,
15
+ "num_experts_per_tok": 2,
16
+ "num_hidden_layers": 56,
17
+ "num_key_value_heads": 8,
18
+ "num_local_experts": 8,
19
+ "output_router_logits": false,
20
+ "rms_norm_eps": 1e-05,
21
+ "rope_theta": 1000000.0,
22
+ "router_aux_loss_coef": 0.001,
23
+ "sliding_window": null,
24
+ "tie_word_embeddings": false,
25
+ "torch_dtype": "bfloat16",
26
+ "transformers_version": "4.38.0",
27
+ "use_cache": true,
28
+ "vocab_size": 32768,
29
+ "quantization_config": {
30
+ "quant_method": "exl2",
31
+ "version": "0.1.5",
32
+ "bits": 8.0,
33
+ "head_bits": 8,
34
+ "calibration": {
35
+ "rows": 100,
36
+ "length": 2048,
37
+ "dataset": "(default)"
38
+ }
39
+ }
40
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.34.0.dev0"
6
+ }
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
output-00001-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35df79413790c84063f68cfa5d308d4d76a14b6b9d40866f1d9f88f2cac6e4aa
3
+ size 8569422376
output-00002-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a59002f8bbc1a32d478d2bddf5c15aab422f9a0732cd460266df00ade86e7b0
3
+ size 8520306088
output-00003-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e72c883944fbb2f20b88f7699ba6d3bbb1b8aead3dbe54c8e6d792c276a7a47
3
+ size 8562563704
output-00004-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f668e5b1d63435dbb138b04a7fb1317e98d7427a3b84f84b0e29d2bd6ac057ae
3
+ size 8539616536
output-00005-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ce0eba57cd2928e7312162fb563fdaeb3077ae9736990024f879ffa74c7bedd
3
+ size 8551200984
output-00006-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e422fefdde9865403291f22f9222f9575ef7293026145e3a7967ef4eb90f977
3
+ size 8548131656
output-00007-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:badf4490ab6ffc16885f5ecf8b038ff028de19e596761d0f6fb3e7a50bfceddb
3
+ size 8548467248
output-00008-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6dd24c4b457c8b4e982b3886e63abcc483a23ea8349ac7585a79c5db1f144019
3
+ size 8503684280
output-00009-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b692779c594f007b5562f2497e4ec5fdb43826d3d6a7ddd324f017d1ec71b459
3
+ size 8526934840
output-00010-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:855d44fa3814aa05b4ebbd0b05b7793b5fe2327399a2fbabc33b119b3a45031c
3
+ size 8580903824
output-00011-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:50c169515f15105616abc36b4ba80ed0e91f8babf557d4af948edcdc8506594f
3
+ size 8560383464
output-00012-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d27b249b49e3abc2389eba49f26446e975cb0fcc33e4acff938d1e9f0258651
3
+ size 8570281616
output-00013-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daebab7e7aac873f19a6c2f5cfe5b190c61087058cd16fd7a7656aa1bcdd8dd5
3
+ size 8541151592
output-00014-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:460e7812688035367c2602153652d83a8139be70cda581b19af0260c61495726
3
+ size 8587397488
output-00015-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a1cf0e058e77db0fbc8babb888a26dc1263900863210ed1488f96e2d4c7fd3e
3
+ size 281580456
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "unk_token": "<unk>",
5
+ "b_inst": "[INST]",
6
+ "e_inst": "[/INST]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": true,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "additional_special_tokens": [],
31
+ "bos_token": "<s>",
32
+ "chat_template": [
33
+ {
34
+ "name": "default",
35
+ "template": "{{bos_token}}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ ' [INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'] + ' ' + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
36
+ },
37
+ {
38
+ "name": "tool_use",
39
+ "template": "{{bos_token}}{% set user_messages = messages | selectattr('role', 'equalto', 'user') | list %}{% for message in messages %}{% if message['role'] == 'user' %}{% if message == user_messages[-1] %}{% if tools %}{{'[AVAILABLE_TOOLS]'+ tools|string + '[/AVAILABLE_TOOLS]'}}{% endif %}{{ '[INST]' + message['content'] + '[/INST]' }}{% else %}{{ '[INST]' + message['content'] + '[/INST]' }}{% endif %}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'] + ' ' + eos_token}}{% elif message['role'] == 'tool_results' %}{{'[TOOL_RESULTS]' + message['content']|string + '[/TOOL_RESULTS]'}}{% elif message['role'] == 'tool_calls' %}{{'[TOOL_CALLS]' + message['content']|string + eos_token}}{% endif %}{% endfor %}"
40
+ }
41
+ ],
42
+ "clean_up_tokenization_spaces": false,
43
+ "eos_token": "</s>",
44
+ "legacy": true,
45
+ "model_max_length": 1000000000000000019884624838656,
46
+ "pad_token": null,
47
+ "sp_model_kwargs": {},
48
+ "spaces_between_special_tokens": false,
49
+ "tokenizer_class": "LlamaTokenizer",
50
+ "unk_token": "<unk>",
51
+ "use_default_system_prompt": false
52
+ }