昨今(2023年4月)は ChatGPT の話題で持ち切りです。ですが、やはり、自分用にチューニングしたAIを作るために、自分のPC上でAIを構築したくなってきます。
文章を作成したり 絵を描いたりする生成AIには学習済みモデルが必要です。また、その学習済みモデルから新規に文字列や画像を作成するプログラムも必要です。それらを提供しているのが Hugging Face です。
今回は、windows11 の WSL2 を使って構築した Ubuntu に JupyterLab をインストールし、生成AIを動かします。
PC環境
OS: windows11 home
RAM: 128 GB
GPU: GeForce RTX 3060
WSL2
Microsoft Store より、Ubuntu 20.04.5 LTS をインストールします。

Ubuntuを移動させる
学習済みモデルの多くは数GB程度のサイズです。複数のモデルをダウンロードするとすぐに数TBになります。Cドライブの容量が潤沢にあるPCならよいのですが、多くのPCでは、windows11をインストールした時点でCドライブの空き容量は少なくなっていると思います。そのため、大容量HDD(今回はIドライブ)を増設して、そこにAI用のUbuntuをコピーします。
Windows11 のコマンドプロンプト、あるいはWindows PowerShell を起動します。

次に、以下のコマンドを打ち込み、Ubuntuを複製した後、移動先で復元します。
wsl --list -v ←現在の状況を確認
wsl -t Ubuntu-20.04 ←コピーしたいLinuxが起動(Running)していたら停止
wsl --export Ubuntu-20.04 I:\AI_Ubuntu.tar ←Iドライブに、AI_Ubuntu.tarとして Ubuntu20.04をコピー
wsl --import AI_Ubuntu I:\wsl2 I:\AI_Ubuntu.tar --version 2 ←Iドライブのwsl2のフォルダに、AI_Ubuntu として復元
wsl -d AI_Ubuntu ←復元したAI_Ubuntuを起動
Ubuntuの設定
必要なソフトウェアをインストールしていきます。まずは apt を使って python をインストールします。
apt update
apt upgrade
sudo apt install -y python3-pip
NVIDIA のグラフィックカードを搭載しているなら、ドライバとCUDA関連ソフトウェアをインストールします。インストール後はWSL2の再起動推奨。
apt-get install nvidia-driver-515 ←例として、515のドライバをインストール
CUDAのインストール。
https://developer.nvidia.com/cuda-downloadsでコマンド作成。以下は一例。
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/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
続いて、python 関連のソフトウェアをインストールします。以下、不要なものも含まれているかもしれません。少し多めにインストールしています。
export PATH="$HOME/.local/bin:$PATH"
pip3 install Jupyter
pip3 install jupyterlab
pip3 install pandas
pip3 install numpy
pip3 install SciPy
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
python3 -m pip install tensorflow
pip install --upgrade git+https://github.com/google/flax.git
python3 -m pip install --upgrade pip setuptools
pip3 install huggingface-hub
pip install sentencepiece
pip install launchpadlib
pip install albumentations
pip install diffusers
pip install opencv-python
pip install pudb
pip install imageio
pip install imageio-ffmpeg
pip install pytorch-lightning
pip install omegaconf
pip install test-tube
pip install streamlit
pip install einops
pip install torch-fidelity
pip install transformers
pip install kornia
pip install invisible-watermark
pip install Matplotlib
pip install diffusers
pip install transformers scipy ftfy accelerate
python3 -m pip install --upgrade tensorrt
python3 -m pip install --upgrade tensorrt_lean
python3 -m pip install --upgrade tensorrt_dispatch
以上、インストールが終わったら、Jupyterlabを起動します。
export PATH="$HOME/.local/bin:$PATH"
jupyter-lab --ip='0.0.0.0'
Chromeなどのブラウザで
localhost:8888
と入力し、JupyterLabが使用できれば、生成AIを使用する環境の構築は完了です。


コメント