らんだむな記憶

blogというものを体験してみようか!的なー

WSL2 上で PyTorch を使いたい

基本的には WSL2 上で CUDA を使いたい - らんだむな記憶 を済ませて PyTorch をインストールするだけである。ところで、cuDNN を導入していなくて以下のような値が返ってくる:

>>> import torch
>>> torch.backends.cudnn.version()
8500
>>> torch.backends.cudnn.enabled
True

How to check if torch uses cuDNN - PyTorch Forums によるとどうやら

Yes, you just need to install the NVIDIA drivers and the binaries will come with the other libs. If you want to build from source, you would need to install CUDA, cuDNN etc.

ということで、pip で導入する限りは最初から全部入りらしい。自分でビルドするなら cuDNN が必要ということらしい。自分でビルドするなら CUDA と cuDNN をインストールしなさいと。なんてことだ・・・。今までの苦労は・・・。

CUDA のほうも

$ nvcc -V
Cuda compilation tools, release 11.8, V11.8.89
$ python
>>> import torch
>>> torch.version.cuda
'11.7'

という感じでセットアップしたバージョンとは違った。なるほど・・・。

GCE の新しいインスタンスを作りたい

の続きをしたいので、まとめていく。

計算機: Google Cloud Pricing Calculator

Tokyo

  • Provisioning model はすべて Spot (Preemptible VM)
  • Threads per core = 2

で、月額 10,000 円と 20,000 円の予算でどれだけ使えるか計算してみた:

Series disk type size cost 10000 20000
n1-highmem-4+T4 standard PD 100 5.2+(0.06+0.07)*hrs
n1-highmem-4+T4 standard PD 200 10.4+(0.06+0.07)*hrs
a2-highgpu-1g standard PD 300 15.6+(0.22+0.88)*hrs
a2-highgpu-1g standard PD 400 20.8+(0.22+0.88)*hrs 48 115
a2-highgpu-1g balanced PD 300 39.0+(0.22+0.88)*hrs 31 99
a2-highgpu-1g SSD PD 300 66.3+(0.22+0.88)*hrs

Regular インスタンスの場合は

Series disk type size cost 10000 20000
n1-highmem-4+T4 balanced PD 300 39.0+(0.30+0.37)*hrs

Oregon

  • Provisioning model はすべて Spot (Preemptible VM)
  • Threads per core = 2
Series disk type size cost 10000 20000
n1-highmem-4+T4 standard PD 70 1.6+(0.05+0.11)*hrs
n1-highmem-4+T4 standard PD 100 2.8+(0.05+0.11)*hrs
n1-highmem-4+T4 standard PD 200 6.8+(0.05+0.11)*hrs
n1-highmem-4+V100 balanced PD 300 30.0+(0.05+0.74)*hrs 55 149
a2-highgpu-1g standard PD 300 10.8+(0.22+0.88)*hrs
a2-highgpu-1g standard PD 400 14.8+(0.22+0.88)*hrs 53 121
a2-highgpu-1g balanced PD 300 31.1+(0.22+0.88)*hrs 39 106
a2-highgpu-1g SSD PD 300 51.0+(0.22+0.88)*hrs

$1 = ¥135

ディスクの比較

Google Cloud のブロックストレージの使い方. 2020年7月に新しい バランス永続ディスク( pd-balanced… | by Hawk Yasuhara | google-cloud-jp | Medium

参考 (AWS EC2)

A100 x 8

インスタンス 時間単価 vCPU メモリ ストレージ ネットワーク
p3.2xlarge 4.194 USD 8 61 GiB ESB のみ 10 Gbps
p4d.24xlarge 44.92215 USD 96 1152 GiB 8 x 1000 SSD 400 Gbps

ハイパフォーマンスブロックストレージの料金 – Amazon EBS の料金 – Amazon Web Services

  • 汎用 SSD (gp3) - ストレージ: 0.08USD/GB 月

なので、

  • p3.2xlarge: 24.0+4.194*hrs: 11 hrs/10000, 29hrs/20000
  • p3.2xlarge: 44.92215*hrs: 1 hrs/10000, 3hrs/20000

作成コマンド

gcloud compute --project=プロジェクトID instances create ml-dev --zone=asia-northeast1-a --image-family=ubuntu-2004-lts --image-project=ubuntu-os-cloud --subnet=VPCで作成したサブネット名 --network-tier=PREMIUM --no-restart-on-failure --maintenance-policy=TERMINATE --preemptible --deletion-protection --machine-type=a2-highgpu-1g --labels=env=ml-dev --create-disk="name=ディスク名,image-family=ubuntu-2004-lts,image-project=ubuntu-os-cloud,size=300GB,type=pd-balanced,boot=yes"
  • プロジェクトID: gcloud projects list で調べられる。