본문 바로가기
공부/딥러닝

[딥러닝] 우분투에서 CUDA 설정 & Pytorch 설치

by 붕붕=33 2022. 4. 16.

경험상 Pytorch는 버전에 민감하다.

 

특정 버전의 Pytorch를 사용하기 위해 신중한 CUDA 버전 선택이 요구될 수 있다.

 

이번 글에서는 우분투 20.04에서

여러 CUDA 버전을 다운받아 그 중 한 경로를 설정하고

호환되는 Pytorch를 설치하는 방법에 대해 설명하겠다.

 

 


 

1. CUDA 설치

 

자신이 설치하고자 하는 Pytorch 버전에 호환되는 CUDA 버전을 확인한다.

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

 

PyTorch

An open source machine learning framework that accelerates the path from research prototyping to production deployment.

pytorch.org

물론 해당 CUDA 버전이 그래픽 드라이버와 호환되는지도 확인해야 한다.

CUDA Toolkit and Corresponding Driver Versions

 

Release Notes :: CUDA Toolkit Documentation

This section covers CUDA Libraries release notes for 11.x releases. CUDA Math Libraries toolchain uses C++11 features, and a C++11-compatible standard library (libstdc++ >= 20150422) is required on the host. CUDA Math libraries are no longer shipped for SM

docs.nvidia.com

 

호환성 확인 후 NVIDIA 홈페이지에서 CUDA를 다운받는다.

https://www.nvidia.co.kr/Download/index.aspx?lang=kr

 

Download the latest official NVIDIA drivers

Download the latest official NVIDIA drivers

www.nvidia.com

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

 

 

2. CUDA 경로 설정

 

여러 버전의 CUDA를 다른 이름의 경로로 설치해두고

그 중 사용하고자 하는 경로를 .bashrc 파일에 입력하여 설정할 수 있다.

(참고: Shell의 개념, bashrc의 개념)

 

먼저 에디터로 .bashrc (또는 .profile) 파일을 열고

$ vim ~/.bashrc

 

CUDA 경로에 맞게 아래와 같이 추가한다.

(이 경우 경로가 /usr/local/cuda-11.1이지만 본인에 맞게 수정하면 된다.)

export PATH=/usr/local/cuda-11.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH

 

수정된 내용을 아래 명령어로 적용시킨다.

$ source ~/.bashrc

 

nvcc -V 또는 nvcc --version 명령어를 통해 CUDA 설정을 확인한다.

$ nvcc -V

 

 

3. Pytorch 설치

  • 최신 버전

https://pytorch.org/get-started/locally/

 

PyTorch

An open source machine learning framework that accelerates the path from research prototyping to production deployment.

pytorch.org

 

  • 이전 버전

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

 

PyTorch

An open source machine learning framework that accelerates the path from research prototyping to production deployment.

pytorch.org

 

자신이 설치하고자 하는 pytorch 버전을 찾아

해당 명령어를 복사하여 명령창에 입력하여 설치한다.

 

이전 버전들의 경우

conda로 설치하는 경우와 wheel(pip)로 설치하는 경우가 있는데

pip는 Python 라이브러리만 지원하고

conda는 Python을 비롯한 C/C++, Fortran 등 또한 지원한다.

 

 

댓글