Views
No views yet

Note: This model is a an old model, and may not produce accurate responses! This is just an archive of the original model, for anyone to use! This model still is amazing especially for its time being open-sourced.
Mistral-7B-Instruct-Latest-Pure-GGUF because its the last version released for the Mistral Model, and I find that putting v0.3 in the name looked ugly.Straight from the official weights, purely quantized, pure GGUF.
q5_k_m for the closest to original quality.q8_0 is near-lossless if you can fit it.q4_k_m, this is the best for most cases for the daily user.Using this model at a Context Size of 32k, and a quantization of q4_k_m, uses around 9GB.
mistralai/Mistral-7B-Instruct-v0.3 repository on HuggingFace..git, .gitattributes, LICENSE, README. They're not needed.convert_hf_to_gguf.py from the official llama.cpp source.llama-quantize.mistralai/Mistral-7B-Instruct-v0.3 with mistral-inference. For HF transformers code snippets, please keep scrolling.pip install mistral_inference1from huggingface_hub import snapshot_download
2from pathlib import Path
3
4mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
5mistral_models_path.mkdir(parents=True, exist_ok=True)
6
7snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)mistral_inference, a mistral-chat CLI command should be available in your environment. You can chat with the model usingmistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 2561from mistral_inference.transformer import Transformer
2from mistral_inference.generate import generate
3
4from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
5from mistral_common.protocol.instruct.messages import UserMessage
6from mistral_common.protocol.instruct.request import ChatCompletionRequest
7
8
9tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
10model = Transformer.from_folder(mistral_models_path)
11
12completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
13
14tokens = tokenizer.encode_chat_completion(completion_request).tokens
15
16out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
17result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
18
19print(result)1from mistral_common.protocol.instruct.tool_calls import Function, Tool
2from mistral_inference.transformer import Transformer
3from mistral_inference.generate import generate
4
5from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from mistral_common.protocol.instruct.messages import UserMessage
7from mistral_common.protocol.instruct.request import ChatCompletionRequest
8
9
10tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
11model = Transformer.from_folder(mistral_models_path)
12
13completion_request = ChatCompletionRequest(
14 tools=[
15 Tool(
16 function=Function(
17 name="get_current_weather",
18 description="Get the current weather",
19 parameters={
20 "type": "object",
21 "properties": {
22 "location": {
23 "type": "string",
24 "description": "The city and state, e.g. San Francisco, CA",
25 },
26 "format": {
27 "type": "string",
28 "enum": ["celsius", "fahrenheit"],
29 "description": "The temperature unit to use. Infer this from the users location.",
30 },
31 },
32 "required": ["location", "format"],
33 },
34 )
35 )
36 ],
37 messages=[
38 UserMessage(content="What's the weather like today in Paris?"),
39 ],
40)
41
42tokens = tokenizer.encode_chat_completion(completion_request).tokens
43
44out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
45result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
46
47print(result)transformerstransformers to generate text, you can do something like this.1from transformers import pipeline
2
3messages = [
4 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
5 {"role": "user", "content": "Who are you?"},
6]
7chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
8chatbot(messages)transformerstransformers version 4.42.0 or higher. Please see the
function calling guide
in the transformers docs for more information.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "mistralai/Mistral-7B-Instruct-v0.3"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6
7def get_current_weather(location: str, format: str):
8 """
9 Get the current weather
10
11 Args:
12 location: The city and state, e.g. San Francisco, CA
13 format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
14 """
15 pass
16
17conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
18tools = [get_current_weather]
19
20
21# format and tokenize the tool use prompt
22inputs = tokenizer.apply_chat_template(
23 conversation,
24 tools=tools,
25 add_generation_prompt=True,
26 return_dict=True,
27 return_tensors="pt",
28)
29
30model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
31
32inputs.to(model.device)
33outputs = model.generate(**inputs, max_new_tokens=1000)
34print(tokenizer.decode(outputs[0], skip_special_tokens=True))