-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add WeNet and Whisper.cpp and some small fixes (#50)
- Loading branch information
1 parent
71e1c10
commit 5cb3a99
Showing
10 changed files
with
459 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
WeNet | ||
=========== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
install.rst | ||
quick_start.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
安装指南 | ||
============== | ||
|
||
本教程面向使用 WeNet & 昇腾的开发者,帮助完成昇腾环境下 WeNet 的安装。 | ||
|
||
昇腾环境安装 | ||
------------ | ||
|
||
请根据已有昇腾产品型号及CPU架构等按照 :doc:`快速安装昇腾环境指引 <../ascend/quick_install>` 进行昇腾环境安装。 | ||
|
||
.. warning:: | ||
CANN 最低版本为 8.0.rc1,安装 CANN 时,请同时安装 Kernel 算子包。 | ||
|
||
Python 环境创建 | ||
---------------------- | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
# 创建名为 wenet 的 python 3.10 的虚拟环境 | ||
conda create -y -n wenet python=3.10 | ||
# 激活虚拟环境 | ||
conda activate wenet | ||
WeNet 安装 | ||
---------------------- | ||
|
||
使用以下指令安装带有 torch-npu 的 WeNet 及训练相关依赖: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
# 安装带有 torch-npu 的 WeNet | ||
pip install -e .[torch-npu] | ||
# 安装 WeNet 训练相关依赖 | ||
pip install -r requirements.txt | ||
请遵循以下 torch-npu 相关库的版本控制: | ||
|
||
+------------+------------------+-----------+ | ||
| Requirement| Minimum | Recommend | | ||
+============+==================+===========+ | ||
| CANN | 8.0.RC2.alpha003 | latest | | ||
+------------+------------------+-----------+ | ||
| torch | 2.1.0 | 2.2.0 | | ||
+------------+------------------+-----------+ | ||
| torch-npu | 2.1.0 | 2.2.0 | | ||
+------------+------------------+-----------+ | ||
| torchaudio | 2.1.0 | 2.2.0 | | ||
+------------+------------------+-----------+ | ||
| deepspeed | 0.13.2 | latest | | ||
+------------+------------------+-----------+ | ||
|
||
|
||
|
||
安装校验 | ||
---------------------- | ||
|
||
使用以下 Python 脚本对 open_clip 的安装进行校验,正确打印 open_clip 的版本号和 NPU 卡号说明安装成功。 | ||
|
||
.. code-block:: python | ||
:linenos: | ||
:emphasize-lines: 5,6 | ||
import torch | ||
import torch_npu | ||
import timm | ||
print("timm version:", timm.version.__version__) | ||
print("NPU devices:", torch.npu.current_device()) | ||
正确回显如下(单卡 NPU 环境): | ||
|
||
.. code-block:: shell | ||
timm version: 1.0.8.dev0 | ||
NPU devices: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
快速开始 | ||
================== | ||
|
||
.. note:: | ||
|
||
阅读本篇前,请确保已按照 :doc:`安装教程 <./install>` 准备好昇腾环境及 WeNet ! | ||
|
||
本文档帮助昇腾开发者快速使用 WeNet × 昇腾 进行自动语音识别(Automatic Speech Recognition, ASR)模型的训练、推理和评估等。 | ||
|
||
WeNet 提供了多种数据集及模型的实验脚本,该脚本将实验分为几个阶段,包含数据集的下载、模型的训练、推理、评估等,均存放在 `examples <https://github.com/wenet-e2e/wenet/blob/main/examples/>`_ 路径下, | ||
本篇以 aishell-1 数据集的实验为例,基于 WeNet `官方教程 <https://wenet.org.cn/wenet/tutorial_aishell.html#>`_ , | ||
详述如何使用 `NPU 实验脚本 <https://github.com/wenet-e2e/wenet/blob/main/examples/aishell/s0/run_npu.sh>`_ 进行从零开始的语音模型训练。 | ||
|
||
首先进入该脚本所在目录下: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
cd example/aishell/s0 | ||
下载数据 | ||
~~~~~~~~~~~~ | ||
|
||
stage -1 阶段将 aishell-1 数据下载到本地路径 ``$data``: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage -1 --stop_stage -1 | ||
如果已下载数据,请更改 ``run_npu.sh`` 脚本中的变量 ``$data`` 值为实际数据集存放的绝对路径,并从下一阶段开始。 | ||
|
||
准备训练数据 | ||
~~~~~~~~~~~~ | ||
|
||
stage 0 阶段为训练数据准备阶段,将使用 ``local/aishell_data_prep.sh`` 脚本将训练数据重新组织为 ``wav.scp`` 和 ``text`` 两部分。 | ||
|
||
.. note:: | ||
|
||
``wav.scp`` 每行记录两个制表符分隔的列: ``wav_id`` 和 ``wav_path``, | ||
``text`` 每行记录两个制表符分隔的列: ``wav_id`` 和 ``text_label``。 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 0 --stop_stage 0 | ||
提取最佳 cmvn 特征(可选) | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
stage 1 阶段从训练数据中提取 cmvn 特征,本阶段为可选阶段,设置 ``cmvn=false`` 可跳过本阶段。 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 1 --stop_stage 1 | ||
``tools/compute_cmvn_stats.py`` 用于提取全局 cmvn(倒谱均值和方差归一化)统计数据,用来归一化声学特征。 | ||
|
||
生成 token 字典 | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
stage 2 阶段生成训练所需 token 字典,用于 CTC 解码阶段查询,将输出转换为文字。 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 2 --stop_stage 2 | ||
准备 WeNet 数据格式 | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
stage 3 阶段生成 WeNet 所需格式的文件 ``data.list``: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 3 --stop_stage 3 | ||
生成的 ``data.list``每一行都是 json 格式,包含 关键词 ``key`` (文件名称), | ||
语音文件地址 ``wav`` 和 对应文本内容 ``txt`` 三个关键数据。如下为一示例: | ||
|
||
.. code-block:: shell | ||
{"key": "BAC009S0002W0122", "wav": "/export/data/asr-data/OpenSLR/33//data_aishell/wav/train/S0002/BAC009S0002W0122.wav", "txt": "而对楼市成交抑制作用最大的限购"} | ||
模型训练 | ||
~~~~~~~~~~ | ||
|
||
stage 4 为模型训练阶段, ``run_npu.sh`` 脚本中实现了 NPU 卡号的自动获取和相关环境变量设置,因此可直接通过以下启动昇腾 NPU 上的模型训练: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 4 --stop_stage 4 | ||
如需自行指定 NPU 卡号,请更改 ``run_npu.sh`` 脚本中的变量 ``ASCEND_RT_VISIBLE_DEVICES`` 值为指定卡号。 | ||
|
||
.. note:: | ||
|
||
有关断点重训,参数配置等,请参考 `WeNet 官方文档 <https://wenet.org.cn/wenet/tutorial_aishell.html#stage-4-neural-network-training>`_ 。 | ||
|
||
测试推理 | ||
~~~~~~~~~~~~~~~ | ||
|
||
stage 5 为模型测试推理阶段,将测试集中语音文件识别为文本: | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 5 --stop_stage 5 | ||
此外,stage 5 还提供平均模型的功能,平均模型指当 ``${average_checkpoint}``为 ``true`` 时, | ||
将交叉验证集上的最佳的 ``${average_num}`` 个模型平均,生成增强模型。 | ||
|
||
.. note:: | ||
|
||
此阶段还提供解码和 WER 模型评估等功能,详细信息请参考 WeNet `官方文档 <https://wenet.org.cn/wenet/tutorial_aishell.html#stage-5-recognize-wav-using-the-trained-model>`_ 。 | ||
|
||
|
||
导出训练好的模型 | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
stage 6 为模型导出阶段, ``wenet/bin/export_jit.py`` 使用 ``Libtorch`` 导出以上训练好的模型,导出的模型可用于其他编程语言(如 C++)的推理。 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
bash run_npu.sh --stage 6 --stop_stage 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Whisper.cpp | ||
=========== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
install.rst | ||
quick_start.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
安装指南 | ||
============== | ||
|
||
本教程面向使用 Whisper.cpp & 昇腾的开发者,帮助完成昇腾环境下 Whisper.cpp 的安装。 | ||
|
||
昇腾环境安装 | ||
------------ | ||
|
||
请根据已有昇腾产品型号及CPU架构等按照 :doc:`快速安装昇腾环境指引 <../ascend/quick_install>` 进行昇腾环境安装。 | ||
|
||
.. warning:: | ||
CANN 最低版本为 8.0.rc1,安装 CANN 时,请同时安装 Kernel 算子包。 | ||
|
||
Whisper.cpp 编译安装 | ||
---------------------- | ||
|
||
1. 下载 Whisper.cpp 项目到本地 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
git clone https://github.com/ggerganov/whisper.cpp.git | ||
2. 在 Whisper.cpp 项目目录下,创建构建目录并进入该目录 | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
mkdir build | ||
cd build | ||
3. 编译安装 CANN 版本的 Whisper.cpp | ||
|
||
.. code-block:: shell | ||
:linenos: | ||
cmake .. -D GGML_CANN=on | ||
make -j | ||
安装校验 | ||
---------------------- | ||
|
||
编译完毕后,无任何报错信息,并输出以下关键回显即说明安装成功: | ||
|
||
.. code-block:: shell | ||
[ 90%] Built target quantize | ||
[ 95%] Linking CXX executable ../../bin/main | ||
[ 95%] Built target main | ||
[100%] Linking CXX executable ../../bin/server | ||
[100%] Built target server |
Oops, something went wrong.