Phi-3-Medium-4K-Instruct 是一款拥有140亿参数的轻量级、最先进的开放模型,它基于 Phi-3 数据集训练而成。该数据集包含合成数据和经过筛选的公开网站数据,重点关注高质量和推理密集型特性。
该模型属于 Phi-3 系列的 Medium 版本,有两个变体:4K 和 128K,这里的数字代表模型支持的上下文长度(以 tokens 为单位)。
该模型经过了后训练过程,其中包括监督微调以及针对指令遵循和安全措施的直接偏好优化。
在常识、语言理解、数学、代码、长上下文和逻辑推理等基准测试中,Phi-3-Medium-4K-Instruct 在同尺寸及更大尺寸的模型中展现出稳健且最先进的性能。
资源与技术文档:
| 短上下文 | 长上下文 | |
|---|---|---|
| Medium | 4K [openMind] | 128K [openMind] |
主要使用场景
该模型旨在广泛应用于英语的商业和研究领域。它适用于需要以下特性的通用人工智能系统和应用:
我们的模型旨在加速语言和多模态模型的研究,并作为生成式人工智能驱动功能的构建模块。
使用场景考量
我们的模型并非专门为所有下游用途设计或评估。开发人员在选择使用场景时,应考虑语言模型的常见局限性,并在特定下游用途中使用之前,对准确性、安全性和公平性进行评估和缓解,特别是在高风险场景中。开发人员应了解并遵守与其使用场景相关的适用法律法规(包括隐私、贸易合规法律等)。
本模型卡片中的任何内容均不应被解释为或视为对模型发布所依据的许可的限制或修改。
Phi-3-Medium-4K-Instruct 已集成到 transformers 的开发版本(4.40.2)中。在通过 pip 发布正式版本之前,请确保执行以下操作之一:
加载模型时,确保将 trust_remote_code=True 作为 from_pretrained() 函数的参数传入。
将本地 transformers 更新至开发版本:pip uninstall -y transformers && pip install transformers。此命令是克隆并从源代码安装的替代方法。
当前 transformers 版本可通过以下命令验证:pip list | grep transformers。
Phi-3-Medium-4K-Instruct 也可在 Azure AI Studio 中使用。
Phi-3-Medium-4K-Instruct 支持的词汇量最多为 32064 个 token。分词器文件 已提供占位符 token,可用于下游微调,也可扩展至模型的词汇量上限。
考虑到训练数据的特性,Phi-3-Medium-4K-Instruct 模型最适合使用如下对话格式的提示词。 您可以使用通用模板将提示词作为问题提供,如下所示:
<|user|>\nQuestion <|end|>\n<|assistant|>例如:
<|user|>
How to explain Internet for a medieval knight?<|end|>
<|assistant|>模型在 <|assistant|> 之后生成文本。对于少样本提示,可按以下格式设置提示:
<|user|>
I am going to Paris, what should I see?<|end|>
<|assistant|>
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\nThese are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world."<|end|>
<|user|>
What is so great about #1?<|end|>
<|assistant|>以下代码片段展示了如何快速在 GPU 上运行模型:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
torch.random.manual_seed(0)
model_id = "microsoft/Phi-3-medium-4k-instruct"
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
]
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 500,
"return_full_text": False,
"temperature": 0.0,
"do_sample": False,
}
output = pipe(messages, **generation_args)
print(output[0]['generated_text'])某些应用程序/框架可能不会在对话开头包含 BOS 标记(<s>)。请确保包含此标记,因为它能带来更可靠的结果。
与其他语言模型一样,Phi 系列模型在某些情况下可能会表现出不公平、不可靠或冒犯性的行为。需要注意的一些局限性行为包括:
开发人员应采用负责任的 AI 最佳实践,并负责确保特定用例符合相关法律法规(例如隐私、贸易等)。需要考虑的重要方面包括:
我们的训练数据来源广泛,总计 4.8 万亿 tokens(包含 10% 的多语言数据),由以下部分组合而成:
我们专注于可能提高模型推理能力的数据质量,并对公开可用文档进行筛选,以确保其包含适当水平的知识。例如,某一天英超联赛的比赛结果可能是前沿模型的良好训练数据,但对于小尺寸模型,我们需要移除此类信息,以便为推理保留更多模型容量。有关数据的更多详细信息,请参见 Phi-3 技术报告。
我们报告了Phi-3-Medium-4K-Instruct在标准开源基准测试中的结果,这些基准测试用于衡量模型的推理能力(包括常识推理和逻辑推理)。我们将其与Mixtral-8x22b、Gemini-Pro、Command R+ 104B、Llama-3-70B-Instruct、GPT-3.5-Turbo-1106以及GPT-4-Turbo-1106(Chat)进行了比较。
所有报告的数值均通过完全相同的流程生成,以确保数值的可比性。由于评估中略有不同的选择,这些数值可能与其他已发布的数值存在差异。
按照当前标准,我们使用少样本提示来评估模型,温度设为0。 提示和样本数量是Microsoft内部语言模型评估工具的一部分,特别是我们并未针对Phi-3对该流程进行任何优化。 更具体地说,我们不会更改提示、选择不同的少样本示例、修改提示格式或对模型进行任何其他形式的优化。
每个基准测试的k-shot示例数量如下表所示。
| 基准测试 | Phi-3-Medium-4K-Instruct 14b | Command R+ 104B | Mixtral 8x22B | Llama-3-70B-Instruct | GPT3.5-Turbo version 1106 | Gemini Pro | GPT-4-Turbo version 1106 (Chat) |
|---|---|---|---|---|---|---|---|
| AGI Eval 5-shot | 50.2 | 50.1 | 54.0 | 56.9 | 48.4 | 49.0 | 59.6 |
| MMLU 5-shot | 78.0 | 73.8 | 76.2 | 80.2 | 71.4 | 66.7 | 84.0 |
| BigBench Hard 3-shot | 81.4 | 74.1 | 81.8 | 80.4 | 68.3 | 75.6 | 87.7 |
| ANLI 7-shot | 55.8 | 63.4 | 65.2 | 68.3 | 58.1 | 64.2 | 71.7 |
| HellaSwag 5-shot | 82.4 | 78.0 | 79.0 | 82.6 | 78.8 | 76.2 | 88.3 |
| ARC Challenge 10-shot | 91.6 | 86.9 | 91.3 | 93.0 | 87.4 | 88.3 | 95.6 |
| ARC Easy 10-shot | 97.7 | 95.7 | 96.9 | 98.2 | 96.3 | 96.1 | 98.8 |
| BoolQ 2-shot | 86.5 | 86.1 | 82.7 | 89.1 | 79.1 | 86.4 | 91.3 |
| CommonsenseQA 10-shot | 82.8 | 82.0 | 82.0 | 84.4 | 79.6 | 81.8 | 86.7 |
| MedQA 2-shot | 69.9 | 59.2 | 67.9 | 78.5 | 63.4 | 58.2 | 83.7 |
| OpenBookQA 10-shot | 87.4 | 86.8 | 88.6 | 91.8 | 86.0 | 86.4 | 93.4 |
| PIQA 5-shot | 87.9 | 86.4 | 85.0 | 85.3 | 86.6 | 86.2 | 90.1 |
| Social IQA 5-shot | 80.2 | 75.3 | 78.2 | 81.1 | 68.3 | 75.4 | 81.7 |
| TruthfulQA (MC2) 10-shot | 75.1 | 57.8 | 67.4 | 81.9 | 67.7 | 72.6 | 85.2 |
| WinoGrande 5-shot | 81.5 | 77.0 | 75.3 | 83.3 | 68.8 | 72.2 | 86.7 |
| TriviaQA 5-shot | 73.9 | 82.8 | 84.5 | 78.5 | 85.8 | 80.2 | 73.3 |
| GSM8K Chain of Thought 8-shot | 91.0 | 78.3 | 83.8 | 93.5 | 78.1 | 80.4 | 94.2 |
| HumanEval 0-shot | 62.2 | 61.6 | 39.6 | 78.7 | 62.2 | 64.4 | 79.9 |
| MBPP 3-shot | 75.2 | 68.9 | 70.7 | 81.3 | 77.8 | 73.2 | 86.7 |
| Average | 78.5 | 75.0 | 76.3 | 82.5 | 74.3 | 75.4 | 85.2 |
我们在下表中仔细研究了80个公共基准数据集的不同类别:
| 基准测试 | Phi-3-Medium-4K-Instruct 14b | Command R+ 104B | Mixtral 8x22B | Llama-3-70B-Instruct | GPT3.5-Turbo version 1106 | Gemini Pro | GPT-4-Turbo version 1106 (Chat) |
|---|---|---|---|---|---|---|---|
| Popular aggregated benchmark | 75.4 | 69.9 | 73.4 | 76.3 | 67.0 | 67.5 | 80.5 |
| Reasoning | 84.1 | 79.3 | 81.5 | 86.7 | 78.3 | 80.4 | 89.3 |
| Language understanding | 73.9 | 75.6 | 78.1 | 76.9 | 68.7 | 76.2 | 80.7 |
| Code generation | 66.1 | 68.6 | 60.0 | 69.3 | 70.4 | 66.7 | 76.1 |
| Math | 52.8 | 45.3 | 52.5 | 59.7 | 52.8 | 50.9 | 67.1 |
| Factual knowledge | 48.3 | 60.3 | 60.6 | 52.4 | 63.4 | 54.6 | 45.9 |
| Multilingual | 62.9 | 67.8 | 69.8 | 62.0 | 67.0 | 73.4 | 78.2 |
| Robustness | 66.5 | 57.9 | 65.5 | 78.7 | 69.3 | 69.7 | 84.6 |
ONNX Runtime 生态系统现已支持 Phi-3 Medium 模型在各种平台和硬件上运行。 优化后的 phi-3 模型也以 ONNX 格式在此发布,可配合 ONNX Runtime 在 CPU 和 GPU 上跨设备运行,包括服务器平台、Windows、Linux 和 Mac 桌面系统以及移动 CPU,并为每个目标设备提供最适合的精度。DirectML GPU 加速支持 Windows 桌面 GPU(AMD、Intel 和 NVIDIA)。 除 DML 外,ONNX Runtime 还为 Phi-3 Medium 提供跨平台支持,覆盖从 CPU、GPU 到移动设备的多种设备。 以下是我们添加的部分优化配置:
本模型采用 MIT 许可证。
本项目可能包含项目、产品或服务的商标或徽标。Microsoft 商标或徽标的授权使用须遵守 Microsoft 商标与品牌指南。在本项目的修改版本中使用 Microsoft 商标或徽标不得引起混淆或暗示 Microsoft 的赞助。任何第三方商标或徽标的使用均受该第三方政策的约束。