之前我本地机器运行faster-whisper 会报错类似
Could not load library libcudnn_ops_infer.so.8
github 上也有类似的情况 :https://github.com/SYSTRAN/faster-whisper/issues/516#issuecomment-2785038635
缺少.so.8 文件,我通过以下方式,完美解决
- 安装并配置好cuda环境
先启动个容器(这是我自用的基于nvidia/cuda:12.4.1-cudnn-runtime-ubuntu20.04 镜像作的,支持cuda,以及无限白嫖Pycharm专业版的镜像【ubuntu系统下运行的,其他系统运行请自行查阅对应 xhost配置】)
Dockerfile
FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai
ENV PYCHARM_VERSIONS=2024.3.2
ENV PYCHARM_URL=https://bj.bcebos.com/petite-mark/public_read/pycharm-$PYCHARM_VERSIONS.tar.gz
ENV PYENV_URL=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/5b7534d6_a010_4981_87c4_f25e224dc102/pyenv-2.5.0.zip?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-05T08%3A46%3A00Z%2F-1%2F%2F32d8b45a0e61d73f8ab376fc44e82d92f8eec0f0a18555bc30c2dc6430444734
ENV PYTHON_VERSIONS=3.9.9
ENV PYTHON_URL=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/de8298f4_040b_4204_8676_39a0d31b2c3f/Python-$PYTHON_VERSIONS.tar.xz?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-06T04%3A55%3A57Z%2F-1%2F%2Fac59bd3f09d339e327e77b6f1d3d6b987e816d116295e1d6c95c774b92ae845a
ENV START_BASH=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/14cf3e28_8788_46fa_9f87_d48c5350a702/start.sh?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-06T13%3A35%3A09Z%2F-1%2F%2F84692a8bc2c29b294f924c56db140e884a9c11037a180620829e6e3565ec60ed
ENV PYTHON_VERSIONS2=3.11.0
ENV PYTHON_URL2=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/47cd7fac_b599_41e9_b861_4404902a8621/Python-$PYTHON_VERSIONS2.tar.xz?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-12T15%3A53%3A15Z%2F-1%2F%2F4330e239c2f920e4bc444029279a7eccd76bfa9f39ace0967d398579b0478cd0
ENV PYCHARM_CONFIG=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/96e6d2d7_2fcd_4d64_b8d2_9589a469466e/PyCharm2024.3.zip?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-12T16%3A40%3A12Z%2F-1%2F%2Ffe7dc3c019aad58f5164890fb4921886424859f4c0992f2419f66f78979c724e
ENV PYCHARM_PLUGINS=~/.local/share/JetBrains/PyCharm2024.3
ENV PYCHARM_PLUGINS_URL=https://collection-data.bj.bcebos.com/jiaohaicheng/selfspace/a9bf6304_b442_4e0c_9974_a80780b644a8/PyCharm2024.3.zip?authorization=bce-auth-v1%2F359794b9ccff4c03a01bdaaf0ede3be2%2F2025-02-15T10%3A26%3A32Z%2F-1%2F%2Fad1c024f2b68e2f23b4a7a0decb2d960d484b581a2337f9d5580bae9d8cee1d7
# 安装必要的依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \
openjdk-11-jdk \
libx11-6 \
libxcomposite1 \
libxrandr2 \
libxss1 \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
xauth \
libbz2-dev \
libncurses5-dev \
libffi-dev \
libreadline-dev \
libssl-dev \
zlib1g-dev \
build-essential \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
libc6-dev \
liblzma-dev \
libncursesw5-dev \
git \
python3-pip \
python-is-python3 \
wget \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 下载并安装PyCharm
RUN wget $PYCHARM_URL -O /tmp/pycharm.tar.gz \
&& tar -xvzf /tmp/pycharm.tar.gz -C /opt/ \
&& rm /tmp/pycharm.tar.gz
# 设置PyCharm环境变量
ENV PYCHARM_HOME=/opt/pycharm-$PYCHARM_VERSIONS
ENV PATH=$PYCHARM_HOME/bin:$PATH
# 配置 Pycharm 缓存
RUN wget $PYCHARM_CONFIG -O ./PyCharm2024.3.zip && \
mkdir -p ~/.config/JetBrains && \
mv PyCharm2024.3.zip ~/.config/JetBrains/ && \
unzip ~/.config/JetBrains/PyCharm2024.3.zip -d ~/.config/JetBrains/ && \
rm ~/.config/JetBrains/PyCharm2024.3.zip
# 配置 Pycharm 插件
RUN wget $PYCHARM_PLUGINS_URL -O PyCharm2024.3.zip && mkdir -p ~/.local/share/JetBrains && tar -xvf PyCharm2024.3.zip -C ~/.local/share/JetBrains && rm PyCharm2024.3.zip
# 安装pyenv
RUN wget $PYENV_URL -O pyenv.zip && unzip pyenv.zip && mv pyenv-2.5.0/ ~/.pyenv && rm pyenv.zip
RUN mkdir -p ~/.pyenv/cache && wget $PYTHON_URL -O ~/.pyenv/cache/Python-$PYTHON_VERSIONS.tar.xz && wget $PYTHON_URL2 -O ~/.pyenv/cache/Python-$PYTHON_VERSIONS2.tar.xz
RUN ln -s ~/.pyenv/bin/pyenv /usr/bin/pyenv && pyenv install $PYTHON_VERSIONS && pyenv global $PYTHON_VERSIONS && pyenv install $PYTHON_VERSIONS2 && rm -rf ~/.pyenv/cache/Python-*.tar.xz
# 安装中文字体
RUN apt-get update && apt-get install -y --no-install-recommends \
fonts-arphic-uming \
fonts-noto-cjk \
locales \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN locale-gen zh_CN.UTF-8 && update-locale LANG=zh_CN.UTF-8
# 设置语言环境
ENV LANG=zh_CN.UTF-8
ENV LC_ALL=zh_CN.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends \
ibus \
ibus-pinyin \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN ibus-daemon -d -x
ENV GTK_IM_MODULE=ibus
ENV QT_IM_MODULE=ibus
ENV XMODIFIERS=@im=ibus
RUN wget $START_BASH -O ~/start.sh && chmod +x ~/start.sh
# 启动PyCharm
CMD ["sh", "-c", "~/start.sh"]
打包镜像
shell
docker build -t pycharm-container .
映射桌面环境
shell
xhost +local:docker
启动容器
shell
docker run -itd --gpus all --name pycharm --env DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v /home/jhc/Projects:/projects pycharm-container
进入容器中执行下列命令 配置cuda环境
wget https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda_12.6.3_560.35.05_linux.run
sudo sh cuda_12.6.3_560.35.05_linux.run
requirements.txt
txt
torch==2.2.2
torchvision==0.17.2
torchaudio==2.2.2
faster-whisper
gradio
pybind11>=2.12
numpy<2
main.py (验证cuda是否可用)
python
import torch
# 回车运行
print(torch.cuda.is_available())
main.py (运行faster-whisper)
python
from faster_whisper import WhisperModel
model_size = "./modelscape/faster-whisper-medium"
# Run on GPU with FP16
model = WhisperModel(model_size, device="cuda")
segments, info = model.transcribe("1.wav", beam_size=5)
print("Detected language '%s' with probability %f" % (info.language, info.language_probability))
for segment in segments:
print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
下载模型文件
来源:https://modelscope.cn/models/gpustack/faster-whisper-medium/files
所以新建文件夹 modelscope
并在路径下执行:git clone https://www.modelscope.cn/gpustack/faster-whisper-medium.git 拉模型文件(较大,需要科学上网,初次拉取之前记得配置lfs: sudo apt update && sudo apt install git-lfs && git lfs install)