模型简介
模型特点
模型能力
使用案例
🚀 Phi-4-reasoning-plus模型卡片
Phi-4-reasoning-plus是一款经过微调的先进推理模型,它基于Phi-4模型,在思维链轨迹数据集上进行监督微调,并结合强化学习训练而成。该模型在推理任务上表现出色,尤其适用于对推理和逻辑要求较高的场景。
🚀 快速开始
推理参数
推理时,建议设置 temperature=0.8
,top_p=0.95
,并将 do_sample
设置为 True
。对于更复杂的查询,可将最大令牌数设置为 32k,以支持更长的思维链(CoT)。
Phi-4-reasoning-plus在推理密集型任务中表现出色。在实验中,我们将其最大令牌数扩展到 64k,它在处理长序列时取得了不错的结果,能够在长输入下保持连贯性和逻辑一致性。这使其成为需要深度、多步推理或大量上下文的任务的理想选择。
输入格式
鉴于训练数据的性质,推理时请始终使用 ChatML 模板,并使用以下系统提示:
<|im_start|>system<|im_sep|>
Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} <\think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|>
<|im_start|>user<|im_sep|>
What is the derivative of x^2?<|im_end|>
<|im_start|>assistant<|im_sep|>
使用 transformers
库
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-reasoning-plus")
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-reasoning-plus", device_map="auto", torch_dtype="auto")
messages = [
{"role": "system", "content": "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"},
{"role": "user", "content": "What is the derivative of x^2?"},
]
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(
inputs.to(model.device),
max_new_tokens=4096,
temperature=0.8,
top_p=0.95,
do_sample=True,
)
print(tokenizer.decode(outputs[0]))
使用 vllm
库
vllm serve microsoft/Phi-4-reasoning-plus --enable-reasoning --reasoning-parser deepseek_r1
Phi-4-reasoning-plus还支持Ollama、llama.cpp和任何与Phi-4兼容的框架。
✨ 主要特性
- 先进的推理能力:基于Phi-4模型进行监督微调与强化学习,在推理任务上表现出色。
- 高效的上下文处理:支持32k甚至64k的上下文长度,能处理长序列输入。
- 广泛的任务适用性:在数学推理、代码生成、规划等多种任务上有良好表现。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-reasoning-plus")
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-reasoning-plus", device_map="auto", torch_dtype="auto")
messages = [
{"role": "system", "content": "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"},
{"role": "user", "content": "What is the derivative of x^2?"},
]
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(
inputs.to(model.device),
max_new_tokens=4096,
temperature=0.8,
top_p=0.95,
do_sample=True,
)
print(tokenizer.decode(outputs[0]))
高级用法
vllm serve microsoft/Phi-4-reasoning-plus --enable-reasoning --reasoning-parser deepseek_r1
📚 详细文档
模型概述
属性 | 详情 |
---|---|
开发者 | 微软研究院 |
描述 | Phi-4-reasoning-plus是一款最先进的开放权重推理模型,它基于Phi-4模型,在思维链轨迹数据集上进行监督微调,并结合强化学习训练而成。监督微调数据集包括合成提示和来自公共领域网站的高质量过滤数据,重点关注数学、科学和编码技能,以及安全和负责任AI的对齐数据。该方法的目标是确保使用专注于高质量和高级推理的数据来训练小而强大的模型。Phi-4-reasoning-plus还额外进行了强化学习训练,因此具有更高的准确性,但平均生成的令牌数增加了50%,因此延迟也更高。 |
架构 | 基础模型与之前发布的Phi-4相同,具有140亿个参数,是一个密集的仅解码器Transformer模型 |
输入 | 文本,最适合聊天格式的提示 |
上下文长度 | 32k令牌 |
GPU | 32个H100 - 80G |
训练时间 | 2.5天 |
训练数据 | 160亿个令牌,约83亿个唯一令牌 |
输出 | 对输入的生成文本。模型响应有两个部分,即思维链推理块和总结块 |
日期 | 2025年1月 - 2025年4月 |
状态 | 基于离线数据集训练的静态模型,公开可用数据的截止日期为2025年3月及更早 |
发布日期 | 2025年4月30日 |
许可证 | MIT |
预期用途
用途类型 | 详情 |
---|---|
主要用例 | 我们的模型旨在加速语言模型的研究,用作生成式AI功能的构建块。它适用于通用AI系统和应用程序(主要是英文),这些应用程序需要:1. 内存/计算受限的环境;2. 低延迟场景;3. 推理和逻辑。 |
非预期用例 | 此模型仅针对数学推理进行设计和测试。我们的模型并非专门为所有下游用途设计或评估。开发者在选择用例时应考虑语言模型的常见限制,并在特定下游用例中使用之前评估和减轻准确性、安全性和公平性问题,特别是在高风险场景中。开发者应了解并遵守与其用例相关的适用法律或法规(包括隐私、贸易合规法等),包括模型对英文的关注。在选择用例时,请参考下面的负责任AI考虑部分以获取更多指导。本模型卡片中的任何内容均不应被解释为或视为对模型发布许可证的限制或修改。 |
数据概述
训练数据集
我们的训练数据是数学、科学和编码领域的问答和聊天格式数据的混合。聊天提示来自过滤后的高质量网络数据,并可选择通过合成数据生成管道进行重写和处理。我们还包括了提高真实性和安全性的数据。
基准数据集
我们使用开源的 Eureka 评估套件和我们自己的内部基准来评估Phi-4-reasoning-plus,以了解模型的能力。具体来说,我们在以下任务上评估我们的模型:
- 推理任务:
- AIME 2025、2024、2023和2022:数学奥林匹克问题。
- GPQA - Diamond:复杂的研究生水平科学问题。
- OmniMath:超过4000个奥林匹克水平数学问题的集合,有人工注释。
- LiveCodeBench:从竞争性编码竞赛中收集的代码生成基准。
- 3SAT(3 - 文字可满足性问题)和TSP(旅行商问题):算法问题解决。
- BA Calendar:规划。
- Maze和SpatialMap:空间理解。
- 通用基准:
- Kitab:信息检索。
- IFEval和ArenaHard:指令遵循。
- PhiBench:内部基准。
- FlenQA:提示长度对模型性能的影响。
- HumanEvalPlus:功能代码生成。
- MMLU - Pro:流行的多任务语言理解聚合数据集。
安全性
方法
Phi-4-reasoning-plus通过监督微调(SFT)采用了强大的安全后训练方法。这种方法利用了各种开源和内部生成的合成提示,以及符合严格微软安全指南的大语言模型生成的响应,例如用户理解和清晰度、安全和道德指南、限制、免责声明和知识范围、处理复杂和敏感主题、安全和尊重参与、指南的保密性和思维链的保密性。
安全评估和红队测试
在发布之前,Phi-4-reasoning-plus遵循了多方面的评估方法。使用多个开源安全基准和内部工具进行了定量评估,利用对抗性对话模拟。对于定性安全评估,我们与微软的独立AI红队(AIRT)合作,评估Phi-4-reasoning-plus在平均和对抗性用户场景中的安全风险。在平均用户场景中,AIRT模拟了典型的单轮和多轮交互,以识别潜在的风险行为。在对抗性用户场景中,测试了各种旨在故意破坏模型安全训练的技术,包括真实性、越狱、有害内容(如仇恨和不公平、暴力、性内容或自残)以及受保护材料的版权侵犯。我们还在Toxigen基准上评估模型,该基准旨在衡量针对少数群体的偏见和毒性。
请参考技术报告以获取更多关于安全对齐的详细信息。
模型质量
以下是模型在代表性基准上的质量概述。对于以下表格,数字越高表示性能越好:
模型 | AIME 24 | AIME 25 | OmniMath | GPQA - D | LiveCodeBench (8/1/24–2/1/25) |
---|---|---|---|---|---|
Phi - 4 - reasoning | 75.3 | 62.9 | 76.6 | 65.8 | 53.8 |
Phi - 4 - reasoning - plus | 81.3 | 78.0 | 81.9 | 68.9 | 53.1 |
OpenThinker2 - 32B | 58.0 | 58.0 | — | 64.1 | — |
QwQ 32B | 79.5 | 65.8 | — | 59.5 | 63.4 |
EXAONE - Deep - 32B | 72.1 | 65.8 | — | 66.1 | 59.5 |
DeepSeek - R1 - Distill - 70B | 69.3 | 51.5 | 63.4 | 66.2 | 57.5 |
DeepSeek - R1 | 78.7 | 70.4 | 85.0 | 73.0 | 62.8 |
o1 - mini | 63.6 | 54.8 | — | 60.0 | 53.8 |
o1 | 74.6 | 75.3 | 67.5 | 76.7 | 71.0 |
o3 - mini | 88.0 | 78.0 | 74.6 | 77.7 | 69.5 |
Claude - 3.7 - Sonnet | 55.3 | 58.7 | 54.6 | 76.8 | — |
Gemini - 2.5 - Pro | 92.0 | 86.7 | 61.1 | 84.0 | 69.2 |
模型 | FlenQA [3K - 令牌子集] | IFEval Strict | ArenaHard | HumanEvalPlus | MMLUPro | Kitab(无上下文 - 精度、有上下文 - 精度、无上下文 - 召回率、有上下文 - 召回率) | Toxigen判别式(有毒类别、中性类别) | PhiBench 2.21 |
---|---|---|---|---|---|---|---|---|
Phi - 4 | 82.0 | 62.3 | 68.1 | 83.5 | 71.5 | 19.3 88.5 8.2 68.1 |
72.6 90.0 |
58.2 |
Phi - 4 - reasoning | 97.7 | 83.4 | 73.3 | 92.9 | 74.3 | 23.2 91.5 4.9 74.8 |
86.7 84.7 |
70.6 |
Phi - 4 - reasoning - plus | 97.9 | 84.9 | 79.0 | 92.3 | 76.0 | 27.6 93.6 6.3 75.4 |
77.3 90.5 |
74.2 |
o3 - mini | 96.8 | 91.5 | 81.9 | 94.0 | 79.4 | 37.9 94.0 4.2 76.1 |
85.4 88.7 |
78.0 |
GPT - 4o | 90.8 | 81.8 | 75.6 | 88.0 | 73.0 | 53.7 84.7 20.3 69.2 |
87.6 85.1 |
72.4 |
总体而言,Phi-4-reasoning和Phi-4-reasoning-plus仅具有140亿个参数,但在广泛的推理任务中表现出色,显著优于如DeepSeek-R1蒸馏70亿模型等更大的开放权重模型,并接近完整DeepSeek R1模型的性能水平。我们还在多个新的推理基准上测试了模型,包括3SAT、TSP和BA - 日历等算法问题解决和规划任务。这些新任务对于模型来说名义上是域外任务,因为训练过程并未有意针对这些技能,但模型仍然对这些任务表现出强大的泛化能力。此外,在针对标准通用能力基准(如指令遵循或非推理任务)评估性能时,我们发现我们的新模型相比Phi-4有了显著改进,尽管后训练主要集中在特定领域的推理技能上。
负责任AI考虑
与其他语言模型一样,Phi-4-reasoning-plus可能会表现出不公平、不可靠或冒犯性的行为。需要注意的一些限制行为包括:
- 服务质量:模型主要基于英文文本进行训练。非英文语言的性能会较差。训练数据中代表性较少的英语变体可能比标准美式英语的性能更差。Phi-4-reasoning-plus不支持多语言使用。
- 伤害的代表性和刻板印象的延续:这些模型可能会过度或不足地代表某些人群,抹去某些群体的代表性,或强化贬低或负面的刻板印象。尽管进行了安全后训练,但由于不同群体的代表性水平不同或训练数据中负面刻板印象示例的普遍性反映了现实世界的模式和社会偏见,这些限制可能仍然存在。
- 不适当或冒犯性内容:这些模型可能会产生其他类型的不适当或冒犯性内容,这可能使其在没有针对特定用例的额外缓解措施的情况下,不适合在敏感环境中部署。
- 信息可靠性:语言模型可能会生成无意义的内容或编造听起来合理但不准确或过时的内容。
- 选举信息可靠性:模型在回答与选举关键查询时的缺陷率较高,这可能导致提供不正确或无权威性的选举关键信息。我们正在努力提高模型在这方面的性能。用户应向所在地区的选举机构核实与选举相关的信息。
- 代码范围有限:Phi-4-reasoning-plus的大部分训练数据基于Python,并使用常见的包,如
typing
、math
、random
、collections
、datetime
、itertools
。如果模型生成使用其他包的Python脚本或其他语言的脚本,我们强烈建议用户手动验证所有API的使用。
开发者应应用负责任AI的最佳实践,并负责确保特定用例符合相关法律法规(如隐私、贸易等)。强烈建议使用具有先进护栏的安全服务,如 Azure AI Content Safety。需要考虑的重要领域包括:
- 分配:在没有进一步评估和额外去偏技术的情况下,模型可能不适合对法律地位、资源分配或生活机会(如住房、就业、信贷等)有重大影响的场景。
- 高风险场景:开发者应评估在高风险场景中使用模型的适用性,在这些场景中,不公平、不可靠或冒犯性的输出可能会造成极大的代价或伤害。这包括在敏感或专家领域提供建议(如法律或健康建议),其中准确性和可靠性至关重要。应根据部署上下文在应用程序级别实施额外的保障措施。
- 错误信息:模型可能会产生不准确的信息。开发者应遵循透明度最佳实践,并告知最终用户他们正在与AI系统交互。在应用程序级别,开发者可以构建反馈机制和管道,将响应基于特定用例的上下文信息,这种技术称为检索增强生成(RAG)。
- 有害内容生成:开发者应根据上下文评估输出,并使用适合其用例的可用安全分类器或自定义解决方案。
- 滥用:可能存在其他形式的滥用,如欺诈、垃圾邮件或恶意软件生产,开发者应确保其应用程序不违反适用的法律法规。
🔧 技术细节
文档未提及技术实现细节,故跳过此章节。
📄 许可证
本模型采用MIT许可证,许可证链接:https://huggingface.co/microsoft/Phi-4-reasoning-plus/resolve/main/LICENSE



