本文档记录 baichuan-inc/baichuan-7B 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。
baichuan-7B 是百川智能推出的 7B 参数预训练基座模型,基于 BaiChuanForCausalLM 架构(自定义实现),32 层 Transformer,hidden_size=4096,使用自定义 modeling_baichuan.py 代码,需 --trust-remote-code 参数加载。
相关获取地址:
quay.io/ascend/vllm-ascend:v0.18.0rc1参考文档:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.57.6 |
torch-npu | 2.9.0.post1+gitee7ba04 |
modelscope | 1.35.3 |
1 逻辑卡 (Ascend910_9362)/opt/atomgit/models/baichuan-7B8000启动前可先检查端口:
ss -lntp | grep ':8000 ' || true已验证通过的启动命令:
export ASCEND_RT_VISIBLE_DEVICES=0
export VLLM_USE_MODELSCOPE=false
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
# 方式一:enforce-eager 模式(推荐,首次验证使用)
vllm serve /opt/atomgit/models/baichuan-7B \
--host 0.0.0.0 \
--port 8000 \
--data-parallel-size 1 \
--tensor-parallel-size 1 \
--served-model-name baichuan-7B \
--max-num-seqs 32 \
--max-model-len 4096 \
--trust-remote-code \
--dtype bfloat16 \
--gpu-memory-utilization 0.85 \
--enforce-eager
# 方式二:PIECEWISE 编译模式(性能更优)
vllm serve /opt/atomgit/models/baichuan-7B \
--host 0.0.0.0 \
--port 8000 \
--data-parallel-size 1 \
--tensor-parallel-size 1 \
--served-model-name baichuan-7B \
--max-num-seqs 32 \
--max-model-len 4096 \
--trust-remote-code \
--dtype bfloat16 \
--gpu-memory-utilization 0.85关键参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
--tensor-parallel-size | 1 | 7B 模型单卡即可运行 |
--max-model-len | 4096 | 模型 max_position_embeddings 限制 |
--trust-remote-code | - | 必须开启,模型使用自定义架构代码 |
--gpu-memory-utilization | 0.85 | KV 缓存占用 85% NPU 内存 |
--enforce-eager | - | 禁用图编译,首次验证推荐 |
--dtype | bfloat16 | 部署精度(原始权重为 float32) |
# 从 ModelScope 下载模型权重
modelscope download --model baichuan-inc/baichuan-7B \
--local_dir /opt/atomgit/models/baichuan-7Bpython inference.py --prompt "What is the capital of France?"python inference.py --input prompts.txt --output results.jsonpython inference.py --interactivepython inference.py --interactive --multi-turnpython inference.py --prompt "Explain quantum entanglement." --streampython inference.py --api-base http://192.168.1.100:8000/v1 --prompt "Hello"baichuan-7B 为预训练基座模型,推荐使用 completions API:
python inference.py --prompt "The capital of France is" --use-completion基础检查:
curl -sf http://127.0.0.1:8000/v1/models
curl -sf http://127.0.0.1:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "baichuan-7B",
"prompt": "The capital of France is",
"temperature": 0,
"max_tokens": 32
}'验证结果:
/v1/models 返回 200/v1/completions 返回 200,模型正确续写文本使用 benchmark_perf.py 脚本,分三个维度测试:
python benchmark_perf.py \
--api-base http://127.0.0.1:8000/v1 \
--model baichuan-7B \
--output ./benchmark_results.json测试条件:单卡 Ascend910_9362,enforce-eager 模式,max_model_len=4096。
| 输出 tokens | 延迟 (s) | 输出吞吐 (tok/s) |
|---|---|---|
| 32 | 1.04 | 30.8 |
| 64 | 2.06 | 31.0 |
| 128 | 3.92 | 32.7 |
| 256 | 8.17 | 31.3 |
平均输出吞吐:~31.5 tok/s
| 输入 tokens | TTFT (s) |
|---|---|
| 32 | 0.078 |
| 128 | 0.072 |
| 512 | 0.068 |
| 1024 | 0.070 |
平均 TTFT:~0.072s
| 并发数 | 请求总数 | 总耗时 (s) | 输出吞吐 (tok/s) | 总吞吐 (tok/s) | RPS | P99 延迟 (s) |
|---|---|---|---|---|---|---|
| 1 | 4 | 16.33 | 31.36 | 62.96 | 0.24 | 4.167 |
| 4 | 16 | 17.56 | 116.61 | 234.14 | 0.91 | 4.415 |
| 8 | 32 | 16.38 | 248.45 | 498.94 | 1.95 | 4.277 |
| 16 | 64 | 16.37 | 502.11 | 1009.22 | 3.91 | 4.237 |
| 32 | 128 | 17.60 | 930.87 | 1869.01 | 7.27 | 4.593 |
| 指标 | 数值 |
|---|---|
| 模型加载时间 | ~5s (pytorch_model.bin) |
| 模型权重占用 | ~13.5 GB |
| 单请求输出吞吐 | ~31.5 tok/s |
| 首 Token 延迟 (TTFT) | ~0.072s |
| 32 并发输出吞吐 | ~931 tok/s |
| 32 并发总吞吐 | ~1869 tok/s |
| 32 并发 RPS | ~7.3 |
注:性能数据基于 enforce-eager 模式,使用 PIECEWISE 编译模式可获得更优性能。
使用 GPQA(Graduate-Level Google-Proof Q&A)数据集做精度评测。
modelscope download --dataset modelscope/gpqaeval_gpqa.py 脚本,32 并发逐题发送请求python eval_gpqa.py \
--dataset /tmp/GPQA/gpqa_main.csv \
--model baichuan-7B \
--output ./gpqa_results.json \
--workers 32 \
--use-completion \
--few-shot| 指标 | 数值 |
|---|---|
| 数据集 | GPQA |
| 总题数 | 448 |
| 正确数 | 119 |
| 准确率 | 26.6% |
| GPU/CPU 基线 | 27.0% |
| 指标 | NPU | GPU/CPU | 差异 |
|---|---|---|---|
| 准确率 | 26.6% | 27.0% | 0.4% |
结论:NPU 与 GPU/CPU 准确率差异 0.4% < 1%,通过精度验证。
| 学科 | 正确/总数 | 准确率 |
|---|---|---|
| Biology | 20/78 | 25.6% |
| Chemistry | 46/183 | 25.1% |
| Physics | 53/187 | 28.3% |
| 特性 | 说明 | 昇腾兼容性 |
|---|---|---|
| 架构类型 | BaiChuanForCausalLM | ✅ 已知支持 |
| 自定义代码 | modeling_baichuan.py | ✅ trust-remote-code 加载 |
| 注意力机制 | Full Attention | ✅ 昇腾支持 |
| 精度 | FP32 → BF16 部署 | ✅ 昇腾支持 |
| 层数 | 32 层 | ✅ 支持 |
| hidden_size | 4096 | ✅ 支持 |
| num_attention_heads | 32 | ✅ 支持 |
| max_position_embeddings | 4096 | ✅ 支持 |
| vocab_size | 64000 | ✅ 支持 |
| 编译模式 | PIECEWISE (ACL Graph) | ✅ 支持 |
baichuan-7B 使用 BaiChuanForCausalLM 架构,已在 vLLM-Ascend 注册表中注册,无特殊不兼容算子。需 --trust-remote-code 加载自定义模型代码。
基座模型特性:baichuan-7B 为预训练基座模型,未经指令微调。推荐使用 completions API + few-shot prompting 进行推理,而非指令式提示。
max_model_len 限制:模型 max_position_embeddings=4096,输入 + 输出总长度不能超过此限制。
trust-remote-code:模型使用自定义 modeling_baichuan.py 代码,启动时必须添加 --trust-remote-code 参数。
模型下载:权重文件为 pytorch_model.bin(~14GB),下载时间较长。
验证日期:2026-05-16 验证工具版本:vllm-ascend v0.18.0rc1 验证人:Ascend NPU 适配验证