本文档记录 baichuan-inc/Baichuan2-7B-Chat 模型在 vLLM-Ascend 环境的快速部署与验证结果。
Baichuan2-7B-Chat 是百川智能推出的 70 亿参数大语言模型,支持中英双语对话,具备通用对话和推理能力。
相关获取地址:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0 |
transformers | 4.57.6 |
torch-npu | 2.9.0 |
CANN | 8.5.1 |
SOC | ascend910_9391 |
1 逻辑卡(Ascend 910B2,64GB HBM)/home/openmind/.cache/modelscope/hub/models/baichuan-inc/Baichuan2-7B-Chat| 参数 | 值 |
|---|---|
| 架构 | BaichuanForCausalLM |
| 参数量 | 7B |
| 层数 | 32 |
| 隐藏维度 | 4096 |
| 注意力头数 | 32 |
| 词表大小 | 125696 |
| 精度 | BF16(原始)/ Float16(vLLM 推理) |
# 从 ModelScope 下载
modelscope download --model baichuan-inc/Baichuan2-7B-Chat使用 vLLM-Ascend 加载模型进行推理:
from vllm import LLM, SamplingParams
MODEL_PATH = "baichuan-inc/Baichuan2-7B-Chat"
llm = LLM(
model=MODEL_PATH,
trust_remote_code=True,
dtype="float16",
tensor_parallel_size=1,
max_model_len=2048,
gpu_memory_utilization=0.9,
)
sampling = SamplingParams(max_tokens=64, temperature=0)
outputs = llm.generate(["The capital of France is"], sampling)
print(outputs[0].outputs[0].text)
# Paris.运行 4 项冒烟测试验证模型功能:
python3 smoke_test.py=== Baichuan2-7B-Chat vLLM-Ascend Smoke Test ===
[1/4] Testing basic generation...
PASS: Paris.
[2/4] Testing Chinese generation...
PASS: 中国的首都是北京。
[3/4] Testing batch generation...
[1] The answer to 2 + 2 is 4. This is a basic arithmetic operation...
[2] Large language models (LLMs) are a type of artificial intelligence...
[3] Silent branches sway, Leaves dance in golden sunlight, Nature whispers peace...
PASS: 3 prompts processed
[4/4] Testing math reasoning (GSM8K style)...
PASS: Shawn has five toys. He got two toys each from his mom and dad, so he received a...
=== All 4/4 tests PASSED (74.5s) ===验证项说明:
| 测试项 | 输入 | 预期 | 结果 |
|---|---|---|---|
| 英文基础生成 | The capital of France is | 包含 Paris | PASS |
| 中文生成 | 中国的首都是哪里? | 包含 北京 | PASS |
| 批量生成 | 3 个 prompt | 3 条非空输出 | PASS |
| 数学推理 | GSM8K 风格题目 | 包含正确答案 9 | PASS |
AI-ModelScope/gsm8kpython3 eval_gsm8k_vllm.py --tensor_parallel 1 --batch_size 64 --output logs/gsm8k_vllm.json| 指标 | 基线 | NPU 结果 | 差异 |
|---|---|---|---|
| GSM8K 5-shot | 28.00% | 28.05% (370/1319) | +0.05% |
GSM8K NPU 准确率 28.05%,与基线 28.00% 差异 +0.05%(< 1%),验证通过。
=== Baichuan2-7B-Chat GSM8K 5-shot vLLM-Ascend (tp=1, batch=64) ===
Total test samples: 1319
Loading model with vLLM-Ascend...
Model loaded.
Generating (1319 samples, batch=64)...
============================================================
Baichuan2-7B-Chat GSM8K 5-shot Results (vLLM-Ascend)
============================================================
Accuracy: 28.05% (370/1319)
Total time: 91s
Throughput: 14.44 samples/s
============================================================
Results saved to logs/gsm8k_vllm.json同时使用 transformers + PyTorch NPU 方案进行评测作为对比:
| 推理方案 | 精度 | 耗时 |
|---|---|---|
| vLLM-Ascend (float16) | 28.05% | 91s |
| PyTorch NPU (float32, 4卡并行) | 28.51% | 12473s |
use_cache 兼容性:使用 transformers 直接加载时,Baichuan2 的自定义 modeling 代码与 DynamicCache 不兼容。需设置 model.config.use_cache = False 和 GenerationConfig(use_cache=False)。推荐使用 vLLM-Ascend 方案以避免此问题。
vLLM dtype:vLLM 推理使用 float16(NPU 原生支持),无需使用 float32。
tokenizer 提示:vLLM 会提示使用 slow tokenizer,不影响推理结果,可忽略。
显存占用:float16 推理时模型约占用 14 GB HBM,单卡 64GB 即可运行。
此为 Chat 版本:模型已进行指令微调,适用于对话和推理场景,支持中英双语。