HuggingFace镜像/Mathstral-7B-v0.1
模型介绍文件和版本分析
下载使用量0

Mathstral-7b-v0.1 模型卡片

Mathstral 7B 是一款专注于数学和科学任务的模型,基于 Mistral 7B 构建。 您可以在 官方博客文章 中了解更多信息。

安装

建议将 mistralai/Mathstral-7b-v0.1 与 mistral-inference 配合使用。

pip install mistral_inference>=1.2.0

下载

from huggingface_hub import snapshot_download
from pathlib import Path

mistral_models_path = Path.home().joinpath('mistral_models', 'Mathstral-7b-v0.1')
mistral_models_path.mkdir(parents=True, exist_ok=True)

snapshot_download(repo_id="mistralai/Mathstral-7b-v0.1", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)

对话

安装 mistral_inference 后,您的环境中应会出现 mistral-demo 命令行界面(CLI)命令。

mistral-chat $HOME/mistral_models/Mathstral-7b-v0.1 --instruct --max_tokens 256

然后你就可以开始与模型对话了,例如可以这样提示它:

“阿尔伯特每周都喜欢去冲浪。每次冲浪持续4小时,每小时收费20美元。阿尔伯特5周会花费多少钱?”

在 transformers 中的使用方法

要在 transformers 库中使用此模型,请安装最新版本:pip install --upgrade transformers,然后运行以下示例代码:

from transformers import pipeline
import torch

checkpoint = "mistralai/Mathstral-7b-v0.1"
pipe = pipeline("text-generation", checkpoint, device_map="auto", torch_dtype=torch.bfloat16)

prompt = [{"role": "user", "content": "What are the roots of unity?"}]
out = pipe(prompt, max_new_tokens = 512)

print(out[0]['generated_text'][-1])
>>> "{'role': 'assistant', 'content': ' The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.'}"

您也可以手动对输入进行分词,并从模型生成文本,而不是使用更高级别的管道:

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

checkpoint = "mistralai/Mathstral-7b-v0.1"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)

prompt = [{"role": "user", "content": "What are the roots of unity?"}]
tokenized_prompt = tokenizer.apply_chat_template(prompt, add_generation_prompt=True, return_dict=True, return_tensors="pt").to(model.device)

out = model.generate(**tokenized_prompt, max_new_tokens=512)
tokenizer.decode(out[0])
>>> '<s>[INST] What are the roots of unity?[/INST] The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.</s>'

评估

我们在行业标准基准上对 Mathstral 7B 及同等规模的开源模型进行了评估。

基准测试MATHGSM8K (8-shot)Odyssey Math maj@16GRE Math maj@16AMC 2023 maj@16AIME 2024 maj@16
Mathstral 7B56.677.137.256.942.42/30
DeepSeek Math 7B44.480.627.644.628.00/30
Llama3 8B28.475.424.026.234.40/30
GLM4 9B50.248.818.946.236.01/30
QWen2 7B56.832.724.858.535.22/30
Gemma2 9B48.369.518.652.331.21/30

Mistral AI 团队

Albert Jiang、Alexandre Sablayrolles、Alexis Tacnet、Alok Kothari、Antoine Roux、Arthur Mensch、Audrey Herblin-Stoop、Augustin Garreau、Austin Birky、Bam4d、Baptiste Bout、Baudouin de Monicault、Blanche Savary、Carole Rambaud、Caroline Feldman、Devendra Singh Chaplot、Diego de las Casas、Eleonore Arcelin、Emma Bou Hanna、Etienne Metzger、Gaspard Blanchet、Gianna Lengyel、Guillaume Bour、Guillaume Lample、Harizo Rajaona、Henri Roussez、Hichem Sattouf、Ian Mack、Jean-Malo Delignon、Jessica Chudnovsky、Justus Murke、Kartik Khandelwal、Lawrence Stewart、Louis Martin、Louis Ternon、Lucile Saulnier、Lélio Renard Lavaud、Margaret Jennings、Marie Pellat、Marie Torelli、Marie-Anne Lachaux、Marjorie Janiewicz、Mickaël Seznec、Nicolas Schuhl、Niklas Muhs、Olivier de Garrigues、Patrick von Platen、Paul Jacob、Pauline Buche、Pavan Kumar Reddy、Perry Savas、Pierre Stock、Romain Sauvestre、Sagar Vaze、Sandeep Subramanian、Saurabh Garg、Sophia Yang、Szymon Antoniak、Teven Le Scao、Thibault Schueller、Thibaut Lavril、Thomas Wang、Théophile Gervet、Timothée Lacroix、Valera Nemychnikova、Wendy Shang、William El Sayed、William Marshall