Adding `safetensors` variant of this model
#1
by
SFconvertbot
- opened
- README.md +13 -70
- special_tokens_map.json +3 -21
- tokenizer.json +16 -7
- tokenizer_config.json +3 -4
README.md
CHANGED
|
@@ -1,79 +1,16 @@
|
|
| 1 |
---
|
| 2 |
-
library_name: transformers
|
| 3 |
license: apache-2.0
|
|
|
|
| 4 |
tags:
|
| 5 |
- finetuned
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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 |
|
|
@@ -95,8 +32,8 @@ 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.
|
| 99 |
-
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.
|
| 100 |
|
| 101 |
messages = [
|
| 102 |
{"role": "user", "content": "What is your favourite condiment?"},
|
|
@@ -114,6 +51,12 @@ decoded = tokenizer.batch_decode(generated_ids)
|
|
| 114 |
print(decoded[0])
|
| 115 |
```
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
## Troubleshooting
|
| 118 |
- If you see the following error:
|
| 119 |
```
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
tags:
|
| 5 |
- finetuned
|
| 6 |
+
inference:
|
| 7 |
+
parameters:
|
| 8 |
+
temperature: 0.7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
# Model Card for Mistral-7B-Instruct-v0.2
|
| 12 |
|
| 13 |
+
The Mistral-7B-Instruct-v0.2 Large Language Model (LLM) is an improved instruct fine-tuned version of [Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
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/).
|
| 16 |
|
|
|
|
| 32 |
|
| 33 |
device = "cuda" # the device to load the model onto
|
| 34 |
|
| 35 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 36 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 37 |
|
| 38 |
messages = [
|
| 39 |
{"role": "user", "content": "What is your favourite condiment?"},
|
|
|
|
| 51 |
print(decoded[0])
|
| 52 |
```
|
| 53 |
|
| 54 |
+
## Model Architecture
|
| 55 |
+
This instruction model is based on Mistral-7B-v0.1, a transformer model with the following architecture choices:
|
| 56 |
+
- Grouped-Query Attention
|
| 57 |
+
- Sliding-Window Attention
|
| 58 |
+
- Byte-fallback BPE tokenizer
|
| 59 |
+
|
| 60 |
## Troubleshooting
|
| 61 |
- If you see the following error:
|
| 62 |
```
|
special_tokens_map.json
CHANGED
|
@@ -1,23 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"bos_token":
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
"normalized": false,
|
| 6 |
-
"rstrip": false,
|
| 7 |
-
"single_word": false
|
| 8 |
-
},
|
| 9 |
-
"eos_token": {
|
| 10 |
-
"content": "</s>",
|
| 11 |
-
"lstrip": false,
|
| 12 |
-
"normalized": false,
|
| 13 |
-
"rstrip": false,
|
| 14 |
-
"single_word": false
|
| 15 |
-
},
|
| 16 |
-
"unk_token": {
|
| 17 |
-
"content": "<unk>",
|
| 18 |
-
"lstrip": false,
|
| 19 |
-
"normalized": false,
|
| 20 |
-
"rstrip": false,
|
| 21 |
-
"single_word": false
|
| 22 |
-
}
|
| 23 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"eos_token": "</s>",
|
| 4 |
+
"unk_token": "<unk>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
}
|
tokenizer.json
CHANGED
|
@@ -31,13 +31,23 @@
|
|
| 31 |
"special": true
|
| 32 |
}
|
| 33 |
],
|
| 34 |
-
"normalizer":
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
},
|
|
|
|
| 41 |
"post_processor": {
|
| 42 |
"type": "TemplateProcessing",
|
| 43 |
"single": [
|
|
@@ -124,7 +134,6 @@
|
|
| 124 |
"end_of_word_suffix": null,
|
| 125 |
"fuse_unk": true,
|
| 126 |
"byte_fallback": true,
|
| 127 |
-
"ignore_merges": false,
|
| 128 |
"vocab": {
|
| 129 |
"<unk>": 0,
|
| 130 |
"<s>": 1,
|
|
|
|
| 31 |
"special": true
|
| 32 |
}
|
| 33 |
],
|
| 34 |
+
"normalizer": {
|
| 35 |
+
"type": "Sequence",
|
| 36 |
+
"normalizers": [
|
| 37 |
+
{
|
| 38 |
+
"type": "Prepend",
|
| 39 |
+
"prepend": "โ"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"type": "Replace",
|
| 43 |
+
"pattern": {
|
| 44 |
+
"String": " "
|
| 45 |
+
},
|
| 46 |
+
"content": "โ"
|
| 47 |
+
}
|
| 48 |
+
]
|
| 49 |
},
|
| 50 |
+
"pre_tokenizer": null,
|
| 51 |
"post_processor": {
|
| 52 |
"type": "TemplateProcessing",
|
| 53 |
"single": [
|
|
|
|
| 134 |
"end_of_word_suffix": null,
|
| 135 |
"fuse_unk": true,
|
| 136 |
"byte_fallback": true,
|
|
|
|
| 137 |
"vocab": {
|
| 138 |
"<unk>": 0,
|
| 139 |
"<s>": 1,
|
tokenizer_config.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"add_bos_token": true,
|
| 3 |
"add_eos_token": false,
|
| 4 |
-
"add_prefix_space": null,
|
| 5 |
"added_tokens_decoder": {
|
| 6 |
"0": {
|
| 7 |
"content": "<unk>",
|
|
@@ -30,15 +29,15 @@
|
|
| 30 |
},
|
| 31 |
"additional_special_tokens": [],
|
| 32 |
"bos_token": "<s>",
|
| 33 |
-
"chat_template": "{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n{%- endif %}\n\n{{- bos_token }}\n{%- for message in loop_messages %}\n {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}\n {{- raise_exception('After the optional system message, conversation roles must alternate user/assistant/user/assistant/...') }}\n {%- endif %}\n {%- if message['role'] == 'user' %}\n {%- if loop.first and system_message is defined %}\n {{- ' [INST] ' + system_message + '\\n\\n' + message['content'] + ' [/INST]' }}\n {%- else %}\n {{- ' [INST] ' + message['content'] + ' [/INST]' }}\n {%- endif %}\n {%- elif message['role'] == 'assistant' %}\n {{- ' ' + message['content'] + eos_token}}\n {%- else %}\n {{- raise_exception('Only user and assistant roles are supported, with the exception of an initial optional system message!') }}\n {%- endif %}\n{%- endfor %}\n",
|
| 34 |
"clean_up_tokenization_spaces": false,
|
| 35 |
"eos_token": "</s>",
|
| 36 |
-
"legacy":
|
| 37 |
"model_max_length": 1000000000000000019884624838656,
|
| 38 |
"pad_token": null,
|
| 39 |
"sp_model_kwargs": {},
|
| 40 |
"spaces_between_special_tokens": false,
|
| 41 |
"tokenizer_class": "LlamaTokenizer",
|
| 42 |
"unk_token": "<unk>",
|
| 43 |
-
"use_default_system_prompt": false
|
|
|
|
| 44 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"add_bos_token": true,
|
| 3 |
"add_eos_token": false,
|
|
|
|
| 4 |
"added_tokens_decoder": {
|
| 5 |
"0": {
|
| 6 |
"content": "<unk>",
|
|
|
|
| 29 |
},
|
| 30 |
"additional_special_tokens": [],
|
| 31 |
"bos_token": "<s>",
|
|
|
|
| 32 |
"clean_up_tokenization_spaces": false,
|
| 33 |
"eos_token": "</s>",
|
| 34 |
+
"legacy": true,
|
| 35 |
"model_max_length": 1000000000000000019884624838656,
|
| 36 |
"pad_token": null,
|
| 37 |
"sp_model_kwargs": {},
|
| 38 |
"spaces_between_special_tokens": false,
|
| 39 |
"tokenizer_class": "LlamaTokenizer",
|
| 40 |
"unk_token": "<unk>",
|
| 41 |
+
"use_default_system_prompt": false,
|
| 42 |
+
"chat_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 %}"
|
| 43 |
}
|