環境
Windows 11
Microsoft Store版 Python 3.10
動機
1年ほど前からバージョンアップしていなかったので、なんとなく更新することにした。
python -c "import torch; print( torch.__version__ )"
2.0.1+cu118
必要となるCUDAのバージョンの確認
PyTorchのページにアクセスし、使用可能なCUDAのバージョンを確認する。PyTorch 2.2.1では、11.8と12.1となっている。今回は12.1を使用してみる。

CUDA Toolkit 12.1.1のインストール
NVIDIA DeveloperのページからCUDA Toolkit 12.1.1をダウンロードし、インストールする。
なぜか、高速インストールだとエラーになってしまったので、カスタムを選択する。

CUDAのRuntime、Documentation、Developmentのみチェックして、次へをクリックすると正常にインストールが始まった。Nsightは後で入れることにする。

正常にインストール完了した。

cuDNN v8のインストール
NVIDIA DeveloperのページからcuDNN v8.9.7 (December 5th, 2023), for CUDA 12.xをダウンロードし、任意のファルダに解凍、binフォルダにパスを通す。
PyTorch 2.2のインストール
1.旧バージョンを削除
pip uninstall torch torchvision torchaudio
2.新バージョンをインストール
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
3.確認
インストール完了後、下記のコマンドを実行しバージョンを確認する。
python -c "import torch; print( torch.__version__ )"
2.2.1+cu121
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())
2.2.1+cu121
True
NVIDIA GeForce RTX 3060 Ti