Qwen2.5 是最新系列的 Qwen 大语言模型。针对 Qwen2.5,我们发布了多个基础语言模型和指令微调语言模型,参数规模从 0.50 亿到 720 亿不等。Qwen2.5 在 Qwen2 的基础上带来了以下改进:
本仓库包含经过指令微调的 70 亿参数 Qwen2.5 模型,其具有以下特点:
这里提供一个使用 apply_chat_template 的代码片段,向您展示如何加载分词器和模型以及如何生成内容。
import argparse
import torch
from openmind_hub import snapshot_download
from openmind import AutoModelForCausalLM, AutoTokenizer
def parse_args():
parser = argparse.ArgumentParser(description="Eval the LLM model")
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default=None,
)
args = parser.parse_args()
return args
def main():
args = parse_args()
if args.model_name_or_path:
model_path = args.model_name_or_path
else:
model_path = snapshot_download(
"JiangSuAscend/Qwen2.5-7B",
revision="main",
ignore_patterns=["*.h5", "*.ot", "*.msgpack"],
)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path, torch_dtype=torch.float16, device_map="auto"
)
prompt = "Q: What is the biggest animal?\nA:"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
input_ids = input_ids.to(model.device)
generation_output = model.generate(input_ids=input_ids, max_new_tokens=32)
print(tokenizer.decode(generation_output[0]))
if __name__ == "__main__":
main()当前的config.json设置的上下文长度最高为32,768个token。
为了处理超过32,768个token的超长输入,我们采用了YaRN技术。这是一种用于增强模型长度外推能力的方法,可确保模型在长文本上发挥最佳性能。
对于支持的框架,你可以在config.json中添加以下内容以启用YaRN:
{
...,
"rope_scaling": {
"factor": 4.0,
"original_max_position_embeddings": 32768,
"type": "yarn"
}
}在部署方面,我们建议使用 vLLM。
如果您不熟悉 vLLM,请参考我们的文档了解使用方法。
目前,vLLM 仅支持静态 YARN,这意味着无论输入长度如何,缩放因子都保持不变,这可能会影响短文本的性能。
我们建议仅在需要处理长上下文时才添加 rope_scaling 配置。