This is a step-by-step guide to enable GPU training for deep learning projects in any code editor, whether it's Jupyter Notebook, VS Code, or PyCharm Professional.
Note: This setup was personally tested on my university's lab computer, which has an NVIDIA RTX A6000 GPU.
- Check your GPU model by running the following command in the terminal:
nvidia-smi- Copy and paste your GPU name into the search bar on NVIDIA's driver download page.
- Download the latest driver for your GPU:
- Open it and install with default settings.
- Download and install Visual Studio Community Edition.
- Open Visual Studio and update if prompted, then close it.
- Download Visual Studio
- Install everything using the default settings.
- Download Anaconda
- Run the following command to check your CUDA version:
nvidia-smi- Visit PyTorch Local Installation Guide to find the correct CUDA version.
- Download the CUDA Toolkit for your version:
- Windows -> Architecture:
x86_64 - Version:
11(For windows 11) - Installer Type:
.exe (local) - Download CUDA Toolkit
- Windows -> Architecture:
- Go to
C:\Program Files - Look for NVIDIA GPU Computing Toolkit folder
- Inside, check for a CUDA folder
- Open it and ensure it contains a folder named
12.x(or your installed version)
- Download the latest cuDNN version.
- Choose Local Windows Installer (ZIP).
- Download cuDNN
- Open it and install with default settings.
- Open
File Explorerand split the screen into two sections. - Navigate to:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\12.x - Open the cuDNN archive in another window.
- Copy and paste the contents of the following folders:
- all contents of bin from cuDNN archive β Paste into
CUDA\12.x\bin - all contents of include from cuDNN archive β Paste into
CUDA\12.x\include - all contents of lib from cuDNN archive β Paste into
CUDA\12.x\lib
- all contents of bin from cuDNN archive β Paste into
- Open Edit the System Environment Variables via Windows Search.
- Check if CUDA_PATH and CUDA_PATH_V12_x exist under system variables.
- If they match your CUDA installation path, you're good to go!
- Go to PyTorch Official Site
- Select the stable version.
- Choose the correct CUDA version.
- Copy the given pip command from website and paste it into your VS Code terminal:
- It looks like this: (It is for CUDA 12.6)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126- Open Anaconda Navigator and choose and open VS Code
- Open VS Code Terminal
- Change the terminal to Git Bash
- Paste and execute the copied command
Make a new .ipynb file Run the following script to check if your GPU is correctly set up:
import torch
print("Number of GPUs:", torch.cuda.device_count())
print("GPU Name:", torch.cuda.get_device_name(0))
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)Number of GPUs: 1
GPU Name: NVIDIA RTX A6000
Using device: cuda
β Now, you are ready to train deep learning models using GPU! π