weixin_72661020/Yi-1.5-34B-Chat-16K
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Yi-1.5-34B-Chat-16K 在昇腾 NPU 上的部署

1. 简介

本文档记录 01ai/Yi-1.5-34B-Chat-16K 在昇腾 NPU 环境的适配与验证结果。

Yi-1.5-34B-Chat-16K 是一个基于 LLaMA 架构的 340 亿参数规模的大语言模型,支持 16K 上下文长度,采用分组查询注意力(Grouped Query Attention, GQA)机制,并使用 bfloat16 精度。

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/01ai/Yi-1.5-34B-Chat-16K
  • 权重下载地址(HuggingFace):https://huggingface.co/01ai/Yi-1.5-34B-Chat-16K

2. 验证环境

组件版本
NPUAscend910B
CANN25.5.2
PyTorch2.9.0
torch_npu2.9.0.post1
transformers4.40.0+
vllm0.18.0+empty
vllm_ascend0.18.0rc1
  • NPU:2 逻辑卡,每卡 65.8 GB
  • 模型路径:/opt/atomgit/Yi-1.5-34B-Chat-16K/model/01ai/Yi-1.5-34B-Chat-16K

3. 模型配置

参数值
模型类型llama
架构LlamaForCausalLM
参数量34B
隐藏层大小7168
注意力头数56
KV 头数8 (GQA)
层数60
中间层大小20480
最大位置编码16384
词表大小64000
激活函数silu
精度bfloat16

4. 服务启动

使用 transformers + torch_npu 直接推理:

python3 inference.py

使用 vLLM-Ascend 部署:

export ASCEND_RT_VISIBLE_DEVICES=0,1
export VLLM_USE_MODELSCOPE=true
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True

vllm serve /opt/atomgit/Yi-1.5-34B-Chat-16K/model/01ai/Yi-1.5-34B-Chat-16K \
  --host 0.0.0.0 \
  --port 8000 \
  --tensor-parallel-size 2 \
  --dtype bfloat16 \
  --trust-remote-code \
  --gpu-memory-utilization 0.90 \
  --max-model-len 16384

5. 冒烟验证

# 检查 NPU 状态
npu-smi info

# 推理测试
python3 -c "
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch, torch_npu

tokenizer = AutoTokenizer.from_pretrained('/opt/atomgit/Yi-1.5-34B-Chat-16K/model/01ai/Yi-1.5-34B-Chat-16K', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    '/opt/atomgit/Yi-1.5-34B-Chat-16K/model/01ai/Yi-1.5-34B-Chat-16K',
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map='auto'
)
inputs = tokenizer('Hello, how are you?', return_tensors='pt')
if 'npu' in str(model.device):
    inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
    outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
"

6. 性能参考

测试条件:单次推理,bfloat16 精度,max_length=50。

指标数值
推理时间6.48 秒
硬件Ascend910B
精度bfloat16
设备映射device_map="auto"

7. 精度评测

测试输入模型输出
Hello, how are you?Hello, how are you?
What is 1+1?2
中国的首都是哪里?北京
Explain quantum computing.Quantum computing uses quantum bits...

8. 注意事项

  • 34B 模型在 bfloat16 精度下约需 68 GB 显存,建议使用 device_map="auto" 或多卡部署
  • 使用 ModelScope SDK 下载模型时指定 cache_dir 参数
  • 如遇到内存不足,可尝试降低 gpu_memory_utilization
  • torch_npu 已预装,无需额外安装