Oracle Cloudでは、Always Freeの条件でAmpere A1のコンピュート・インスタンスを4CPU、24GBメモリのサイズで作成することができます。
このサイズのインスタンスを作成し、OpenAIのWhisperを動かしてみました。最初にOracle Linux 9に実装してみます。次の記事でマーケットプレースにあるUbuntuのイメージを使った実装を行います。Ubuntuでの実装の方が若干、処理が高速です。
以下、作業手順を記載します。仮想クラウド・ネットワークは作成済みとします。
OCIコンソールよりコンピュートのインスタンスを開き、インスタンスの作成を実行します。
任意の
名前をコンピュート・インスタンスに付けます。今回は
MyWhisperとしています。
イメージとシェイプを変更します。
イメージは
Oracle Linux 9の最新版を選択します。
Shapeとして、
インスタンス・タイプは
仮想マシン、
シェイプ・シリーズは
Ampere、
Shape Nameは
VM.Standard.A1.Flexを選択します。
OCPUの数に4、メモリー量(GB)に24を指定し、シェイプの選択をクリックします。
SSHキーの追加として、
キー・ペアを自動で生成を選択します。
秘密キーの保存をクリックし、作成するコンピュート・インスタンスに接続する際に使用する秘密キーのファイルをダウンロードします。
通常、ssh-key-年-月-日.keyという名前のファイルがダウンロードされます。
作成をクリックし、コンピュート・インスタンスを作成します。
仮想クラウド・ネットワークの設定をしていないとエラーが発生しますが、その時点でデフォルト値が設定されます。作成済みの仮想クラウド・ネットワークがひとつであれば、もう一度作成をクリックすると、作成処理が開始します。

コンピュート・インスタンスは、すぐに作成されます。
パブリックIPアドレスを確認します。コンピュート・インスタンスにSSH接続する際に使用します。
コンピュート・インスタンスに接続し、Whisperのインストール作業を始めます。
秘密キー・ファイルはmywhisper.keyに名称を変更し、パーミッションは所有者のみリード可能(chmod 400 mywhisper.key)に設定しています。
ssh -i 秘密キーのファイル opc@パブリックIPアドレス
% ssh -i mywhisper.key opc@***.***.***.***
The authenticity of host '***.***.***.*** (***.***.***.***)' can't be established.
ED25519 key fingerprint is SHA256:8UgC88KhLMLzaK01mgWgWmIy/Vcgl/k6mwwyychwuFQ.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '***.***.***.***' (ED25519) to the list of known hosts.
[opc@mywhisper ~]$
最初にOSを最新までアップデートします。
sudo dnf -y update
[opc@mywhisper ~]$ sudo dnf -y update
Ksplice for Oracle Linux 9 (aarch64) 35 kB/s | 17 kB 00:00
Oracle Linux 9 OCI Included Packages (aarch64) 27 MB/s | 15 MB 00:00
Oracle Linux 9 BaseOS Latest (aarch64) 20 MB/s | 9.1 MB 00:00
Oracle Linux 9 Application Stream Packages (aar 18 MB/s | 10 MB 00:00
Oracle Linux 9 UEK Release 7 (aarch64) 29 kB/s | 11 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
kernel-uek aarch64 5.15.0-6.80.3.1.el9uek ol9_baseos_latest 1.0 M
kernel-uek-core aarch64 5.15.0-6.80.3.1.el9uek ol9_baseos_latest 39 M
kernel-uek-devel aarch64 5.15.0-6.80.3.1.el9uek ol9_baseos_latest 38 M
kernel-uek-modules aarch64 5.15.0-6.80.3.1.el9uek ol9_baseos_latest 57 M
Upgrading:
NetworkManager aarch64 1:1.40.0-1.0.2.el9 ol9_baseos_latest 2.0 M
NetworkManager-config-server
noarch 1:1.40.0-1.0.2.el9 ol9_baseos_latest 17 k
[中略]
libnvme-1.0-5.el9.aarch64
policycoreutils-python-utils-3.4-4.el9.noarch
python3-gobject-base-noarch-3.40.1-6.el9.noarch
scl-utils-1:2.0.3-2.el9.aarch64
tcl-1:8.6.10-7.el9.aarch64
Complete!
[opc@mywhisper ~]$
pipと
gitをインストールします。
sudo dnf -y install python-pip git[opc@mywhisper ~]$ sudo dnf -y install python-pip git
Last metadata expiration check: 1:39:42 ago on Mon 23 Jan 2023 02:31:14 AM GMT.
Dependencies resolved.
=============================================================================================
Package Architecture Version Repository Size
=============================================================================================
Installing:
git aarch64 2.31.1-2.el9.2 ol9_appstream 149 k
python3-pip noarch 21.2.3-6.el9 ol9_appstream 2.9 M
Installing dependencies:
[中略]
Installed:
git-2.31.1-2.el9.2.aarch64 git-core-2.31.1-2.el9.2.aarch64
git-core-doc-2.31.1-2.el9.2.noarch perl-DynaLoader-1.47-479.el9.aarch64
perl-Error-1:0.17029-7.el9.noarch perl-File-Find-1.37-479.el9.noarch
perl-Git-2.31.1-2.el9.2.noarch perl-TermReadKey-2.38-11.el9.aarch64
python3-pip-21.2.3-6.el9.noarch
Complete!
[opc@mywhisper ~]$
PyTorchをインストールします。以下のページより、Run this Commandを求めます。
https://pytorch.org/get-started/locally/

Run this Commandをコピーし、シェルより実行します。
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
[opc@mywhisper ~]$ pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cpu
Collecting torch
Downloading https://download.pytorch.org/whl/torch-1.13.1-cp39-cp39-manylinux2014_aarch64.whl (60.5 MB)
|████████████████████████████████| 60.5 MB 1.7 MB/s
Collecting torchvision
Downloading https://download.pytorch.org/whl/torchvision-0.14.1-cp39-cp39-manylinux2014_aarch64.whl (760 kB)
|████████████████████████████████| 760 kB 51.2 MB/s
Collecting torchaudio
Downloading https://download.pytorch.org/whl/torchaudio-0.13.1-cp39-cp39-manylinux2014_aarch64.whl (3.5 MB)
|████████████████████████████████| 3.5 MB 14.1 MB/s
Collecting typing-extensions
Downloading typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Collecting numpy
Downloading numpy-1.24.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.0 MB)
|████████████████████████████████| 14.0 MB 6.1 MB/s
Requirement already satisfied: requests in /usr/lib/python3.9/site-packages (from torchvision) (2.25.1)
Collecting pillow!=8.3.*,>=5.3.0
Downloading Pillow-9.4.0-cp39-cp39-manylinux_2_28_aarch64.whl (3.1 MB)
|████████████████████████████████| 3.1 MB 64.9 MB/s
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.9/site-packages (from requests->torchvision) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.9/site-packages (from requests->torchvision) (1.26.5)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3.9/site-packages (from requests->torchvision) (4.0.0)
Installing collected packages: typing-extensions, torch, pillow, numpy, torchvision, torchaudio
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /home/opc/.local/lib/python3.9/site-packages
sysconfig: /home/opc/.local/lib64/python3.9/site-packages
WARNING: Additional context:
user = True
home = None
root = None
prefix = None
Successfully installed numpy-1.24.1 pillow-9.4.0 torch-1.13.1 torchaudio-0.13.1 torchvision-0.14.1 typing-extensions-4.4.0
[opc@mywhisper ~]$
WARNINGについては、とりあえず気にしないことにしました。
ffmpegをインストールします。これについては、ソース・コードからコンパイルすることにしました。configureしてmakeするのは久しぶりでうろ覚えですが、configureのスクリプトはCPUがサポートしている命令を細かく確認していたように思います。
curl -OL https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
[opc@mywhisper ~]$ curl -OL https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11.7M 100 11.7M 0 0 6734k 0 0:00:01 0:00:01 --:--:-- 6737k
[opc@mywhisper ~]$
ダウンロードしたアーカイブを展開します。
tar xBf ffmpeg-snapshot.tar.bz2 [opc@mywhisper ~]$ tar xBf ffmpeg-snapshot.tar.bz2
[opc@mywhisper ~]$
ffmpegのバイナリを作成します。12、3分の時間がかかりました。
cd ffmpeg ./configure; make
[opc@mywhisper ffmpeg]$ ./configure; make
install prefix /usr/local
source path .
C compiler gcc
C library glibc
ARCH aarch64 (generic)
[中略]
CC fftools/ffmpeg.o
LD ffmpeg_g
STRIP ffmpeg
CC fftools/ffprobe.o
LD ffprobe_g
STRIP ffprobe
[opc@mywhisper ffmpeg]$
ffmpegをインストールします。
sudo make install
[opc@mywhisper ffmpeg]$ sudo make install
INSTALL doc/ffmpeg.1
INSTALL doc/ffprobe.1
INSTALL doc/ffmpeg-all.1
INSTALL doc/ffprobe-all.1
[中略]
INSTALL libavutil/film_grain_params.h
INSTALL libavutil/avconfig.h
INSTALL libavutil/ffversion.h
INSTALL libavutil/libavutil.pc
[opc@mywhisper ffmpeg]$
インストールされたffmpegを確認します。
which ffmpeg
[opc@mywhisper ffmpeg]$ which ffmpeg
/usr/local/bin/ffmpeg
[opc@mywhisper ffmpeg]$
OpenAI Whisperをインストールします。
pip install git+https://github.com/openai/whisper.git
[opc@mywhisper ffmpeg]$ cd
[opc@mywhisper ~]$ pip install git+https://github.com/openai/whisper.git
Defaulting to user installation because normal site-packages is not writeable
Collecting git+https://github.com/openai/whisper.git
Cloning https://github.com/openai/whisper.git to /tmp/pip-req-build-jy5v_fwq
Running command git clone -q https://github.com/openai/whisper.git /tmp/pip-req-build-jy5v_fwq
Resolved https://github.com/openai/whisper.git to commit f5bfe004eccc3837a0d198baf7602ec7bccffafd
Requirement already satisfied: numpy in ./.local/lib/python3.9/site-packages (from openai-whisper==20230117) (1.24.1)
Requirement already satisfied: torch in ./.local/lib/python3.9/site-packages (from openai-whisper==20230117) (1.13.1)
Collecting tqdm
Downloading tqdm-4.64.1-py2.py3-none-any.whl (78 kB)
|████████████████████████████████| 78 kB 3.1 MB/s
Collecting more-itertools
Downloading more_itertools-9.0.0-py3-none-any.whl (52 kB)
|████████████████████████████████| 52 kB 3.4 MB/s
Collecting transformers>=4.19.0
Downloading transformers-4.25.1-py3-none-any.whl (5.8 MB)
|████████████████████████████████| 5.8 MB 35.7 MB/s
Collecting ffmpeg-python==0.2.0
Downloading ffmpeg_python-0.2.0-py3-none-any.whl (25 kB)
Collecting future
Downloading future-0.18.3.tar.gz (840 kB)
|████████████████████████████████| 840 kB 55.7 MB/s
Collecting huggingface-hub<1.0,>=0.10.0
Downloading huggingface_hub-0.11.1-py3-none-any.whl (182 kB)
|████████████████████████████████| 182 kB 75.3 MB/s
Collecting filelock
Downloading filelock-3.9.0-py3-none-any.whl (9.7 kB)
Collecting tokenizers!=0.11.3,<0.14,>=0.11.1
Downloading tokenizers-0.13.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.3 MB)
|████████████████████████████████| 7.3 MB 90.0 MB/s
Requirement already satisfied: requests in /usr/lib/python3.9/site-packages (from transformers>=4.19.0->openai-whisper==20230117) (2.25.1)
Requirement already satisfied: pyyaml>=5.1 in /usr/lib64/python3.9/site-packages (from transformers>=4.19.0->openai-whisper==20230117) (5.4.1)
Collecting regex!=2019.12.17
Downloading regex-2022.10.31-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (769 kB)
|████████████████████████████████| 769 kB 93.7 MB/s
Collecting packaging>=20.0
Downloading packaging-23.0-py3-none-any.whl (42 kB)
|████████████████████████████████| 42 kB 3.5 MB/s
Requirement already satisfied: typing-extensions>=3.7.4.3 in ./.local/lib/python3.9/site-packages (from huggingface-hub<1.0,>=0.10.0->transformers>=4.19.0->openai-whisper==20230117) (4.4.0)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.9/site-packages (from requests->transformers>=4.19.0->openai-whisper==20230117) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3.9/site-packages (from requests->transformers>=4.19.0->openai-whisper==20230117) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.9/site-packages (from requests->transformers>=4.19.0->openai-whisper==20230117) (1.26.5)
Using legacy 'setup.py install' for openai-whisper, since package 'wheel' is not installed.
Using legacy 'setup.py install' for future, since package 'wheel' is not installed.
Installing collected packages: tqdm, packaging, filelock, tokenizers, regex, huggingface-hub, future, transformers, more-itertools, ffmpeg-python, openai-whisper
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /home/opc/.local/lib/python3.9/site-packages
sysconfig: /home/opc/.local/lib64/python3.9/site-packages
WARNING: Additional context:
user = True
home = None
root = None
prefix = None
Running setup.py install for future ... done
Running setup.py install for openai-whisper ... done
Successfully installed ffmpeg-python-0.2.0 filelock-3.9.0 future-0.18.3 huggingface-hub-0.11.1 more-itertools-9.0.0 openai-whisper-20230117 packaging-23.0 regex-2022.10.31 tokenizers-0.13.2 tqdm-4.64.1 transformers-4.25.1
[opc@mywhisper ~]$
以上で、一旦、コンピュート・インスタンスを再起動します。
sudo shutdown -r now
私はMacユーザーなのでQuickTime Playerで音声を録音しました。
記事の最初の動画が、MPEG4のファイルをtest.m4aとしてアップロードして、Whisperを実行した結果になります。
whisper test.m4a --language ja --model small
最後にsmallとlargeで処理時間を確認してみました。smallで約17秒、largeで約2分22秒でした。無料で出来る範囲ですから、贅沢は言えないでしょう。
[opc@mywhisper ~]$ time whisper test.m4a --language ja --model small
/home/opc/.local/lib/python3.9/site-packages/whisper/transcribe.py:79: UserWarning: FP16 is not supported on CPU; using FP32 instead
warnings.warn("FP16 is not supported on CPU; using FP32 instead")
[00:00.000 --> 00:10.560] こんにちは初めてウィズパーをインストールしてみました これで試してみます
real 0m16.561s
user 0m46.247s
sys 0m1.868s
[opc@mywhisper ~]$ time whisper test.m4a --language ja --model large
/home/opc/.local/lib/python3.9/site-packages/whisper/transcribe.py:79: UserWarning: FP16 is not supported on CPU; using FP32 instead
warnings.warn("FP16 is not supported on CPU; using FP32 instead")
[00:00.000 --> 00:09.000] こんにちは 初めてウィスパーを インストールしてみました これで試してみます
real 2m22.358s
user 4m1.277s
sys 0m24.204s
[opc@mywhisper ~]$
APEXのアプリケーションから呼び出すにはAPIサーバーを作ったり、(処理時間が長いので)非同期処理を実装したりする必要がありそうです。それはそれで手間もかかりますが、それくらいの手間をかける価値はある気がします。