本文档记录 IBM Granite 4.1-3B 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。
Granite-4.1-3B 是 IBM 推出的稠密 Transformer 解码器模型,采用标准 Decoder-only 架构,特点包括:
attention_multiplier、embedding_multiplier、residual_multiplier、logits_scalingtie_word_embeddings 共享输入输出词嵌入vLLM 原生已支持 GraniteForCausalLM 架构,在昇腾 NPU 上可直接加载运行,无需额外算子适配。
相关获取地址:
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 |
npu-smi | 25.5.1 |
1 逻辑卡(Ascend 910B4)/opt/atomgit/models/ibm-granite/granite-4___1-3b8000bfloat16~6.4 GB启动前可先检查端口:
ss -lntp | grep ':8000 ' || true已验证通过的启动命令:
export ASCEND_RT_VISIBLE_DEVICES=0
export VLLM_USE_MODELSCOPE=true
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export OMP_PROC_BIND=false
export OMP_NUM_THREADS=1
export TASK_QUEUE_ENABLE=1
export VLLM_ENABLE_V1_MULTIPROCESSING=0
vllm serve /opt/atomgit/models/ibm-granite/granite-4___1-3b \
--host 0.0.0.0 \
--port 8000 \
--data-parallel-size 1 \
--tensor-parallel-size 1 \
--seed 1024 \
--served-model-name granite-4.1-3b \
--max-num-seqs 32 \
--max-model-len 8192 \
--trust-remote-code \
--gpu-memory-utilization 0.90注意:当前环境需显式设置
VLLM_ENABLE_V1_MULTIPROCESSING=0,否则 EngineCore 子进程在初始化 NPU 设备上下文时可能出现rtSetDefaultDeviceId execution failed错误。
基础检查:
curl -sf http://127.0.0.1:8000/v1/models
curl -sf http://127.0.0.1:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "granite-4.1-3b",
"messages": [
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0,
"max_tokens": 64
}'验证结果:
/v1/models 返回 200/v1/chat/completions 返回 200The capital of France is Paris.测试条件:512 input / 128 output / concurrency=8 / 32 prompts,连续两次取第二次数据。
| 指标 | 数值 |
|---|---|
duration | 20.479 s |
request_throughput | 1.563 req/s |
output_throughput | 187.848 tok/s |
total_token_throughput | 1007.602 tok/s |
压测脚本:python benchmark.py --num-prompts 32 --input-len 512 --output-len 128 --concurrency 8
使用自研对比脚本 accuracy_micro.py 对 NPU(vLLM bf16) 与 CPU(transformers bf16) 做了首 token 贪婪解码一致性评测。
| 指标 | 数值 |
|---|---|
| 评测工具 | accuracy_micro.py |
| 对比基线 | CPU (transformers bfloat16) |
| 样本数 | 10 |
| Greedy Top-1 匹配率 | 100% (10/10) |
| 平均 Top-5 重叠率 | 4.8/5 (96%) |
| 精度判定 | PASSED |
判定说明:LLM 跨硬件精度验证以 greedy top-1 token 一致性为核心指标。不同框架/硬件的 bf16 attention 实现存在累积误差,导致 logprob 绝对值差异较大,但 token 排序与贪婪解码结果高度一致,符合生产环境精度要求。
多进程启动问题:当前环境(单卡 Ascend 910B4)若使用默认的 V1 多进程模式,子进程初始化时可能因设备上下文为空而失败。解决方案是显式设置 VLLM_ENABLE_V1_MULTIPROCESSING=0。
ACL Graph 编译:首次启动时 ACL Graph 编译需要约 30~60 秒(取决于 max_model_len 和 batch size 配置),后续推理复用编译缓存,无需重新编译。
内存配置:建议设置 PYTORCH_NPU_ALLOC_CONF=expandable_segments:True,可减少 NPU 内存碎片,提升长序列场景的稳定性。
trust_remote_code:Granite 模型在 transformers 中需要 trust_remote_code=True,vLLM 侧同样需要显式指定。
| 文件 | 说明 |
|---|---|
inference.py | 离线推理脚本(支持批量推理、参数自定义、结果保存) |
benchmark.py | 性能基准测试脚本(支持吞吐、并发等维度测试) |
accuracy_eval.py | 精度评测脚本(NPU vs CPU 对比) |
readme.md | 本部署调优文档 |
*.log / *.json | 运行日志与评测结果 |