本文档记录 Granite-4.1-3B 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。
Granite-4.1-3B 是 IBM 开发的 3B 参数密集解码器语言模型,采用标准 Transformer 架构,支持 GQA(Grouped Query Attention)、RoPE 位置编码和 RMSNorm。模型支持 131K 上下文窗口,适用于对话、文本分类、RAG、代码生成等多种任务。
从模型配置看,Granite-4.1-3B 走 GraniteForCausalLM 推理链路,vLLM 已原生支持该架构,在 Ascend NPU 上无需代码修改即可直接部署。
相关获取地址:
quay.io/ascend/vllm-ascend:v0.18.0rc1参考文档:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.53.3 |
torch-npu | 2.9.0.post1+gitee7ba04 |
cann | 8.5.1 |
1 卡 Atlas 910B4(32GB HBM)./granite-4.1-3b8000pip install -U atomgit
python -c "
from atomgit_hub import snapshot_download
snapshot_download('hf_mirrors/ibm-granite/granite-4.1-3b', local_dir='./granite-4.1-3b')
"已验证通过的启动命令:
export VLLM_WORKER_MULTIPROC_METHOD=spawn
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
vllm serve ./granite-4.1-3b \
--host 0.0.0.0 \
--port 8000 \
--dtype bfloat16 \
--served-model-name granite-4.1-3b \
--max-num-seqs 16 \
--max-model-len 4096 \
--gpu-memory-utilization 0.8启动后可通过以下命令验证:
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": "Hello, how are you?"}
],
"temperature": 0.7,
"max_tokens": 64
}'基础检查:
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.2,
"max_tokens": 64
}'验证结果:
/v1/models 返回 200/v1/chat/completions 返回 200,输出内容符合预期from vllm import LLM, SamplingParams
llm = LLM(
model="./granite-4.1-3b",
dtype="bfloat16",
max_model_len=4096,
gpu_memory_utilization=0.8
)
prompts = ["Hello, how are you?"]
sampling_params = SamplingParams(temperature=0.7, max_tokens=64)
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
print(f"Prompt: {output.prompt}")
print(f"Output: {output.outputs[0].text}")验证结果:模型输出自然流畅,语义连贯。
测试条件:Atlas 910B4 单卡(32GB),enforce_eager 模式,bfloat16 精度。
| Prompt 长度 | 生成 Token 数 | 总延迟 | TTFT | TPOT |
|---|---|---|---|---|
| Short(~5 tokens) | 64 | 5.211 s | 1563.45 ms | 57.91 ms |
| Medium(~11 tokens) | 128 | 7.957 s | 2387.22 ms | 57.15 ms |
| Long(~30 tokens) | 256 | 20.504 s | 6151.13 ms | 56.28 ms |
| 指标 | 数值 |
|---|---|
duration | 11.002 s |
request_throughput | 0.364 req/s |
output_throughput | 46.54 tok/s |
total_token_throughput | 48.90 tok/s |
| 指标 | 数值 |
|---|---|
| 模型权重 | 6.39 GB |
| KV Cache 可用 | 13.68 GB |
| 属性 | 值 |
|---|---|
| 架构 | GraniteForCausalLM |
| 参数量 | 3.4B |
| 隐藏层大小 | 2560 |
| 层数 | 40 |
| Attention Heads | 40(GQA,KV Heads=8) |
| 位置编码 | RoPE(theta=10M) |
| 激活函数 | SwiGLU(silu) |
| 归一化 | RMSNorm |
| 数据类型 | bfloat16 |
| 最大上下文 | 131072 |
| 权重文件 | 2 × safetensors |
NPU 初始化:Ascend NPU 要求多进程使用 spawn 方式,启动前需设置 export VLLM_WORKER_MULTIPROC_METHOD=spawn
内存利用率:910B4 32GB 上建议设置 --gpu-memory-utilization 0.7~0.8,模型权重约占用 6.4GB
性能优化:当前基准测试在 enforce_eager 模式下进行,未启用 ACL Graph 编译优化。如需更高性能,可尝试:
--enforce-eager,启用 ACL Graph 模式--max-num-batched-tokens 和 --max-num-seqs--compilation-config 配置图捕获尺寸模型来源:本报告使用 hf_mirrors/ibm-granite/granite-4.1-3b 镜像下载权重,与 HuggingFace 官方权重一致
NPU vs CPU 精度对比(CPU 为基线,NPU 为验证目标):
| 指标 | 数值 |
|---|---|
| 测试用例数 | 待运行(已有性能基准数据,需补充精度对比) |
| 最大 logits 差异 | 待运行 |
| 预测一致性 | 待运行 |
| 精度要求 | NPU vs CPU 最大 logits 误差 < 1% |
| 精度结论 | ⏳ 推理与基准测试已完成(TTFT 1.56s,TPOT 57.9ms),精度对比待运行 |
精度评测源代码和日志详见 eval/ 目录。