背景
FishSpeech是一個(gè)開(kāi)源的智能語(yǔ)音大模型,目前已經(jīng)到1.5版本,能夠提供比較好的TTS文字轉(zhuǎn)語(yǔ)音,語(yǔ)音復(fù)刻等功能。但是需要注意的是,F(xiàn)ishSpeech模型協(xié)議是CC-BY-NC-SA-4.0,無(wú)法直接商用。
CC - BY - NC - SA 4.0 是一種知識(shí)共享許可協(xié)議,全稱(chēng)為 “署名 - 非商業(yè)性使用 - 相同方式共享 4.0 國(guó)際”(Creative Commons Attribution - NonCommercial - ShareAlike 4.0 International)
部署步驟
1. 準(zhǔn)備機(jī)器
機(jī)器配置GPU推薦采用A10 GPU 及以上(24GB,Ampere 架構(gòu),具備 6144 個(gè) CUDA 核心,單精度浮點(diǎn)TFLOPS 35.6)
2. 安裝顯卡驅(qū)動(dòng)
可以參考阿里云(手動(dòng)安裝):help.aliyun.com/zh/egs/user-guide/install-a-gpu-driver-on-a-gpu-accelerated-compute-optimized-linux-instance
注意Nvidia GPU 驅(qū)動(dòng)版本可以使用最新的570(2025年4月22日),對(duì)應(yīng)cuda版本12.8,可以正常使用
驅(qū)動(dòng)可以通過(guò)cuda包解壓得到,只安裝驅(qū)動(dòng)即可,也可以使用操作系統(tǒng)包管理工具安裝。
wget https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_570.124.06_linux.run
chmod +x cuda_12.8.1_570.124.06_linux.run
./cuda_12.8.1_570.124.06_linux.run --extract=/root/cuda128
cd cuda128
./NVIDIA-Linux-x86_64-570.124.06.run
驗(yàn)證驅(qū)動(dòng)安裝成功:
(py3) root@iZ8vb7rgz0erhq04yqfvmoZ:~/cuda128# nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.124.06 Driver Version: 570.124.06 CUDA Version: 12.8 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 Tesla T4 Off | 00000000:00:07.0 Off | 0 |
| N/A 43C P0 27W / 70W | 1847MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 89296 C python 1844MiB |
+-----------------------------------------------------------------------------------------+
3. 下載模型文件
huggingface-cli download fishaudio/fish-speech-1.5 --local-dir checkpoints/fish-speech-1.5
4. 下載代碼文件
如果可以連接github,可以使用gitclone直接獲得,如果沒(méi)有,可以本地clone之后再上傳到服務(wù)器上。
5. 進(jìn)行安裝
首先解壓相關(guān)代碼,然后執(zhí)行下面命令進(jìn)行安裝,實(shí)際執(zhí)行建議安裝conda,用來(lái)創(chuàng)建指定版本的python虛擬環(huán)境。
apt install python3-venv
python3 -m venv py3
source py3/bin/activate
#切換到虛擬環(huán)境
cd fish-speech
pip3 install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu121
apt install libsox-dev ffmpeg
apt install build-essential cmake libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
#最終安裝
pip3 install -e .[stable]
export GRADIO_SERVER_NAME="0.0.0.0"
python tools/run_webui.py --compile --half
重啟命令
source py3/bin/activate
cd fish-speech-main/
python tools/run_webui.py --compile
nohup python -u tools/run_webui.py --compile >>run.log 2>&1 &
6. 開(kāi)通網(wǎng)絡(luò)訪(fǎng)問(wèn)
如果是公有云,給對(duì)應(yīng)端口添加安全組訪(fǎng)問(wèn)策略。 如例子中使用8080和7860端口。
7. 啟動(dòng)腳本
為了方便管理,增加了2個(gè)啟動(dòng)腳本,分別用來(lái)啟動(dòng)webui和api_server。
用來(lái)啟動(dòng)UI端。
#start_webui.sh
#!/bin/bash
# Activate the Python virtual environment
source py3/bin/activate
# Enter the project directory
cd fish-speech-1.5
# Set the environment variable
export GRADIO_SERVER_NAME="0.0.0.0"
# Start the project silently in the background
nohup python -u tools/run_webui.py --compile >> run_webui.log 2>&1 &
# Output the prompt message
echo "webui starting ..."
用來(lái)啟動(dòng)API服務(wù)。
#start_api.sh
#!/bin/bash
# Activate the Python virtual environment
source py3/bin/activate
# Enter the project directory
cd fish-speech-1.5
# Start the project silently in the background
nohup python -u tools/api_server.py --compile --listen 0.0.0.0:8028 >> run_api.log 2>&1 &
# Output the prompt message
echo "api server starting ..."
8. 關(guān)閉程序
關(guān)閉程序簡(jiǎn)單使用查詢(xún)服務(wù)端口,然后kill的方式。
netstat -anp | grep 7860
kill -9 <pid>
netstat -anp | grep 8028
kill -9 <pid>
問(wèn)題和解決
阿里云部分機(jī)器安裝顯卡驅(qū)動(dòng)不成功。報(bào)錯(cuò)如內(nèi)核不匹配,GPL不匹配等。 確認(rèn)是否是共享GPU,共享GPU只能安裝GRID驅(qū)動(dòng),版本最高為470,對(duì)應(yīng)cuda版本11.4。
webui無(wú)法在公網(wǎng)訪(fǎng)問(wèn)
設(shè)置export GRADIO_SERVER_NAME="0.0.0.0"API_SERVER無(wú)法在公網(wǎng)訪(fǎng)問(wèn),以及自定義端口。
這種情況看日志可以發(fā)現(xiàn)啟動(dòng)使用的127.0.0.1。 可以添加 --listen 0.0.0.0:8080 ,設(shè)置監(jiān)聽(tīng)地址和端口。生成速度較慢
如果本身顯卡資源足夠,可以通過(guò)添加 --half --compile 參數(shù)進(jìn)行加速。但不建議使用half,可能影響效果。
另外實(shí)踐中,4090顯卡加入-- compile之后,能達(dá)到260 token/s的執(zhí)行速度。A10公有云獨(dú)享GPU能達(dá)到160 token/s,供參考。