Mistral AI開源 Magistral-Small-2507

宣布Magistral——Mistral AI推出的首款推理模型,專精于垂直領域、具備透明化特性與多語言推理能力。

最優秀的人類思維并非線性——它穿梭于邏輯、洞見、不確定性與發現之間。推理型語言模型讓我們得以將復雜思考和深度理解交由AI增強或代勞,提升了人類處理需要精確逐步推敲分析問題的能力。

但這一領域仍處于萌芽階段。早期思維模型存在諸多已知局限:缺乏針對垂直領域問題的專業深度、透明度不足、以及目標語言環境下的推理不連貫等。

今天我們激動地宣布通過Magistral模型為AI研究做出最新貢獻——這是我們首個推理模型。Magistral同步推出開源版與企業版,其設計理念是:以人類熟悉的思維方式進行深度推理論證,同時兼具跨專業領域的知識儲備、可追蹤驗證的透明推理過程,以及深度的多語言適應能力。

亮點

在這里插入圖片描述

Magistral Small 1.1

基于Mistral Small 3.1(2503版本)開發,額外增強推理能力,通過Magistral Medium軌跡進行監督微調并疊加強化學習,最終形成這款高效的小型推理模型,參數量達240億。

Magistral Small支持本地部署,經量化后可適配單張RTX 4090顯卡或32GB內存的MacBook設備運行。

Magistral Small 1.1 版本應提供與 基準測試結果 中 Magistral Small 1.0 相近的性能表現。

本次更新包含以下特性:

  • 更優化的語氣與模型行為表現。您將體驗到更出色的 LaTeX 和 Markdown 格式處理能力,以及對簡單通用提示的更簡潔回答。
  • 模型陷入無限生成循環的概率顯著降低。
  • 新增 [THINK][/THINK] 特殊標記用于封裝推理內容。該設計既便于解析思維軌跡,也能有效避免提示中出現’[THINK]'字符串時引發混淆。
  • 推理提示詞現已整合至系統提示模板中。

主要特點

  • 推理能力:能夠在給出答案前進行長鏈式推理追蹤。
  • 多語言支持:支持數十種語言,包括英語、法語、德語、希臘語、印地語、印尼語、意大利語、日語、韓語、馬來語、尼泊爾語、波蘭語、葡萄牙語、羅馬尼亞語、俄語、塞爾維亞語、西班牙語、土耳其語、烏克蘭語、越南語、阿拉伯語、孟加拉語、中文及波斯語。
  • Apache 2.0許可證:開放許可協議,允許商業及非商業用途的修改和使用。
  • 上下文窗口:128k上下文窗口,超過40k后性能可能下降。因此建議將模型最大長度設置為40k。

基準測試結果

ModelAIME24 pass@1AIME25 pass@1GPQA DiamondLivecodebench (v5)
Magistral Medium 1.172.03%60.99%71.46%59.35%
Magistral Medium 1.073.59%64.95%70.83%59.36%
Magistral Small 1.170.52%62.03%65.78%59.17%
Magistral Small 1.070.68%62.76%68.18%55.84%

采樣參數

請確保使用:

  • top_p: 0.95
  • temperature: 0.7
  • max_tokens: 40960

基礎聊天模板

為獲得最佳效果,我們強烈建議包含以下系統提示詞(可根據具體使用場景進行編輯調整):

請先通過思維過程(內心獨白)構思,直至形成最終回復。使用Markdown格式撰寫回復,數學公式請用LaTeX表示。思維過程和回復內容需與輸入語言保持一致。

思維過程必須遵循以下模板:[THINK]您的思考或草稿內容,如同在草稿紙上演算習題。可隨意采用非正式表達并充分展開,直至有把握生成最終回復。語言需與輸入保持一致。[/THINK]此處提供完整的最終回復內容。

[THINK][/THINK]是必須保持原樣的特殊標記符。

請務必以mistral-common作為權威參考。下方提供支持mistral-common的庫示例。

根據使用場景和需求,您可選擇在多輪對話中保留推理痕跡,或僅保留助手最終回復內容。

使用方法

該模型可與以下框架配合使用:

推理

  • vllm(推薦): 參見下文
  • transformers: 參見下文

此外,社區還準備了量化版本的模型,可與以下框架配合使用(按字母順序排序):

  • llama.cpp: https://huggingface.co/mistralai/Magistral-Small-2507-GGUF
  • lmstudio (llama.cpp, MLX): GGUF, MLX-bf16, MLX-8bit, MLX-6bit, MLX-4bit

訓練

支持通過以下工具進行微調(按字母順序排列):

  • axolotl: https://github.com/axolotl-ai-cloud/axolotl/tree/main/examples/magistral
  • unsloth: https://docs.unsloth.ai/basics/magistral

vLLM(推薦)

我們建議配合使用vLLM庫部署生產級推理流水線。

安裝指南

請確保安裝最新版vLLM代碼庫:

pip install -U vllm \--pre \--extra-index-url https://wheels.vllm.ai/nightly

該操作會自動安裝mistral_common >= 1.8.2版本。

版本驗證命令:

python -c "import mistral_common; print(mistral_common.__version__)"

您也可以直接使用現成的 Docker 鏡像 或從 Docker Hub 獲取。

按如下方式啟動模型服務:

vllm serve mistralai/Magistral-Small-2507 --reasoning-parser mistral --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2

按如下方式測試模型連通性:

from typing import Any
from openai import OpenAI
from huggingface_hub import hf_hub_download# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"TEMP = 0.7
TOP_P = 0.95
MAX_TOK = 40_960client = OpenAI(api_key=openai_api_key,base_url=openai_api_base,
)models = client.models.list()
model = models.data[0].iddef load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:file_path = hf_hub_download(repo_id=repo_id, filename=filename)with open(file_path, "r") as file:system_prompt = file.read()index_begin_think = system_prompt.find("[THINK]")index_end_think = system_prompt.find("[/THINK]")return {"role": "system","content": [{"type": "text", "text": system_prompt[:index_begin_think]},{"type": "thinking","thinking": system_prompt[index_begin_think + len("[THINK]") : index_end_think],"closed": True,},{"type": "text","text": system_prompt[index_end_think + len("[/THINK]") :],},],}SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")query = "Write 4 sentences, each with at least 8 words. Now make absolutely sure that every sentence has exactly one word less than the previous sentence."
# or try out other queries
# query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."
# query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133"
# query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?"messages = [SYSTEM_PROMPT,{"role": "user", "content": query}
]
stream = client.chat.completions.create(model=model,messages=messages,stream=True,temperature=TEMP,top_p=TOP_P,max_tokens=MAX_TOK,
)print("client: Start streaming chat completions...:\n")
printed_reasoning_content = False
answer = []for chunk in stream:reasoning_content = Nonecontent = None# Check the content is reasoning_content or contentif hasattr(chunk.choices[0].delta, "reasoning_content"):reasoning_content = chunk.choices[0].delta.reasoning_contentelif hasattr(chunk.choices[0].delta, "content"):content = chunk.choices[0].delta.contentif reasoning_content is not None:if not printed_reasoning_content:printed_reasoning_content = Trueprint("Start reasoning:\n", end="", flush=True)print(reasoning_content, end="", flush=True)elif content is not None:# Extract and print the contentif not reasoning_content and printed_reasoning_content:answer.extend(content)print(content, end="", flush=True)if answer:print("\n\n=============\nAnswer\n=============\n")print("".join(answer))
else:print("\n\n=============\nNo Answer\n=============\n")print("No answer was generated by the model, probably because the maximum number of tokens was reached.")# client: Start streaming chat completions...:
#
# Start reasoning:
# First, I need to write ...
# ...
#
#
# =============
# Answer
# =============
# 
# Here are four sentences where each has at least 8 words, and each subsequent sentence has exactly one word less than the previous one:# 1. The quick brown fox jumps over the lazy dog and rests.
# 2. The lazy dog rests under the big shady tree peacefully.
# 3. The big shady tree provides ample shade during summer.
# 4. The tree's leaves are very lush and green.

Transformers

請確保安裝最新版本的Transformers代碼:

pip install git+https://github.com/huggingface/transformers

同時請確保安裝 mistral_common >= 1.8.2

pip install --upgrade mistral-common

檢查

python -c "import mistral_common; print(mistral_common.__version__)"

現在你可以在Magistral中使用Transformers了:

from typing import Any
import torchfrom huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoTokenizerTEMP = 0.7
TOP_P = 0.95
MAX_TOK = 40_960def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:file_path = hf_hub_download(repo_id=repo_id, filename=filename)with open(file_path, "r") as file:system_prompt = file.read()index_begin_think = system_prompt.find("[THINK]")index_end_think = system_prompt.find("[/THINK]")return {"role": "system","content": [{"type": "text", "text": system_prompt[:index_begin_think]},{"type": "thinking","thinking": system_prompt[index_begin_think + len("[THINK]") : index_end_think],"closed": True,},{"type": "text","text": system_prompt[index_end_think + len("[/THINK]") :],},],}model_id = "mistralai/Magistral-Small-2507"
SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133."
# or try out other queries
# query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."
# query = "Write 4 sentences, each with at least 8 words. Now make absolutely sure that every sentence has exactly one word less than the previous sentence."
# query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?"tokenizer = AutoTokenizer.from_pretrained(model_id, tokenizer_type="mistral", use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto"
)input_ids = tokenizer.apply_chat_template([SYSTEM_PROMPT,{"role": "user", "content": query},],
)output = model.generate(input_ids=torch.tensor([input_ids], device=model.device),pad_token_id=tokenizer.pad_token_id,eos_token_id=tokenizer.eos_token_id,temperature=TEMP,top_p=TOP_P,do_sample=True,max_new_tokens=MAX_TOK,
)[0]decoded_output = tokenizer.decode(output[len(input_ids) :])
print(decoded_output)# [THINK]Alright, I need to think of 5 random numbers first. Let's say I pick the numbers 5, 10, 2, 7, and 3.
# 
# Now, I need to see if I can combine these numbers using addition, multiplication, subtraction, or division to get 133.
# ...
# ...
# ...
# But if we're to find any five numbers that can be combined to make 133, then yes, such sets exist, like the one demonstrated above.[/THINK]Yes, it is possible to combine some sets of five random numbers to make 133 using basic arithmetic operations. For example, the numbers 13, 10, 1, 2, and 3 can be combined as follows to make 133:
# 
# \[ (13 \times 10) + (3 \times (2 - 1)) = 130 + 3 = 133 \]
# 
# However, not all sets of five random numbers can be combined in this way to make 133. For instance, with the numbers 5, 10, 2, 7, and 3, it is not possible to combine them using the allowed operations to get exactly 133.
# 
# Therefore, the ability to combine five random numbers to make 133 depends on the specific numbers chosen.
# 
# $133 = (13 \times 10) + (3 \times (2 - 1))$</s>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/90891.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/90891.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/90891.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Kotlin】如何實現靜態方法?(單例類、伴生對象、@JvmStatic)

靜態方法 靜態方法&#xff08;類方法&#xff09;&#xff1a;不需要創建實例就可以調用&#xff08;直接通過類名調用&#xff09;的方法 Java 中的靜態方法&#xff08;static&#xff09; public class Util {public static void doAction() {//...} }調用&#xff1a;Util…

SQL Schema 和Pandas Schema什么意思

在數據處理和分析領域&#xff0c;SQL Schema 和 Pandas Schema 分別指的是在不同數據處理環境中數據的結構定義&#xff0c;以下為你詳細介紹&#xff1a;SQL Schema含義SQL Schema&#xff08;模式&#xff09;是數據庫對象的一個邏輯容器&#xff0c;它定義了數據庫中表、視…

機器學習(一)KNN,K近鄰算法(K-Nearest Neighbors)

&#x1f4a1; 建議初學者掌握KNN作為理解其他復雜算法&#xff08;如SVM、決策樹、神經網絡&#xff09;的基石。K近鄰算法&#xff08;K-Nearest Neighbors, KNN&#xff09;詳解&#xff1a;原理、實踐與優化K近鄰算法&#xff08;K-Nearest NeighboKrs&#xff0c;簡稱KNN&…

Qt 多線程數據庫操作優化

在多線程應用中&#xff0c;數據庫操作往往是性能瓶頸與穩定性風險的高發區。當多個線程同時讀寫數據庫時&#xff0c;若處理不當&#xff0c;輕則出現查詢卡頓、事務沖突&#xff0c;重則導致數據錯亂、連接泄漏甚至程序崩潰。Qt作為跨平臺框架&#xff0c;提供了QSql系列類支…

Qt 狀態機框架:復雜交互邏輯的處理

Qt狀態機框架&#xff08;Qt State Machine Framework&#xff09;是一個強大的工具&#xff0c;用于簡化復雜的交互邏輯和狀態管理。它基于UML狀態圖概念&#xff0c;提供了聲明式的方式來定義對象行為&#xff0c;特別適合處理具有多種狀態和轉換的場景&#xff08;如GUI交互…

【docker】DM8達夢數據庫的docker-compose以及一些啟動踩坑

摘要&#xff1a;本文介紹了通過docker-compose配置啟動達夢數據庫(DM8)的方法。配置包括容器鏡像、端口映射、數據卷掛載以及關鍵環境變量設置&#xff08;如字符集、大小寫敏感等&#xff09;。也說明了啟動過程可能遇到的一些問題。通過docker-compose啟動達夢數據庫可以按照…

服務器中的防火墻設置需要打開嗎

服務器中的防火墻屬于是一種保護計算機網絡不會受到未經授權的網絡設備所訪問的技術手段&#xff0c;防火墻還有著將內部網絡和外部網絡進行隔離的功能&#xff0c;在網絡之間創建安全屏障&#xff0c;以此來保護網絡中數據的安全。防火墻是一種網絡安全系統&#xff0c;可以幫…

Java項目:基于SSM框架實現的社區團購管理系統【ssm+B/S架構+源碼+數據庫+畢業論文+答辯PPT+遠程部署】

摘 要 使用舊方法對社區團購信息進行系統化管理已經不再讓人們信賴了&#xff0c;把現在的網絡信息技術運用在社區團購信息的管理上面可以解決許多信息管理上面的難題&#xff0c;比如處理數據時間很長&#xff0c;數據存在錯誤不能及時糾正等問題。 這次開發的社區團購系統有…

介紹一下static關鍵字

在Java中&#xff0c;被static修飾的成員稱為靜態成員&#xff0c;static關鍵字可以用來修飾方法或者成員變量&#xff0c;且被static修飾的方法或者成員變量屬于類方法或者類屬性&#xff0c;也就是說被static修飾的方法或者成員變量不是單獨存儲在某一個對象的空間&#xff0…

【Java學習|黑馬筆記|Day23】網絡編程、反射、動態代理

【DAY23】 文章目錄【DAY23】一.網絡編程1&#xff09;三要素1.1&#xff09;IPInetAddress類的使用1.2&#xff09;端口號1.3&#xff09;協議2.1&#xff09;UDP協議發送數據2.2&#xff09;UDP協議接收數據2.3&#xff09;UDP的三種通信方式3.1&#xff09;TCP協議的發送和接…

【Zephyr】Window下的Zephyr編譯和使用

工具下載 參考文檔&#xff08;Getting Started Guide — Zephyr Project Documentation&#xff09;中介紹&#xff0c;可以直接通過winget下載&#xff1a; winget download Kitware.CMake Ninja-build.Ninja oss-winget.gperf python Git.Git oss-winget.dtc wget 7zip.7z…

圖論(BFS)構造鄰接表(運用隊列實現搜索)

碼蹄集OJ-夏日漫步 #include<bits/stdc.h> using namespace std; int n; int a[200010],dis[200010],qaq[1000010]; vector<int>son[200010]; int que[200010]; int main( ) {memset(qaq,-1,sizeof(qaq));memset(dis,-1,sizeof(dis));cin>>n;for(int i1;i…

vue怎么實現導入excel表功能

<el-uploadref"upload":action"aaa":on-change"importProject"name"excelFile"multiple:auto-upload"false":show-file-list"false"><el-button type"warning">導入</el-button><…

Linux DNS解析3 -- DNS解析代理配置使用

當網關設備配置了 /etc/hosts 文件時&#xff0c;確實可以為終端設備提供自定義DNS解析功能&#xff0c;但具體效果取決于網關的DNS代理服務配置。下面詳細解釋其工作原理和限制&#xff1a; 一、/etc/hosts 文件的作用 /etc/hosts 是本地靜態域名解析文件&#xff0c;格式為&a…

歷史版本的vscode下載地址

我有點厭惡vscode越來越臃腫的體積&#xff0c;也不需要層出不窮的新功能&#xff0c;于是網上找尋歷史版本。 首先是這個頁面&#xff1a;https://code.visualstudio.com/updates &#xff0c;但最多只顯示兩年&#xff0c;更早的就要手工修改地址欄&#xff0c;我試了最早的…

如何規范化項目執行

要實現項目執行的規范化&#xff0c;應做到以下幾點&#xff1a;制定詳細的項目執行計劃、明確項目團隊角色職責、建立高效溝通與協調機制、實施全面的質量與風險管理、采用合適的項目管理工具。其中&#xff0c;尤其重要的是明確項目團隊角色職責&#xff0c;通過構建清晰的責…

【Rust異步】async和await異步編程實戰:高并發任務處理全解析

?? 歡迎大家來到景天科技苑?? &#x1f388;&#x1f388; 養成好習慣&#xff0c;先贊后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者簡介&#xff1a;景天科技苑 &#x1f3c6;《頭銜》&#xff1a;大廠架構師&#xff0c;華為云開發者社區專家博主&#xff0c;…

在Linux上使用DuckCP實現從csv文件匯總數據到SQLite數據庫的表

從pypi網站Duckcp頁面下載duckcp-0.1.1-py3-none-any.whl 一開始用的Python 3.11.2環境。 繼續沿用上文打補丁的方法&#xff0c;得到一個支持python3.11.1的安裝包。 因為缺少zip壓縮工具&#xff0c;使用python程序來完成對修改后文件的重新壓縮。 import os import zipfile…

基于深度學習的圖像分類:使用EfficientNet實現高效分類

前言 圖像分類是計算機視覺領域中的一個基礎任務&#xff0c;其目標是將輸入的圖像分配到預定義的類別中。近年來&#xff0c;深度學習技術&#xff0c;尤其是卷積神經網絡&#xff08;CNN&#xff09;&#xff0c;在圖像分類任務中取得了顯著的進展。EfficientNet是一種新型的…

Java基礎-綜合案例

1、設計一個可以執行基本數學運算&#xff08;加減乘除&#xff09;的計算器程序功能描述&#xff1a;用戶輸入兩個數字、一個運算符&#xff08;、-、*、/&#xff09;。根據所選運算符執行相應的數學運算&#xff0c;顯示運算結果。import java.util.Scanner;public class Te…