Setting up PyTorch with CUDA on Windows 11 for GPU DeepLearning (2023 December)

Kajhanan Kailainathan
3 min readDec 22, 2023

--

This thing can be confusing and annoying. I just documented the steps. Hope this helps 👍.

Step 1: Check GPU from Task Manager

  1. In Windows 11, right-click on the Start button.
  2. Select Task Manager from the menu.
  3. Select Performance from the leftmost tab.
  4. In the last pane of the tab, choose GPU. If this option is available, it will likely be at the bottom of the list.
  5. In the top right corner of the GPU selection, information about your computer’s GPU will be visible. (If multiple GPUs are available, choose any one which is an NVIDIA GPU).

Step 2: NVIDIA Video Driver

  1. Download NVIDIA Video Driver here. Go to the link and select the drop down list as follows. Choose the Product Type, Product Series, and Product fields according to your GPU name (found from Step 1). Choose your Operating System and do not change the Download Type. Click search button and download.
  2. Run the installer and install the driver.

Step 3: CUDA Toolkit 11.6 or 12.1

  1. Download CUDA Toolkit 11.8 or CUDA Toolkit 12.1, by selecting the appropriate selections from the respective links.

(Operating System: Windows > Architecture: x86_64 > Version: 11 > Installer Type: exe(local))

2. Run the installer and install CUDA toolkit.

Step 4: Verify CUDA path is properly set

  1. Press the Windows key and R together.
  2. Type sysdm.cpl in the search bar and hit enter.
  3. Choose Advanced from the top array of tabs.
  4. Click Environment Variables found at the bottom of the window.
  5. Verify that the CUDA_PATH field under System variables is set as follows.

{path where Cuda Toolkit is installed}\NVIDIA GPU Computing Toolkit\CUDA\{v12.1 or v11.6}

This will be something like C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1

Step 5: Visual Studio, C++

  1. Download the Visual Studio Community edition here.
  2. Run the installer. At some point you will be required to select components that you would like to install.

3. Select the Individual components tabs as shown in the figure above.

4. Select all the C++ components in addition to the ones that are already selected.

5. Finish the installation.

Step 6: Download Miniconda and create an environment

  1. Download Miniconda from here, and install miniconda.
  2. Open the Anaconda prompt. (Search for Anaconda from Windows Search bar)
  3. Create a python 3.9 environment using the following command.
conda create --name torchenv python=3.9

Note that this environment should be created after the installation of CUDA Toolkit. Otherwise, there won’t be CUDA compatibility when PyTorch is installed.

Step 7: Install Pytorch with CUDA and verify

  1. Open the Anaconda prompt and activate the environment you created in the previous step using the following command.
conda activate torchenv

2. Install PyTorch using the following command. (Choose command according to the CUDA version you installed)

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

3. Open Python Interpreter for the miniconda environment. Import torch and run the following commands to verify.

>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.device_count()
1
>>> torch.cuda.current_device()
0
>>> torch.cuda.device(0)
<torch.cuda.device object at 0x000002310A1BBC10>
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce MX250'

--

--