CentOS に Whisper をインストール | RedHat に Whisper をインストール | サーバーに Whisper をインストール

1. Python バージョンをアップグレードします (オプション)

CentOS 7.9 システムにはデフォルトで 2 つの Python バージョンがインストールされています。python -V と入力すると python2 のバージョン情報が表示され、python3 -V と入力すると python3 のバージョン情報が表示されます。

ウィスパーでは 3.8 から 3.11 までの Python バージョンを使用する必要があるためです。

CentOS 7.9 に付属の Python バージョンは一貫性がないため、アンインストールするかアップグレードする必要があります。Python のバージョンをアップグレードしたくない場合は、Anaconda の Python バージョンを使用することもできます。ここでは Anaconda を推奨します。Anaconda をインストールする場合は、2 番目の手順に直接スキップできます。

CentOSのバージョンを確認してください。現在CentOS7.9を使用しています。

cat /etc/centos-release

Python3のバージョンを確認してください。

python3 -V

1.1. Python のバージョンをアップグレードします。

# 安装依赖
yum -y install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
# 创建目录
mkdir -p /usr/local/python3
# 去 https://www.python.org/ftp/python 找一个自己想要下载的版本
wget -c https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tar.xz
# 解压
xz -d Python-3.9.9.tar.xz
tar -xvf Python-3.9.9.tar.xz
# 切换到 Python-3.9.9 目录
cd Python-3.9.9
# 编译并安装
./configure --prefix=/usr/local/python3 && make && make install

1.2. 設定の変更

  1. 古いソフトリンクを削除します。
# 先查看一下有哪些软链接
ll /usr/bin | grep python
ll /usr/bin | grep pip
# 删除软链接
rm -rf /usr/bin/python3 
rm -rf /usr/bin/pip3
  1. ソフトリンクを作成します。
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

2.アナコンダをインストールする

Anaconda をダウンロードするには、公式ダウンロードにアクセスしてください

  1. ディレクトリを作成します。
mkdir -p /opt/Anaconda
  1. アナコンダをダウンロードします。
wget -c https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
  1. スクリプトを実行します。
bash Anaconda3-2023.03-1-Linux-x86_64.sh

次に、プロンプトに従ってインストールします。

最後に、現在の接続を閉じて再接続することを忘れないでください。

次のコマンドを入力して、インストールが成功したことを示すバージョン情報を確認します。

conda -V

3.FFmpegをインストールする

CentOS7.9 では以下のコマンドでは FFmpeg をインストールできません。ソースコードのコンパイルから FFmpeg をインストールする必要があります。

yum install ffmpeg

FFmpeg のソースコードの一部はアセンブリで記述されているため、アセンブリ言語コンパイラをインストールする必要があります。

  1. yasmをインストールする

    # 下载
    wget -c http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
    # 解压
    tar -zxvf yasm-1.3.0.tar.gz
    # 切换目录
    cd yasm-1.3.0
    # 执行配置
    ./configure
    # 编译并安装
    make && make install
    
  2. FFmpegをインストールする

    # 下载源码
    git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
    # 切花目录
    cd ffmpeg
    # 执行配置
    ./configure
    # 编译并安装
    make && make install
    
  3. FFmpeg のバージョン情報を表示する

    ffmpeg --version
    

4.CUDAのインストール

まず次のコマンドを実行して、グラフィックス カードでサポートされている最高の CUDA バージョンを確認します。

nvidia-smi

4.1. CUDA のインストール

NVIDIA 公式 Web サイトでサポートされている CUDA バージョンをダウンロードします。国内のネットワークでは、NVIDIA の公式 CUDA ダウンロード ページにアクセスできない場合があります。便宜のために、ここでは一般的に使用されるダウンロード リンクをいくつか以下に示します。以下でダウンロードした CUDA のバージョンはすべてバージョン 11.8 です。

4.1.1、CentOS

以下でインストールされる CUDA のバージョンは 11.8 であることに注意してください。

Linux オペレーティング システム、x86_64 アーキテクチャ、CentOS 7、オンライン インストール方法: (非推奨) テスト後、この方法でインストールすると、元の NVIDIA グラフィック カード ドライバーで問題が発生し、最新バージョンの CUDA がデフォルトでインストールされます。

sudo yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms
sudo yum -y install cuda

Linux オペレーティング システム、x86_64 アーキテクチャ、CentOS 7、ローカル インストール方法: (推奨) テスト後、この方法で CUDA を正しくインストールできます。注: グラフィック カード ドライバーがすでにインストールされている場合は、グラフィック カード ドライバーのオプションを忘れずに削除してください。

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

Linux オペレーティング システム、x86_64 アーキテクチャ、CentOS 7、ローカル インストール方法: この方法はテストされていません。

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms
sudo yum -y install cuda

4.1.2、レッドハット

以下でインストールされる CUDA のバージョンは 11.8 であることに注意してください。

Linux オペレーティング システム、x86_64 アーキテクチャ、RHEL 7、オンライン インストール方法: (推奨されません)

sudo yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms
sudo yum -y install cuda

Linux オペレーティング システム、x86_64 アーキテクチャ、RHEL 7、ローカル インストール方法: (推奨)

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

Linux オペレーティング システム、x86_64 アーキテクチャ、RHEL 7、ローカル インストール方法:

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms
sudo yum -y install cuda

4.1.3、Ubuntu

以下でインストールされる CUDA のバージョンは 11.8 であることに注意してください。

Linux オペレーティング システム、x86_64 アーキテクチャ、Ubuntu 22.04、オンライン インストール方法: (推奨されません)

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda

Linux オペレーティング システム、x86_64 アーキテクチャ、Ubuntu 22.04、ローカル インストール方法: (推奨)

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

Linux オペレーティング システム、x86_64 アーキテクチャ、Ubuntu 22.04、ローカル インストール方法:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

4.2、環境変数を設定する

  1. 次のファイルを編集します
vim ~/.bashrc
  1. ファイルの最後に以下を追加します
export PATH=/usr/local/cuda-11.8/bin${
    
    PATH:+:${
    
    PATH}}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64

追加が失敗した場合は、CUDA が正しくインストールされていない可能性があります。デフォルトでは、ディレクトリにインストールされます/usr/local。ディレクトリに移動して、ディレクトリcuda-xx.xがある。そうでない場合は、CUDA がインストールされていないことを意味しますCUDA が正しくインストールされました。

  1. 最後に、忘れずに.bashrcファイルをリロードしてください
source ~/.bashrc
sudo ldconfig
  1. CUDAのバージョンを確認する

    バージョン情報が表示される場合は、CUDA が正しくインストールされ、CUDA 環境変数が正しく構成されていることを意味します。

nvcc -V

5. cuDNN のインストール (オプション)

  1. cuDNN のシステム ソフトウェアおよびハードウェアの要件。
画像-20230525102342154
  1. cuDNN の CPU アーキテクチャとシステム バージョンの要件。
画像-20230525102616237
  1. cuDNNをインストールする

    詳細については、公式のインストール ガイドを参照してください。

    前提条件: NVIDIA グラフィックス ドライバーがインストールされており、CUDA がインストールされている。

    zlibをインストールする

    # Ubunut
    sudo apt-get install zlib1g
    # RHEL
    sudo yum install zlib
    

    ダウンロード

    ダウンロードするバージョンを選択してください

    Download cuDNN v8.9.1 (May 5th, 2023), for CUDA 11.x
    

    対応するシステムのインストーラーをダウンロードすることを選択します

    Local Installer for Linux x86_64 (Tar) # 对所有Linux系统可用
    

    cuDNNをインストールする

    tar -xvf cudnn-linux-x86_64-8.x.x.x_cudaX.Y-archive.tar.xz # 把8.x.x.x_cudaX.Y替换为自己下载的cuDNN版本和CUDA版本
    

    cuDNN を CUDA にコピーする

    sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include 
    sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64 
    sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
    

    詳細については、公式ドキュメントを参照してください。

6.PyTorchをインストールする

ここでインストールしたのは PyTorch 2.0.1 バージョン、CUDA 11.8 です。

  1. PyTorchをダウンロード

    conda activate whisper
    pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    
  2. インストールが成功したことを確認する

    python
    import torch
    torch.__version__
    torch.cuda.is_available() # 如果返回 True,说明PyTorch可以使用CUDA
    

7. ウィスパーをインストールする

pip install -U openai-whisper

次のコマンドを入力すると、Whisper のヘルプ情報が表示され、インストールが成功したことが示されます。

whisper -h

8. ささやきの使用

追加できる特定のパラメータは、次のコマンドを使用して表示できます。

whisper -h

ここでいくつかのアプリケーションを紹介します。

文字起こしにはモデルを使用し、文字起こし結果はパスに保存されます。名前はaudio.mp3file 、使用される文字起こしは高速化され、指定された言語は ですすべてのパラメータを省略して、デフォルトでモデルを使用できます。large/opt/whisperaudio.srtCUDAChinesesmall

whisper audio.mp3 --model large --output_format srt --output_dir /opt/whisper --device cuda --language Chinese

最もシンプルな書き方。

whisper audio.mp3

注: モデルが大きくなるほど、転写結果はより正確になり、転写時間は長くなります。

さらに詳しい内容については、私のブログをご覧ください

おすすめ

転載: blog.csdn.net/qq_43907505/article/details/130863950