From abbb488323393b26613ffbe7ba23528b1131e5c3 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 22 May 2024 10:25:13 +0000 Subject: [PATCH 1/3] Update README.md --- README.md | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7b95401..19e3636 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,116 @@ ---- -license: apache-2.0 ---- +--- +license: apache-2.0 +--- + +# Model Card for Mistral-7B-Instruct-v0.3 + +The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3. + +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) +- Extended vocabulary to 32768 +- Supports v3 Tokenizer +- Supports function calling + +## Installation + +It is recommended to use `mistralai/Mistral-7B-Instruct-v0.3` with [mistral-inference](https://github.com/mistralai/mistral-inference) + +``` +pip install mistral_inference +``` + +## Download + +```py +from huggingface_hub import snapshot_download +from pathlib import Path + +mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3') +mistral_models_path.mkdir(parents=True, exist_ok=True) + +snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], cache_dir=mistral_models_path) +``` + +### Instruct following + +```py +from mistral_inference.model import Transformer +from mistral_inference.generate import generate + +from mistral_common.tokens.tokenizers.mistral import MistralTokenizer +from mistral_common.protocol.instruct.messages import UserMessage +from mistral_common.protocol.instruct.request import ChatCompletionRequest + + +tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3") +model = Transformer.from_folder(mistral_models_path) + +completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")]) + +tokens = tokenizer.encode_chat_completion(completion_request).tokens + +out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id) +result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0]) + +print(result) +``` + +### Function calling + +```py +from mistral_common.protocol.instruct.tool_calls import Function, Tool +from mistral_inference.model import Transformer +from mistral_inference.generate import generate + +from mistral_common.tokens.tokenizers.mistral import MistralTokenizer +from mistral_common.protocol.instruct.messages import UserMessage +from mistral_common.protocol.instruct.request import ChatCompletionRequest + + +tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3") +model = Transformer.from_folder(mistral_models_path) + +completion_request = ChatCompletionRequest( + tools=[ + Tool( + 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"], + }, + ) + ) + ], + messages=[ + UserMessage(content="What's the weather like today in Paris?"), + ], +) + +out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id) +result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0]) + +print(result) +``` + +## Limitations + +The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance. +It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to +make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs. + +## The Mistral AI Team + +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 \ No newline at end of file From 9a93e9095bd4a736fce752ea5cde0e620345250c Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 22 May 2024 10:32:05 +0000 Subject: [PATCH 2/3] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 19e3636..9cda059 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,14 @@ mistral_models_path.mkdir(parents=True, exist_ok=True) snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], cache_dir=mistral_models_path) ``` +### Chat + +After installing `mistral_inference`, a `mistral-chat` command should be available in your CLI. You can chat with the model using + +``` +mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 +``` + ### Instruct following ```py From 16a3e67b4df51bd3d15f3c6d1f13933db240db48 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 22 May 2024 10:33:22 +0000 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cda059..f475a54 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,10 @@ snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=[ ### Chat -After installing `mistral_inference`, a `mistral-chat` command should be available in your CLI. You can chat with the model using +After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using ``` -mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 +mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256 ``` ### Instruct following