Installing PyTorch with Cuda

This tutorial was made in April 2023, and can be subjective to changes.

1. Check your NVIDIA driver

Open the NVIDIA Control Panel. Click System Information and check the driver version. It should be greater then 531.41, as this is the current driver version at the time of writing.

If you have an older version, goto https://www.nvidia.com/en-us/geforce/drivers/ and update your driver. There is an automatic and manual driver update possible if you know the videocard type. image

2. Open a command prompt

Open a Windows terminal or the command prompt (cmd) and type python. The Windows app store will open automatically where you can install it from! image

3. Install pytorch with cuda

Goto the pytorch website https://pytorch.org/get-started/locally/ and select the necessary buttons using Pip. image e.g.

C:\Users\demo> pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

And also install numpy:

C:\Users\demo> pip3 install numpy

4. Test if cuda is recognized

Try this oneliner:

C:\Users\demo> python -c "import torch; print(torch.rand(2,3).cuda())"

If you get a tensor back, you are ready to go.

If you have more then 1 card installed, you can check the count:

C:\Users\demo> python -c "import torch; print(torch.cuda.device_count())"

image