X
Xiaoxy510/granite-speech-4.1-2b-plus-ascend
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Granite-Speech-4.1-2B-Plus on Ascend NPU

1. 简介

本文档记录 Granite-Speech-4.1-2B-Plus 在 Ascend NPU 环境的快速部署与验证结果。

模型基本信息:

  • 参数量:2,111,812,956
  • 模型类型:GraniteSpeechPlusForConditionalGeneration
  • 架构:与 granite-speech-4.1-2b 类似,encoder_hidden_size=2048
  • 加载方式:AutoModelForSpeechSeq2Seq

相关资源:

  • 权重下载地址(HuggingFace):https://huggingface.co/ibm-granite/granite-speech-4.1-2b-plus
  • 权重下载地址(ModelScope):https://modelscope.cn/models/ibm-granite/granite-speech-4.1-2b-plus

2. 验证环境

组件版本
torch2.9.0
torch-npu2.9.0.post1+gitee7ba04
transformers4.57.6
ascend-kernels20250516
Cann8.0
  • NPU:1 逻辑卡
  • 模型路径:${MODEL_DIR}
  • 运行环境:Ascend 910 系列

3. 环境配置

3.1 创建 conda 环境

conda create -n granite-speech-npu python=3.10
conda activate granite-speech-npu

3.2 安装依赖(使用华为源)

pip install torch==2.9.0 --index-url https://repo.myhuaweicloud.com/pypi/simple
pip install torch-npu==2.9.0.post1+gitee7ba04 --index-url https://repo.myhuaweicloud.com/pypi/simple
pip install transformers==4.57.6 --index-url https://repo.myhuaweicloud.com/pypi/simple
pip install ascend-kernels==20250516 --index-url https://repo.myhuaweicloud.com/pypi/simple
pip install accelerate datasets --index-url https://repo.myhuaweicloud.com/pypi/simple

4. 适配方法

4.1 关键适配点

  1. 模型加载:使用 AutoModelForSpeechSeq2Seq 而非 processor,避免 CUDA 依赖
  2. encoder_hidden_size:配置为 2048(区别于 granite-speech-4.1-2b 的 1024)
  3. 设备指定:显式指定 --device npu:0

4.2 核心代码示例

import torch
from transformers import AutoModelForSpeechSeq2Seq

model = AutoModelForSpeechSeq2Seq.from_pretrained(
    model_dir,
    trust_remote_code=True
)
model = model.to("npu:0")
model.eval()

5. 使用方式

5.1 推理脚本

python inference.py \
  --model-dir ${MODEL_DIR} \
  --device npu:0 \
  --warmup \
  --benchmark

参数说明:

  • --model-dir:模型权重路径
  • --device:运行设备(默认 npu:0)
  • --warmup:是否进行预热
  • --benchmark:是否运行性能测试

5.2 精度测试

python eval.py

6. 评测结果

6.1 精度结果

指标数值
模型Granite-Speech-4.1-2B-Plus
参数量2,111,812,956
评测工具本地 NPU 测试
Encoder output[1, 1600, 2048]
Projector output[1, 321, 2048]
LM output[1, 32/321, 100353]
精度状态PASS

6.2 性能结果

指标数值
NPU 单次推理时间(LM)92.59 ms
NPU 吞吐量10.80 steps/s
Encoder ForwardOK
Language Model ForwardOK
Projector ForwardOK
Projector + LM ChainOK

7. 注意事项

  1. processor 依赖:本适配方案不使用 processor,避免 CUDA 依赖
  2. 设备兼容性:仅支持 Ascend NPU 设备
  3. 精度验证:完整精度评测需准备真实音频数据
  4. 内存占用:encoder_hidden_size=2048 导致显存占用增加,确保 NPU 内存充足
  5. 预热建议:生产环境部署前建议执行 warmup 操作