PyTorch

PyTorch, CUDA, Python 설치

재진. 2024. 8. 9. 10:28

[ PyTorch, CUDA, Python 설치 ]

 

  • 설치할 때 2가지 경우가 있다고 생각하는데요.
    • 원하는 PyTorch, Python version에 맞게 CUDA 설치
    • 본인 GPU에서 가능한 가장 높은 version 설치(2, 1, 3, 4, 5 순으로 보시면 됩니다.)

위 GPU 이상이면 현재 최신인 2.4.0까지 가능합니다.

 

 


 

 

원하는 PyTorch, Python version에 맞게 CUDA 설치

1. 원하는 PyTorch나 Python에 맞추어 설치 가능한 버전 찾기 

저는 PyTorch 2.4를 설치할 거라 python >= 3.8, CUDA 12.1을 설치하겠습니다.

     

 

https://github.com/pytorch/pytorch/blob/main/RELEASE.md#release-compatibility-matrix

 

pytorch/RELEASE.md at main · pytorch/pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration - pytorch/pytorch

github.com

 

 


 

2. 원하는 버전의 CUDA설치가 가능한 GPU인지 확인

( 사실 첫 번째 사진만 보면 왠~만하면 다 가능할 듯합니다)

  1. GPU에 해당되는 Compute Capability확인
  2. Compute Capability에 따라 설치 가능한 CUDA SDK version 확인

2060 super 임으로 Compute Capability 7.5점입니다.


Compute Capability에 따른 설치 가능한 CUDA SDK Version 찾기(7.5점, 10.0~12.5 SDK Version)

 

문제없는 걸 확인했으니 SDK 설치 ㄱㄱ


https://en.wikipedia.org/wiki/CUDA#GPUs_supported 

 

CUDA - Wikipedia

From Wikipedia, the free encyclopedia Parallel computing platform and programming model In computing, CUDA (originally Compute Unified Device Architecture) is a proprietary[1] parallel computing platform and application programming interface (API) that all

en.wikipedia.org

 

 


 

3. CUDA SDK download and install 하기

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

 

CUDA Toolkit Archive

Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production

developer.nvidia.com


 

설치가 완료되면 cmd창에서 확인 가능합니다

nvcc --version

가상환경에서는 바로 적용이 안되어서  재부팅하였습니다

 

 


 

4. PyTorch 설치하기

본인에게 맞게 option 선택하시고 command 복사해서 실행시키시면 끝입니다.


# CUDA 12.0, pytorch 2.4.0
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

# CUDA 11.8
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda=11.8 -c pytorch -c nvidia
# CUDA 12.1
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU Only
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 cpuonly -c pytorch

# CUDA 11.8
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia
# CUDA 12.1
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU Only
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 cpuonly -c pytorch

 

 

PyTorch == 2.4.0 (https://pytorch.org/get-started/locally/)

PyTorch 2.4.0 미만의 버전을 설치 시(https://pytorch.org/get-started/previous-versions/)

 

Start Locally

Start Locally

pytorch.org

 

 


 

5. 설치 확인

    Terminal 

conda list < grep torch


    Python

import torch
print(torch.__version__)
print(torch.cuda.get_device_name(device = 0))
print(torch.cuda.device_count())

- 끝 -