How to setup PyTorch with CUDA in Windows 11

A guide to setting up Pytorch with GPU support in Windows 11

Nilotpal Sinha PhD
3 min readSep 3, 2022
Photo by Sunrise King on Unsplash

If you have recently bought a new laptop with Windows 11 installed on it and are interested in doing some deep learning using PyTorch then you have come to the right place.

In this article, I will give a step-by-step guide on how to install PyTorch with GPU support.

My laptop is HP Omen 16 with RTX 3050 graphics card.

One of the pre-requisite is that you need to have “conda” installed in your system. You get this when installing python using “Anaconda”. Please check the link to install “Anaconda

Steps

First, you need to install the Cuda toolkit on your system, or else you will get an error whenever you try to run the “nvcc” command in Powershell.

Figure 1

Installing Cuda Toolkit

You will first need to figure out which version of Cuda is installed when the graphics card driver was installed. This can be checked by typing the following command in PowerShell:

nvidia-smi.exe
Figure 2

From the output, you will get the Cuda version installed. For me, it was “11.6”.

Now, to install the specific version Cuda toolkit, type the following command:

conda install cuda --channel nvidia/label/cuda-11.6.0

Important tip: You have to modify the channel for your specific version of the Cuda. You can get the specific channel link from this link.

Figure 3

After the installation, you can verify if the toolkit is installed correctly or not by using the following command:

nvcc --version
Figure 4

Installing PyTorch

Go to the PyTorch website and select the appropriate option to get the command for installing Pytorch with GPU support. I chose the installation using “pip” as it was easier for me.

Figure 5

Run the command encircled in figure 5 to install PyTorch using pip.

Checking the Installation

After you have completed the installation, you have to check if the installation works or not.

Type in the following command in the jupyter notebook or the python interpreter:

import torchprint(f'PyTorch version: {torch.__version__}')
print('*'*10)
print(f'_CUDA version: ')
!nvcc --version
print('*'*10)
print(f'CUDNN version: {torch.backends.cudnn.version()}')
print(f'Available GPU devices: {torch.cuda.device_count()}')
print(f'Device Name: {torch.cuda.get_device_name()}')

You should not get any error and get a similar result as shown below:

Figure 6

Conclusion

In this article, I provide a guide on how to install PyTorch with GPU support on Windows 11. Hope you can now experiment with deep learning in Windows 11 as well.

--

--

Nilotpal Sinha PhD

Passionate about life philosophy, AI, technology, hacking and coding. PhD in Computer Science.