😓

[失敗]おうちChatgptと言われているFlexGenをゲーミングノートPCでためす(GPUサポートあり)

2023/03/05に公開約7,100字

[失敗]おうちChatgptと言われているFlexGenをゲーミングノートPCでためす(GPUサポートあり)

おうちで動くchatgptと言われているらしいFlexGenを試してみたくなって
手元にあった下記の環境でいけるかどうか試してみてだめだった内容になります

  • Ubuntu 22.04.2 LTS
  • GeForce RTX 2060 6GB
  • Intel(R) Core(TM) i7-8750H
  • メモリ16GB

➡AWSのEC2インスタンスのg4dn.xlargeに近そうな構成かなと

https://aws.amazon.com/jp/ec2/instance-types/g4/

nvida driverのインストール

下記サイトでapt周りの設定を確認してから

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_network

cuda-driversのみインストールを実施していきます

$ 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-drivers

nvida docker環境を構築

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker

➡インストールガイドの通りすすめる

$ curl https://get.docker.com | sh \
  && sudo systemctl --now enable docker

➡dockerのインストーラを実行する(aptですでにdocker関連のパッケージがインストール済みの場合はsudo apt purge docker*などで先にアンインストールする必要があるかもしれません)

$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
      && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
            sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
            sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

➡nvidia-container-toolkit apt レポジトリを設定して

$ sudo apt-get update
$ sudo apt-get install -y nvidia-container-toolkit
$ sudo nvidia-ctk runtime configure --runtime=docker
$ sudo systemctl restart docker

➡nvidia-container-toolkitをインストール

$ sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.30.02              Driver Version: 530.30.02    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 2060         On | 00000000:01:00.0 Off |                  N/A |
| N/A   36C    P8                2W /  80W|      8MiB /  6144MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
+---------------------------------------------------------------------------------------+

nvidia-smiをコンテナ内で実行するとこんな感じになるはず

FlexGenをためす

https://github.com/piroz/docker-flexgen

こちらを少しアレンジさせていただき、つくったdockerのレポトリをgithubからcheckoutして

$ cd docker-flexgen
$ sudo docker build . -t flexgen
$ sudo docker run --rm --gpus all flexgen
Downloading ()okenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 685/685 [00:00<00:00, 846kB/s]
Downloading ()lve/main/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 651/651 [00:00<00:00, 776kB/s]
Downloading ()olve/main/vocab.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 899k/899k [00:02<00:00, 365kB/s]
Downloading ()olve/main/merges.txt: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 456k/456k [00:01<00:00, 342kB/s]
Downloading ()cial_tokens_map.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 221/221 [00:00<00:00, 260kB/s]
Initialize...
Load the pre-trained pytorch weights of opt-6.7b from huggingface. The downloading and cpu loading can take dozens of minutes. If it seems to get stuck, you can monitor the progress by checking the memory usage of this process.
Downloading ()lve/main/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 651/651 [00:00<00:00, 690kB/s]
Downloading ()model.bin.index.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 41.9k/41.9k [00:00<00:00, 81.8kB/s]
Downloading ()00001-of-00002.bin";: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 9.96G/9.96G [15:16<00:00, 10.9MB/s]
Downloading (…)00002-of-00002.bin";: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3.36G/3.36G [05:29<00:00, 10.2MB/s]
Loading checkpoint shards:   0%|                                                                                                                                                                                                                                    | 0/2 [00:00<?, ?it/s]Killed

➡実行して寝ておきたらこんな感じになっていた
今回--compress-weightのオプションで学習済みの重みファイルのダウンロードをしていたようだが
前述のコマンド出力結果からファイル9.96G3.36GなどのファイルサイズのものをLoadしようとしたところでKilledとなっていた

dmesgでの確認

2023-03-05T22:10:33,899738+09:00 oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=systemd-oomd.service,mems_allowed=0,global_oom,task_memcg=/system.slice/docker-55e9ef773709e7e9eef0aae65e71b08ef6aed027c5edcac3ceba155b2ef045e6.scope,task=python3,pid=51404,uid=0
2023-03-05T22:10:33,899780+09:00 Out of memory: Killed process 51404 (python3) total-vm:37378212kB, anon-rss:6312644kB, file-rss:76412kB, shmem-rss:0kB, UID:0 pgtables:35300kB oom_score_adj:0

➡OOM-killerが発動していた

小手先のdockerオプション--oom-kill-disableで対処しようとしたが

$ sudo docker run --rm --gpus all --oom-kill-disable -m 15G flexgen bash
WARNING: Your kernel does not support OomKillDisable. OomKillDisable discarded.

➡今回の環境は--oom-kill-disableは使えない環境っぽかった

次のアクションの予定

今回はスペック不足であるそうな結果となったが
現状これ以外の機材を揃えることはできなさそう
compress-weightのオプションあたりどのようなことをやっているのか見て
省メモリ化が可能なのかどうかを見てみたい

Discussion

ログインするとコメントできます