UbuntuでPytorchをインストールする方法は色々な記事で紹介されていますが、躓くことが多かったので、自分なりにまとめて紹介することにしました。
STEP1 : Nvidiaドライバーをインストールせよ
nvidiaドライバーのインストールも様々な記事で紹介されているので問題ないと思います。
ubuntu-drivers devices
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-driver-510
sudo reboot

ubuntuにCUDA、nvidiaドライバをインストールするメモ - Qiita
使用しているGPUの確認lspci | grep -i nvidia現状入っているCUDA,nvidia-driverの確認dpkg -l | grep nvidiadpkg -l | grep cuda...
STEP2 : Pytorchをインストール
よくpytorchをインストールする前にシステム?の方にCUDAとcudnnをインストールする記事を見るのですが、今回紹介する方法はインストールしなくても良いです。
下のサイトを読むと、PyTorchにはCUDAが付属してくるようなので、システムの方のCUDAはあんまり関係ないみたいです。(ソースからビルドするときは別)

Difference between versions 9.2,10.1,10.2,11.0 of cuda for PyTorch 1.7
Recently,I need to install pytorch ,when I check out the website :install pytorch websiteIt shows four different version 9.2,10.1,10.2,11.0 to choose ,And I hav...

PyTorch + CUDA 11.6
Hi, sir. I have one question: If I installed cuda 113 version pytorch, but my GPU is cuda 11.6. Is this mismatch of version affect the reproducibility of code. ...
で、PyTorchのインストールですが、下のサイトから使いたいバージョンのPyTorchを選んでインストールします。

PyTorch
An open source machine learning framework that accelerates the path from research prototyping to production deployment.
私の場合は以下のようにしてインストールしてみました。
pip install torch==1.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
STEP3 : GPUが使えるか確認せよ
最後にGPUが使えるところまで、できたかを確認します。
print(torch.cuda.is_available())
# TrueならOK
print(torch.version.cuda)
# 私の例なら11.1
GPUが使えることを確認したら終了です!お疲れ様でした
コメント