728x90

When using deep learning in Python, setting up the GPU and CUDA environment is important. There are two main ways to do this:

 

● Personal use – You can install the latest CUDA and PyTorch versions that work best with your GPU.

Work – You may need to use a specific version of PyTorch to match project requirements.

 

To make sure everything runs smoothly, your GPU driver, CUDA, cuDNN, and PyTorch versions must be compatible. Since reinstalling or rolling back versions can take a lot of time, it’s best to set up the environment correctly from the start and focus on actual development.

 

This blog explains how to set up the environment based on PyTorch 1.13, assuming your GPU meets the requirements.

 

1. Checking GPU Environment: Run ‘cmd’ and execute ‘nvidia-smi’ to check the GPU status

Verify the installed CUDA and driver versions. The CUDA version displayed in the command prompt represents the highest supported version, but older versions are also compatible. As of April 2025, the latest driver update for RTX 30 series GPUs includes CUDA 12.x and driver 5xx.xx. Visit the official website below to check for the latest updates and install them accordingly.

 

NVIDIA Driver: docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions

 

 

2. Checking CUDA Version for PyTorch 1.13

PyTorch can be installed using either conda or pip, and you should set up the CUDA environment based on your personal system before proceeding with the installation. In this step, we are only checking the CUDA version. PyTorch 1.13 is confirmed to be compatible with CUDA 11.6x and 11.7x.

 

pytorch.org/get-started/previous-versions/

 

3. Capability Based on GPU Environment

Additionally, you need to check the Capabilityof your specific GPU. For RTX 3050, 3060, 3070, 3080, and 3090, the capability is 8.6 and they can be used with CUDA 11.1 or later.

 

GPU Capability: en.wikipedia.org/wiki/CUDA

 

4. Setting Up the CUDA Environment and Installing PyTorch

Based on PyTorch 1.13, install CUDA 11.7.x, followed by cuDNN 11.x, considering the GPU capability. For cuDNN, extract the files and copy them into the folder where CUDA is installed to complete the environment setup. Finally, install PyTorch 1.13 using either pipor conda, as previously explained.

 

CUDA: developer.nvidia.com/cuda-toolkit-archive

cuDNN: developer.nvidia.com/rdp/cudnn-archive

 

5. Checking Environment Setup and Functionality: nvcc - - version

You can verify the installation by running "nvcc --version" (or "nvcc -V") in the command prompt “cmd”. The following code can be used to check whether the GPU is available. 

import torch
print(torch.cuda.is_available())


Additionally, in practical applications, the code below can be used to automatically assign the device.

device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')

 

** Refer to korean version

728x90
728x90

파이썬 Python 기반에 Deep Learning(D/L) 활용 시 GPU 및 CUDA 환경 설정에 대한 설명입니다. 환경 설정에 방향은 두 가지 정도로 나뉠 수 있습니다. 개인적인 활용에서는 GPU 환경에 맞춰 CUDA 및 Pytorch 최신 환경으로 구성할 수 있고, 업무 환경 상 Pytorch 특정 버전에 맞춰 환경을 구성해야 될 수도 있겠습니다.

 

환경 설정에서는 GPU 드라이버, CUDA, cuDNN, Pytorch 버전이 호환되어야 정상 활용 가능하므로 개인적인 환경에 따라 다를 수 있겠지만 상황에 따라 재설치 및 Rollback 시간이 상당하므로 가능하면 환경설정에 시간 소모를 줄이고 개발에 집중하는 것이 좋다고 생각합니다.

 

현 블로그에서는 기본적으로 GPU 환경 조건이 충분하다는 상황에서 Pytorch 1.13 기준에서 환경 설정 과정을 설명합니다.

 

1. GPU 환경 확인: cmd 실행 후 ‘nvidia-smi’ 확인, 드라이버 업데이트

CUDA 버전과 드라이버 버전 확인 합니다. cmd 창에 출력되는 CUDA 버전은 지원 가능한 버전이므로 이하 버전들도 적용 가능합니다. 23년 12월 기준 RTX 30 시리즈 드라이버 최신 업데이트 시 CUDA 12.x와 드라이버 5xx.xx 입니다. 아래 주소 확인 후 최신 업데이트 합니다.

 

NVIDIA Driver: docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions

 

 

 

2. Pytorch 1.13 기준 CUDA 버전 확인

파이토치 설치 방법은 conda와 pip으로 구분되어 있으며 개인 환경에 맞춰 CUDA 환경 구성 후 설치하면 됩니다. 현 시점에서는 CUDA 버전만 확인합니다. 파이토치 1.13은 CUDA 11.6x와 11.7x와 연동되는 것을 확인 할 수 있습니다.

 

pytorch.org/get-started/previous-versions/

 

 

3. GPU 환경에 따른 Capability

추가로 본인 GPU 환경에 따른 Capability를 확인해야 됩니다. RTX 3050/30603070/3080/3090의 경우 Capability 8.6 이며, 이는 CUDA 11.1 이상에서 활용 가능함을 확인 할 수 있습니다.

 

GPU Capability: en.wikipedia.org/wiki/CUDA

 

 

 

4. CUDA 환경 구축 및 Pytorch 설치

파이토치 1.13 호환성 기준으로 Capability 고려하여 CUDA 11.7.x 설치 후 cuDNN 11.x 설치하면 됩니다. cuDNN의 경우 압축 해제 후 파일들을 CUDA 설치된 폴더에 복사/붙여넣기하여 환경 구성을 완료합니다. 이후 앞에서 확인한 파이토치 1.13을 pip 또는 conda로 최종 설치합니다.

 

CUDA: developer.nvidia.com/cuda-toolkit-archive

cuDNN: developer.nvidia.com/rdp/cudnn-archive

 

 

 

5. 환경 구성 및 동작 확인: nvcc - -version

cmd 창에서 ‘nvcc –V’ 또는 ‘nvcc –version’으로 설치 확인 할 수 있습니다. 아래 코드를 통해 GPU 사용 및 할당 가능한지 확인할 수 있습니다.

 

import torch

print(torch.cuda.is_available()) # True면 활용 가능

 

추가로 실무에서 아래 코드로 디바이스 자동 지정 할 수 있습니다.

device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')

728x90

+ Recent posts