日別アーカイブ: 2023年1月29日

Docker で GPUを使いたい

少し前から OpenAI が提供している whisper を触っています

業務でお客さんとMTGをする機会が最近増えてきて、会話をしていると会話に集中してしまって、メモを取り忘れてしまうんですよね。
端々ではメモをとっても、やっぱり抜けてしまう事はあったり、話を聞いていて

「お、それはこういうことかな?」

って考えている間に話が進んでしまっていたり。。。
ということで、できるだけ録音をするようにしています。

どうせなら文字起こしを手軽に行いたいというのがモチベーションとなります。
将来的には要約まで自動的にやってくれるとよくて、それはもう現実的なレベルまで世の中は来ているわけですが。

Dockerfile

参考にさせてもらったのはこちら

Dockerを使ってOpenAIのWhisperをサクッと試す
https://zenn.dev/kento1109/articles/d7d8f512802935

FROM pytorch/pytorch:1.9.0-cuda10.2-cudnn7-runtime

WORKDIR /workspace

RUN apt-get update && apt-get install -y \
    build-essential \
    gcc \
    git \
    ffmpeg \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

RUN pip install git+https://github.com/openai/whisper.git 

試してみるとエラーになった

root@dfbc095388f8:/workspace# whisper mtg02.m4a --language ja --model large
Traceback (most recent call last):
  File "/opt/conda/bin/whisper", line 5, in <module>
    from whisper.transcribe import cli
  File "/opt/conda/lib/python3.7/site-packages/whisper/__init__.py", line 12, in <module>
    from .decoding import DecodingOptions, DecodingResult, decode, detect_language
  File "/opt/conda/lib/python3.7/site-packages/whisper/decoding.py", line 514
    if prefix := self.options.prefix:
               ^
SyntaxError: invalid syntax

cudaのバージョン問題

参考にさせていただいたページにもあるように、pytorch をPCにあった cuda バージョンにする必要があります。

cudaバージョンの確認方法は、コマンドプロンプトで

>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:59:34_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

という形で表示されます。

ところが、イメージには11.7用のものが見当たらないんですよね

pytorch/pytorch
https://hub.docker.com/r/pytorch/pytorch/tags?page=1&name=11.

最新は11.6のようなので、こちらを使用してみる

FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime

modelのダウンロードエラー?

実行してみると。。。

root@401ac01bcb2c:/workspace# whisper mtg03.m4a --language ja --model large
  0%|▏                                    | 12.3M/2.87G [00:02<11:43, 4.37MiB/s]
Traceback (most recent call last):
  File "/opt/conda/bin/whisper", line 8, in <module>
    sys.exit(cli())
  File "/opt/conda/lib/python3.10/site-packages/whisper/transcribe.py", line 310, in cli
    model = load_model(model_name, device=device, download_root=model_dir)
  File "/opt/conda/lib/python3.10/site-packages/whisper/__init__.py", line 108, in load_model
    checkpoint_file = _download(_MODELS[name], download_root, in_memory)
  File "/opt/conda/lib/python3.10/site-packages/whisper/__init__.py", line 62, in _download
    raise RuntimeError("Model has been downloaded but the SHA256 checksum does not not match. Please retry loading the model.")
RuntimeError: Model has been downloaded but the SHA256 checksum does not not match. Please retry loading the model.

ん、Modelのダウンロードに失敗した?
リトライしろってあるのでもう一度やってみる

root@401ac01bcb2c:/workspace# whisper mtg03.m4a --language ja --model large
/opt/conda/lib/python3.10/site-packages/whisper/__init__.py:48: UserWarning: /root/.cache/whisper/large-v2.pt exists, but the SHA256 checksum does not match; re-downloading the file
  warnings.warn(f"{download_target} exists, but the SHA256 checksum does not match; re-downloading the file")
 23%|████████▌                             | 667M/2.87G [01:34<05:55, 6.71MiB/s]

先に進んだので大丈夫じゃーん!って思っていたら、ここから進まなくなった。。。

今日はここまでにしよう。。。