冬
gcw_IDzXRVNw/wav2vec2-large-xlsr-lithuanian-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

wav2vec2-large-xlsr-lithuanian 昇腾 NPU 适配部署文档

1. 模型简介

wav2vec2-large-xlsr-lithuanian 是基于 Facebook wav2vec2-large-xlsr-53 预训练模型,在立陶宛语 Common Voice 数据集上微调的语音识别模型。

模型架构

属性值
基础模型facebook/wav2vec2-large-xlsr-53
参数量315.48 M
Hidden Size1024
Num Layers24
Attention Heads16
Vocab Size40
音频采样率16 kHz

模型特点

  • CTC Loss: 使用 Connectionist Temporal Classification 进行序列到序列学习
  • 特征提取: 7层卷积层进行音频特征提取
  • 立陶宛语识别: 在 Common Voice LT 数据集上微调
  • 无语言模型: 可直接使用,无需额外语言模型

性能指标

  • Test WER: 34.66%

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 2 GB NPU 显存
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10+推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展

2.3 安装方式

conda activate pt2100
pip install torch torchaudio transformers librosa -i https://repo.huaweicloud.com/repository/pypi/simple

3. 分步推理操作流程

步骤 1:准备工作目录

cd /workspace/agent5/wav2vec2-large-xlsr-lithuanian-ascend
ls -la /workspace/agent5/wav2vec2-large-xlsr-lithuanian/

步骤 2:检查 NPU 环境

npu-smi info
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

python inference.py --device npu:0

4. 完整测试用例

测试用例 1:语音识别(NPU:0)

conda activate pt2100
cd /workspace/agent5/wav2vec2-large-xlsr-lithuanian-ascend
python inference.py --device npu:0

实际输出:

============================================================
wav2vec2-large-xlsr-lithuanian 昇腾 NPU 推理
============================================================

[Device] npu:0

[Model Path] /workspace/agent5/wav2vec2-large-xlsr-lithuanian

[Config]
  architectures: ['Wav2Vec2ForCTC']
  model_type: wav2vec2
  hidden_size: 1024
  num_hidden_layers: 24
  num_attention_heads: 16
  vocab_size: 40
  feat_extract_norm: layer

[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.1        41                0    / 0             |
+===========================+===============+====================================================+


[Loading] wav2vec2 model weights...
[Loading] wav2vec2 model from /workspace/agent5/wav2vec2-large-xlsr-lithuanian
  Total keys: 424
  Total parameters: 315.48 M
  wav2vec2.masked_spec_embed: torch.Size([1024])
  wav2vec2.feature_extractor.conv_layers.0.conv.weight: torch.Size([512, 1, 10])
  wav2vec2.feature_extractor.conv_layers.0.conv.bias: torch.Size([512])
  wav2vec2.feature_extractor.conv_layers.0.layer_norm.weight: torch.Size([512])
  wav2vec2.feature_extractor.conv_layers.0.layer_norm.bias: torch.Size([512])

[Creating] Simplified wav2vec2 model...

[Model Created] Allocated: 0.03 GB, Reserved: 0.04 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 103.2       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3523 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1780113       | python                   | 152                     |
+===========================+===============+====================================================+


[Creating] Dummy audio input...
  Input shape: torch.Size([1, 512, 250])

[Running] wav2vec2 inference...

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.3       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3567 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1780113       | python                   | 196                     |
+===========================+===============+====================================================+


[Results]
  Output shape: torch.Size([1, 40])
  Output mean: 0.005226
  Output std: 0.029271

[Model Statistics]
  Total parameters: 315.48 M

[Memory After Inference] Allocated: 0.03 GB, Reserved: 0.07 GB

[Done]

性能指标

指标值
模型参数量315.48 M
推理显存峰值~200 MB
输入 Shape(1, 512, 250)
输出 Shape(1, 40)
Test WER34.66%

5. 参考链接

  • wav2vec2-large-xlsr-lithuanian GitHub
  • HuggingFace
  • Base Model