模型简介
模型特点
模型能力
使用案例
🚀 Phi-4-reasoning-plus模型卡片
Phi-4-reasoning-plus是基于Phi-4微调的推理模型,在数学、科学和编码等推理密集型任务中表现出色,具有较高的准确性和推理能力。
🚀 快速开始
若要充分发挥模型的能力,推理时必须使用 temperature=0.8
、top_k=50
、top_p=0.95
并设置 do_sample=True
。对于更复杂的查询,可设置 max_new_tokens=32768
以支持更长的思维链(CoT)。
✨ 主要特性
- 先进架构:基于14B参数的密集解码器Transformer模型,与之前发布的Phi-4基础模型相同。
- 高质量训练:使用16B标记(约83亿唯一标记)的训练数据,训练时间为2.5天。
- 长上下文处理:支持32k标记的上下文长度,在实验中扩展到64k标记也能保持良好性能。
- 高准确性:经过强化学习训练,准确性更高,但平均生成的标记数增加50%,延迟也相应增加。
- 多任务表现出色:在推理任务和通用基准测试中均有良好表现,超越了许多大参数模型。
📦 安装指南
文档未提及安装步骤,暂无法提供。
💻 使用示例
基础用法
由于训练数据的特性,推理时始终使用ChatML模板和以下系统提示:
<|im_start|>system<|im_sep|>
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:<|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_k=50,
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兼容的框架。
📚 详细文档
模型概述
属性 | 详情 |
---|---|
开发者 | Microsoft Research |
描述 | Phi-4-reasoning-plus是一个最先进的开放权重推理模型,基于Phi-4进行监督微调,并结合强化学习。监督微调数据集包括合成提示和来自公共领域网站的高质量过滤数据,专注于数学、科学和编码技能以及安全和负责任AI的对齐数据。该模型经过强化学习训练,准确性更高,但平均生成的标记数增加50%,延迟也相应增加。 |
架构 | 基础模型与之前发布的Phi-4相同,14B参数,密集解码器Transformer模型 |
输入 | 文本,最适合聊天格式的提示 |
上下文长度 | 32k标记 |
GPU | 32个H100-80G |
训练时间 | 2.5天 |
训练数据 | 16B标记,约83亿唯一标记 |
输出 | 对输入的生成文本,模型响应分为推理思维链块和总结块两部分 |
日期 | 2025年1月 - 2025年4月 |
状态 | 基于离线数据集训练的静态模型,公开可用数据截止到2025年3月及更早 |
发布日期 | 2025年4月30日 |
许可证 | MIT |
预期用途
用途类型 | 详情 |
---|---|
主要用例 | 该模型旨在加速语言模型的研究,作为生成AI功能的构建块。适用于需要内存/计算受限环境、低延迟场景和推理逻辑的通用AI系统和应用(主要为英文)。 |
非预期用例 | 该模型仅针对数学推理进行设计和测试,并非针对所有下游用途进行专门设计或评估。开发者在选择用例时应考虑语言模型的常见限制,并在特定下游用例中使用前评估和缓解准确性、安全性和公平性问题,特别是在高风险场景中。开发者应遵守适用的法律法规(包括隐私、贸易合规等),并参考“负责任AI考虑因素”部分获取更多指导。 |
数据概述
训练数据集
训练数据是数学、科学和编码领域的问答和聊天格式数据的混合。聊天提示来自过滤后的高质量网络数据,并可通过合成数据生成管道进行重写和处理。此外,还包括提高真实性和安全性的数据。
基准数据集
使用开源的Eureka评估套件和内部基准对Phi-4-reasoning-plus进行评估,具体包括:
- 推理任务:AIME 2025、2024、2023和2022、GPQA-Diamond、OmniMath、LiveCodeBench、3SAT和TSP、BA Calendar、Maze和SpatialMap。
- 通用基准:Kitab、IFEval和ArenaHard、PhiBench、FlenQA、HumanEvalPlus、MMLU-Pro。
安全性
方法
Phi-4-reasoning-plus采用了强大的安全后训练方法,通过监督微调(SFT),利用各种开源和内部生成的合成提示,以及符合微软严格安全指南的LLM生成响应。
安全评估和红队测试
在发布前,Phi-4-reasoning-plus采用了多方面的评估方法,包括使用多个开源安全基准和内部工具进行定量评估,以及与微软独立AI红队(AIRT)合作进行定性安全评估。还在Toxigen基准上评估模型的偏差和毒性。
模型质量
在代表性基准测试中,Phi-4-reasoning和Phi-4-reasoning-plus在推理任务中表现出色,超越了许多大参数模型,并且在通用能力基准测试中也有显著提升。
负责任AI考虑因素
Phi-4-reasoning-plus可能存在一些局限性,如服务质量、群体代表性、不当内容、信息可靠性、选举信息可靠性和代码范围有限等问题。开发者应遵循负责任AI最佳实践,确保特定用例符合相关法律法规,并使用安全服务进行风险缓解。
🔧 技术细节
文档未提及技术实现细节,暂无法提供。
📄 许可证
本项目采用MIT许可证。



