HuggingFace镜像/Qwen2.5-3B-Instruct
模型介绍文件和版本分析
下载使用量0

Qwen2.5-3B-Instruct

简介

Qwen2.5 是 Qwen 系列大型语言模型的最新版本。我们发布了参数规模从 0.500 亿到 720 亿不等的多个基础语言模型和指令微调语言模型。相比 Qwen2,Qwen2.5 带来了以下改进:

  • 知识量显著增加,并且在代码和数学能力方面有大幅提升,这得益于我们在这些领域专门训练的专家模型。
  • 在指令遵循、长文本生成(超过 8K tokens)、结构化数据理解(如表格)以及结构化输出生成(尤其是 JSON 格式)方面有显著改进。对系统提示的多样性更具适应性,增强了聊天机器人的角色扮演实现和条件设定能力。
  • 长上下文支持,最长可达 128K tokens,生成文本长度可达 8K tokens。
  • 多语言支持,覆盖超过 29 种语言,包括中文、英语、法语、西班牙语、葡萄牙语、德语、意大利语、俄语、日语、韩语、越南语、泰语、阿拉伯语等。

本仓库包含经过指令微调的 30 亿参数 Qwen2.5 模型,其特点如下:

  • 类型:因果语言模型
  • 训练阶段:预训练与后训练
  • 架构:采用 RoPE、SwiGLU、RMSNorm、Attention QKV 偏置和词嵌入共享的 transformers
  • 参数数量:30.9 亿
  • 非嵌入层参数数量:27.7 亿
  • 层数:36
  • 注意力头数量(GQA):Q 头 16 个,KV 头 2 个
  • 上下文长度:完整上下文 32,768 tokens,生成长度 8192 tokens

更多详情,请参考我们的 博客、GitHub 和 文档。

环境要求

Qwen2.5 的代码已集成到最新版 Hugging Face transformers 中,建议您使用最新版本的 transformers。

若使用 transformers<4.37.0,您将遇到以下错误:

KeyError: 'qwen2'

快速入门

以下提供一个使用apply_chat_template的代码片段,向您展示如何加载分词器和模型以及如何生成内容。

from openmind import AutoModelForCausalLM,AutoTokenizer, AutoModel, is_torch_npu_available
from openmind_hub import snapshot_download
import torch
import argparse
import torch.nn.functional as F


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="zhouhui/Qwen2.5-3B-Instruct",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
        
    
    model = AutoModelForCausalLM.from_pretrained(
        model_path,
        torch_dtype="auto",
        device_map="auto"
    )
    tokenizer = AutoTokenizer.from_pretrained(model_path)

    prompt = "你好,你是谁啊?哪个公司做的模型"
    messages = [
        {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
        {"role": "user", "content": prompt}
    ]
    text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True
    )
    model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

    generated_ids = model.generate(
        **model_inputs,
        max_new_tokens=512
    )
    generated_ids = [
        output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
    ]

    response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
    print("response")
    print(response)


if __name__ == "__main__":
    main()

评估与性能

详细的评估结果已在本📑 博客中公布。

有关 GPU 内存要求及相应吞吐量,请参见此处的结果。

引用

如果您觉得我们的工作对您有所帮助,欢迎引用我们的成果。

@misc{qwen2.5,
    title = {Qwen2.5: A Party of Foundation Models},
    url = {https://qwenlm.github.io/blog/qwen2.5/},
    author = {Qwen Team},
    month = {September},
    year = {2024}
}

@article{qwen2,
      title={Qwen2 Technical Report}, 
      author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
      journal={arXiv preprint arXiv:2407.10671},
      year={2024}
}