Phi-3-mini-4k-instruct 的功能测试

Model card 介绍

Phi-3-Mini-4K-Instruct 是一个 3.8B 参数、轻量级、最先进的开放模型,使用 Phi-3 数据集进行训练,其中包括合成数据和经过过滤的公开可用网站数据,重点是 高品质和推理密集的属性。 该型号属于 Phi-3 系列,Mini 版本有 4K 和 128K 两种变体,这是它可以支持的上下文长度(以令牌为单位)。

该模型经历了训练后过程,其中结合了监督微调和针对指令遵循和安全措施的直接偏好优化。 当根据测试常识、语言理解、数学、代码、长上下文和逻辑推理的基准进行评估时,Phi-3 Mini-4K-Instruct 在参数少于 130 亿的模型中展示了强大且最先进的性能。

资源和技术文档:

预期用途

主要用例

该模型旨在用于英语的商业和研究用途。 该模型适用于需要以下功能的应用:

  1. 内存/计算受限环境
  2. 延迟限制场景
  3. 强大的推理能力(尤其是代码、数学和逻辑)

我们的模型旨在加速语言和多模式模型的研究,用作生成人工智能驱动功能的构建块。

用例注意事项

我们的模型并非针对所有下游目的而专门设计或评估。 开发人员在选择用例时应考虑语言模型的常见限制,并在特定下游用例中使用之前评估和减轻准确性、安全性和复杂性,特别是对于高风险场景。 开发人员应了解并遵守与其用例相关的适用法律或法规(包括隐私、贸易合规法等)。

本模型卡中包含的任何内容均不应解释为或视为对该模型发布所依据的许可的限制或修改。

如何使用

Phi-3 Mini-4K-Instruct 已集成到 Transformer 的开发版本 (4.40.0) 中。 在通过 pip 发布正式版本之前,请确保您正在执行以下操作之一:

  • 加载模型时,确保 trust_remote_code=True 作为 from_pretrained() 函数的参数传递。
  • 将本地 Transformer 更新到开发版本:pip uninstall -y transformers && pip install git+https://github.com/huggingface/transformers.  前面的命令是从源克隆和安装的替代方法。

电流互感器版本可以通过以下方式验证:pip list | grep transformers.

Phi-3 Mini-4K-Instruct 也可用于  HuggingChat.

分词器

Phi-3 Mini-4K-Instruct 支持高达 32064 个令牌的词汇量。 分词器 文件已经提供了可用于下游微调的占位符标记,但它们也可以扩展到模型的词汇量大小。

聊天格式

鉴于训练数据的性质,Phi-3 Mini-4K-Instruct 模型最适合使用如下聊天格式进行提示。 您可以使用通用模板将提示作为问题提供,如下所示:

<|user|>\nQuestion <|end|>\n<|assistant|>

例如:

<|system|>
You are a helpful AI assistant.<|end|>
<|user|>
How to explain Internet for a medieval knight?<|end|>
<|assistant|>

其中模型在 <|assistant|> 之后生成文本。 如果出现少量提示,则提示格式可以如下:

<|system|>
You are a helpful AI assistant.<|end|>
<|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 = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-3-mini-4k-instruct", 
    device_map="cuda", 
    torch_dtype="auto", 
    trust_remote_code=True, 
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")

messages = [
    {"role": "system", "content": "You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user."},
    {"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 系列模型的行为方式可能不公平、不可靠或具有攻击性。 需要注意的一些限制行为包括:

  • 服务质量:Phi 模型主要根据英文文本进行训练。 英语以外的语言的性能会更差。 训练数据中代表性较少的英语语言品种可能会比标准美式英语表现更差。
  • 伤害的表征和刻板印象的
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值