SenseVoice 训练推理适配昇腾
【摘要】 SenseVoice训练推理适配昇腾
/*****************************如有任何疑问和问题请留言*******************************/
0.前提条件
0.1 登录机器
机器已开通,密码已获取,能通过ssh登录
0.2 检查NPU设备
NPU设备检查:运行npu-smi info命令,返回npu设备信息。
0.3 docker安装
检查docker是否安装:docker -v,如如尚未安装,运行以下命令进行docker安装
yum install -y docker-engine.aarch64 docker-engine-selinux.noarch docker-runc.aarch64
#配置IP转发,用于容器内的网络访问:
sed -i 's/net\.ipv4\.ip_forward=0/net\.ipv4\.ip_forward=1/g' /etc/sysctl.conf
sysctl -p | grep net.ipv4.ip_forward
0.4 获取镜像
docker pull swr.cn-southwest-2.myhuaweicloud.com/atelier/pytorch_2_1_ascend:pytorch_2.1.0-cann_8.0.rc3-py_3.9-hce_2.0.2406-aarch64-snt9b-20240910112800-2a95df3
版本配套表
固件与驱动 |
24.1.rc1及以上 |
CANN |
8.0.RC3 |
Pytorch |
2.1.0 |
funasr |
1.1.3 |
modelscope |
1.16.1 |
0.5 获取代码
下载代码:
https://github.com/FunAudioLLM/CosyVoice.git
0.6 使用镜像
docker run -itd --shm-size="32g" --cap-add=SYS_PTRACE -e ASCEND_VISIBLE_DEVICES=0-1 -p 8192:8192 -u root -v ${dir}:${container_dir} --name ${container_name} ${image_id} /bin/bash
# ASCEND_VISIBLE_DEVICES指定容器要用的卡,0-1代表0 1这2块卡,-用于指定范围
# -p 8192:8192代表需要在宿主机和容器中绑定的端口。示例中,http server使用了8192端口
# -v ${dir}:${container_dir}代表需要在容器中挂载宿主机的目录。宿主机和容器使用不同大的文件系统,dir为宿主机中代码和数据集文件所在目录,目录container_dir为要挂载到的容器中的目录。为方便两个地址可以相同。
# --name ${container_name}容器名称,进入容器时会用到
# -{image_id} ,为docker镜像的id,在宿主机上可通过docker images查询得到
进入容器:通过容器名称进入
docker exec -it -u root ${container_name} bash
1.推理验证
以SenseVoiceSmall为例
1.1 安装训练依赖的三方库
前提可访问公网
进入代码中requirements.txt所在目录,修改requirements.txt,用如下内容替换全部:
torch
modelscope
huggingface
huggingface_hub
funasr>=1.1.3
numpy<=1.26.4
gradio
执行pip install -r requirements.txt
1.2 编译安装 torchaudio
下载torchaudio
git clone https://github.com/pytorch/audio
cd audio
git checkout v2.1.0
执行 python setup.py bdist_wheel, 编译完成后在dist目录下会生成torchaudio-2.1.0* linux_aarch64.whl
执行 pip install torchaudio-2.1.0* linux_aarch64.whl 完成torchaudio 安装
1.3 推理验证
1)下载模型到本地
下载地址: https://www.modelscope.cn/models/iic/SenseVoiceSmall/files
2)修改demo1.py, 在from funasr import AutoModel前面 增加两行
import torch_npu
from torch_npu.contrib import transfer_to_npu
修改model_dir的值为模型本地目录,建议最好是绝对路径
然后执行 python demo1.py
demo2.py 同理
1.4 训练验证
1)使用 find / -name train_ds.py 查看train_ds.py所在目录,一般在
/home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib/python3.9/site-packages/funasr/bin/train_ds.py
2)修改上面查到的train_ds.py,在import torch 后面增加
import torch_npu
from torch_npu.contrib import transfer_to_npu
3)修改finetune.sh 中 train_tool的路径为上面train_ds.py的路径,即:
/home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib/python3.9/site-packages/funasr/bin/train_ds.py
4)修改finetune.sh 中 model_name_or_model_dir的路径为已下载模型的绝对路径
5)代码中提供的 train_example.jsonl 和 val_example.jsonl无法直接使用,音频文件无法获取,需要自己重新制作
6)执行 bash finetune.sh 启动训练
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
yd_2735004422025/02/10 03:03:571楼编辑删除举报
DrvMngGetConsoleLogLevel failed. (g_conLogLevel=3)
[EVENT] PROFILING(539,python):2025-02-10-10:57:47.900.269 [msprof_callback_impl.cpp:336] >>> (tid:539) Started to register profiling ctrl callback.
[EVENT] PROFILING(539,python):2025-02-10-10:57:47.900.605 [msprof_callback_impl.cpp:343] >>> (tid:539) Started to register profiling hash id callback.
[INFO] PROFILING(539,python):2025-02-10-10:57:47.900.695 [prof_atls_plugin.cpp:83] (tid:539) RegisterProfileCallback, callback type is 7
[EVENT] PROFILING(539,python):2025-02-10-10:57:47.900.790 [msprof_callback_impl.cpp:350] >>> (tid:539) Started to register profiling enable host freq callback.
[INFO] PROFILING(539,python):2025-02-10-10:57:47.900.852 [prof_atls_plugin.cpp:83] (tid:539) RegisterProfileCallback, callback type is 8
[ERROR] ATRACE(539,python):2025-02-10-10:57:47.915.789 [trace_driver_api.c:56](tid:539) get platform
yd_2735004422025/02/10 03:04:582楼编辑删除举报
[INFO] HCCL(280,python):2025-02-10-10:54:04.897.948 [adapter_rts.cc:2541][280][adapter_rts.cc][CallBackInitRts] g_deviceType [6] g_deviceLogicId [-1] g_devicePhyId [-1]
[ERROR] RUNTIME(280,python):2025-02-10-10:54:05.039.307 [runtime.cc:1929]280 CheckHaveDevice:Call halGetDeviceInfo failed: drvRet=4, module type=0, info type=1.
[INFO] PROFILING(280,python):2025-02-10-10:54:05.039.594 [prof_atls_plugin.cpp:161] (tid:280) Module[7] register callback of ctrl handle.
[ERROR] RUNTIME(280,python):2025-02-10-10:54:05.039.848 [driver.cc:65]280 GetDeviceCount:report error module_type=1, module_name=EL9999
[ERROR] RUNTIME(280,python):2025-02-10-10:54:05.039.921 [driver.cc:65]280 GetDeviceCount:Call drvGetDevNum, drvRetCode=7.
[ERROR] RUNTIME(280,python):2025-02-10-10:54:05.040.035 [api_c_device.cc:23]280 rtGetDeviceCount:ErrCode=507899, desc=[driver error:internal error], I
昇腾适配2025/02/25 12:03:52编辑删除举报