Downloads · 30 days
31
1% of all-time downloads
dfurman/Mistral-7B-Instruct-v0.1
Mistral-7B-Instruct-v0.1 is a text generation model from dfurman. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
Downloads · 30 days
31
1% of all-time downloads
All-time downloads
2.2K
Public
Repo size
655 MB
Likes
2
Public
Click a slice to open those files.
.safetensors218 MB · 99%
From the Hugging Face model README
A pretrained generative language model with 7 billion parameters geared towards instruction-following capabilities.
This model was built via parameter-efficient finetuning of the mistralai/Mistral-7B-v0.1 base model on the jondurbin/airoboros-2.2.1 dataset.
| Metric | Value |
|---|---|
| MMLU (5-shot) | Coming |
| ARC (25-shot) | Coming |
| HellaSwag (10-shot) | Coming |
| TruthfulQA (0-shot) | Coming |
| Avg. | Coming |
We use Eleuther.AI's Language Model Evaluation Harness to run the benchmark tests above, the same version as Hugging Face's Open LLM Leaderboard.
!pip install -q -U transformers peft torch accelerate einops sentencepiece
import torch
from peft import PeftModel, PeftConfig
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
)
peft_model_id = "dfurman/Mistral-7B-Instruct-v0.1"
config = PeftConfig.from_pretrained(peft_model_id)
tokenizer = AutoTokenizer.from_pretrained(
peft_model_id,
use_fast=True,
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
config.base_model_name_or_path,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(
model,
peft_model_id
)
</details>
messages = [
{"role": "user", "content": "Tell me a recipe for a mai tai."},
]
print("\n\n*** Prompt:")
input_ids = tokenizer.apply_chat_template(
messages,
tokenize=True,
return_tensors="pt",
)
print(tokenizer.decode(input_ids[0]))
<details>
<summary>Prompt</summary>
"<s> [INST] Tell me a recipe for a mai tai. [/INST]"
</details>
print("\n\n*** Generate:")
with torch.autocast("cuda", dtype=torch.bfloat16):
output = model.generate(
input_ids=input_ids.cuda(),
max_new_tokens=1024,
do_sample=True,
temperature=0.7,
return_dict_in_generate=True,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
repetition_penalty=1.2,
no_repeat_ngram_size=5,
)
response = tokenizer.decode(
output["sequences"][0][len(input_ids[0]):],
skip_special_tokens=True
)
print(response)
<details>
<summary>Generation</summary>
"""1 oz light rum
½ oz dark rum
¼ oz orange curaçao
2 oz pineapple juice
¾ oz lime juice
Dash of orgeat syrup (optional)
Splash of grenadine (for garnish, optional)
Lime wheel and cherry garnishes (optional)
Shake all ingredients except the splash of grenadine in a cocktail shaker over ice. Strain into an old-fashioned glass filled with fresh ice cubes. Gently pour the splash of grenadine down the side of the glass so that it sinks to the bottom. Add garnishes as desired."""
</details>
| runtime / 50 tokens (sec) | GPU | dtype | VRAM (GB) |
|---|---|---|---|
| 3.21 | 1x A100 (40 GB SXM) | torch.bfloat16 | 16 |
It took ~2 hours to train 2 epochs on 1x A100 (40 GB SXM).
This model was finetuned with the following format:
tokenizer.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 %}"
This format is available as a chat template via the apply_chat_template() method. Here's an illustrative example:
messages = [
{"role": "user", "content": "Tell me a recipe for a mai tai."},
{"role": "assistant", "content": "1 oz light rum\n½ oz dark rum\n¼ oz orange curaçao\n2 oz pineapple juice\n¾ oz lime juice\nDash of orgeat syrup (optional)\nSplash of grenadine (for garnish, optional)\nLime wheel and cherry garnishes (optional)\n\nShake all ingredients except the splash of grenadine in a cocktail shaker over ice. Strain into an old-fashioned glass filled with fresh ice cubes. Gently pour the splash of grenadine down the side of the glass so that it sinks to the bottom. Add garnishes as desired."},
{"role": "user", "content": "How can I make it more upscale and luxurious?"},
]
print("\n\n*** Prompt:")
input_ids = tokenizer.apply_chat_template(
messages,
tokenize=True,
return_tensors="pt",
)
print(tokenizer.decode(input_ids[0]))
<details>
<summary>Output</summary>
"""<s> [INST] Tell me a recipe for a mai tai. [/INST] 1 oz light rum\n½ oz dark rum\n (...) Add garnishes as desired.</s> [INST] How can I make it more upscale and luxurious? [/INST]"""
</details>
We use the SFTTrainer from trl to fine-tune LLMs on instruction-following datasets.
See here for the finetuning code, which contains an exhaustive view of the hyperparameters employed.
The following TrainingArguments config was used:
The following bitsandbytes quantization config was used:
dryanfurman at gmail
@misc{jiang2023mistral,
title={Mistral 7B},
author={Albert Q. Jiang and Alexandre Sablayrolles and Arthur Mensch and Chris Bamford and Devendra Singh Chaplot and Diego de las Casas and Florian Bressand and Gianna Lengyel and Guillaume Lample and Lucile Saulnier and Lélio Renard Lavaud and Marie-Anne Lachaux and Pierre Stock and Teven Le Scao and Thibaut Lavril and Thomas Wang and Timothée Lacroix and William El Sayed},
year={2023},
eprint={2310.06825},
archivePrefix={arXiv},
primaryClass={cs.CL}
}