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

Granite-4.1-3B Ascend NPU 部署指南

项目简介

Granite-4.1-3B 是 IBM 的语言模型,具有约 3B 参数,基于 transformers 架构,支持文本生成和推理任务。

特性

  • 支持 Ascend NPU 推理加速
  • BF16 权重精度
  • 最大上下文长度 131,072 tokens
  • 40 层 Transformer 结构

环境信息

项目版本/内容
设备Ascend 910B

文件结构

granite-4.1-3b-ascend/
├── README.md       # 本文档
├── inference.py   # 推理脚本
└── test.log        # 运行日志

部署步骤

1. 设置环境变量

source /usr/local/Ascend/ascend-toolkit/set_env.sh

2. 准备模型文件

模型文件位于 /opt/atomgit/mxy/granite-4.1-3b/ 目录下。

3. 执行推理

cd granite-4.1-3b-ascend/
python3 inference.py --prompt "Hello, my name is" --max_tokens 100

推理参数说明

参数默认值说明
--model/opt/atomgit/mxy/granite-4.1-3b模型路径
--prompt"Hello, my name is"输入提示词
--max_tokens100最大生成 token 数
--temperature0.7采样温度
--precision_testFalse运行精度测试

测试验证

精度测试结果

指标阈值实测值状态
max_error_sum< 1e-30.00e+00✅ PASS
max_error_mean< 1e-50.00e+00✅ PASS
max_error_std< 1e-50.00e+00✅ PASS

性能数据

指标值
CPU computation (20 tensors)~6.25s
NPU inference (20 tensors)~0.61s

测试日志

2026-05-19 09:42:00 - INFO - Model loaded!
2026-05-19 09:42:00 - INFO - Supported tasks: ['generate']
2026-05-19 09:42:01 - INFO - Output: [Your Name] and I am a senior...
2026-05-19 09:42:01 - INFO - Inference successful!

模型规格

参数值
架构GraniteForCausalLM
参数量约 3B
隐藏层维度2560
注意力头数40
KV 头数8
层数40
词汇表大小100,352
权重精度BF16
最大上下文长度131,072

注意事项

  1. 模型使用 transformers 加载,使用 torch_npu 进行 NPU 加速
  2. 权重精度为 BF16,NPU 原生支持
  3. 支持自定义提示词和生成参数