Delicate02/granite-4.1-3b-ascend
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Granite-4.1-3B on vLLM-Ascend 0.18.0rc1

1. 简介

本文档记录 IBM Granite 4.1-3B 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。

Granite-4.1-3B 是 IBM 推出的稠密 Transformer 解码器模型,采用标准 Decoder-only 架构,特点包括:

  • GQA (Grouped Query Attention),40 头 attention / 8 头 KV
  • 特殊缩放系数:attention_multiplier、embedding_multiplier、residual_multiplier、logits_scaling
  • tie_word_embeddings 共享输入输出词嵌入
  • 最大序列长度 131072,支持长上下文推理

vLLM 原生已支持 GraniteForCausalLM 架构,在昇腾 NPU 上可直接加载运行,无需额外算子适配。

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/ibm-granite/granite-4.1-3b
  • 权重下载地址(HuggingFace):https://huggingface.co/ibm-granite/granite-4.1-3b
  • Docker Image (vLLM-Ascend 0.18.0rc1 ):quay.io/ascend/vllm-ascend:v0.18.0rc1

参考文档:

  • https://docs.vllm.ai/projects/ascend/zh-cn/v0.18.0/tutorials/models/index.html
  • https://github.com/vllm-project/vllm-ascend

2. 验证环境

组件版本
vllm-ascend0.18.0rc1
vllm0.18.0+empty
transformers4.57.6
torch-npu2.9.0.post1+gitee7ba04
npu-smi25.5.1
  • NPU:1 逻辑卡(Ascend 910B4)
  • 模型路径:/opt/atomgit/models/ibm-granite/granite-4___1-3b
  • 服务端口:8000
  • 模型精度:bfloat16
  • 模型权重大小:~6.4 GB

3. 服务启动

启动前可先检查端口:

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 错误。

4. Smoke 验证

基础检查:

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 返回 200
  • 推理结果正常,示例输出:The capital of France is Paris.

5. 性能参考

测试条件:512 input / 128 output / concurrency=8 / 32 prompts,连续两次取第二次数据。

指标数值
duration20.479 s
request_throughput1.563 req/s
output_throughput187.848 tok/s
total_token_throughput1007.602 tok/s

压测脚本:python benchmark.py --num-prompts 32 --input-len 512 --output-len 128 --concurrency 8

6. 精度评测

使用自研对比脚本 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 排序与贪婪解码结果高度一致,符合生产环境精度要求。

7. 注意事项

  1. 多进程启动问题:当前环境(单卡 Ascend 910B4)若使用默认的 V1 多进程模式,子进程初始化时可能因设备上下文为空而失败。解决方案是显式设置 VLLM_ENABLE_V1_MULTIPROCESSING=0。

  2. ACL Graph 编译:首次启动时 ACL Graph 编译需要约 30~60 秒(取决于 max_model_len 和 batch size 配置),后续推理复用编译缓存,无需重新编译。

  3. 内存配置:建议设置 PYTORCH_NPU_ALLOC_CONF=expandable_segments:True,可减少 NPU 内存碎片,提升长序列场景的稳定性。

  4. trust_remote_code:Granite 模型在 transformers 中需要 trust_remote_code=True,vLLM 侧同样需要显式指定。

8. 交付件清单

文件说明
inference.py离线推理脚本(支持批量推理、参数自定义、结果保存)
benchmark.py性能基准测试脚本(支持吞吐、并发等维度测试)
accuracy_eval.py精度评测脚本(NPU vs CPU 对比)
readme.md本部署调优文档
*.log / *.json运行日志与评测结果