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

Qwen2.5-Coder-32B-Instruct

简介

Qwen2.5-Coder 是最新系列的代码专用 Qwen 大型语言模型(前身为 CodeQwen)。截至目前,Qwen2.5-Coder 已涵盖六种主流模型规模,分别为 0.5、1.5、3、7、14、320 亿参数,以满足不同开发者的需求。相比 CodeQwen1.5,Qwen2.5-Coder 带来了以下改进:

  • 代码生成、代码推理和代码修复能力显著提升。基于强大的 Qwen2.5,我们将训练 tokens 扩展至 5.5 万亿,包括源代码、文本-代码关联数据、合成数据等。Qwen2.5-Coder-32B 已成为当前最先进的开源代码大语言模型(codeLLM),其编码能力可与 GPT-4o 相媲美。
  • 为 Code Agents 等实际应用场景提供更全面的基础能力。在增强编码能力的同时,还保持了其在数学和通用能力方面的优势。
  • 长上下文支持,最长可达 128K tokens。

本仓库包含经指令微调的 32B Qwen2.5-Coder 模型,具有以下特点:

  • 类型:因果语言模型
  • 训练阶段:预训练与后训练
  • 架构:采用 RoPE、SwiGLU、RMSNorm 和 Attention QKV 偏置的 transformers
  • 参数数量:325 亿
  • 非嵌入层参数数量:310 亿
  • 层数:64
  • 注意力头数量(GQA):Q 为 40 个,KV 为 8 个
  • 上下文长度:完整的 131,072 tokens
    • 关于如何部署 Qwen2.5 以处理长文本的详细说明,请参考本节。

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

环境要求

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

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

KeyError: 'qwen2'

快速入门

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

from modelscope import AutoModelForCausalLM, AutoTokenizer

model_name = "Qwen/Qwen2.5-Coder-32B-Instruct"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "write a quick sort algorithm."
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]

处理长文本

当前 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 配置。

评估与性能

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

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

引用

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

@article{hui2024qwen2,
  title={Qwen2. 5-Coder Technical Report},
  author={Hui, Binyuan and Yang, Jian and Cui, Zeyu and Yang, Jiaxi and Liu, Dayiheng and Zhang, Lei and Liu, Tianyu and Zhang, Jiajun and Yu, Bowen and Dang, Kai and others},
  journal={arXiv preprint arXiv:2409.12186},
  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}
}