-
[Pytorch/cuda] 환경설정 - CUDA 버전에 맞는 Pytorch 설정하기 AtoZStudy Bits 2023. 10. 17. 13:48
CUDA 버전에 맞지 않는 Pytorch를 설치할 수는 있지만, 반드시 어느 순간 큰 문제에 직면하게 되고, 모든 가상환경을 처음부터 빌드해야하는 엄청난 상황에 맞닥뜨리게 될 수 있다(본인얘기...). 따라서, 처음 설정할 때부터 아주 신중하게 하나 하나 깔아야하는데, torch 관련 라이브러리들이 dependency 이슈가 엄청 까다롭기 때문에 환경설정에만 허비하는 날들이 굉장히 많고, 내 문제는 왜 stackoverflow, git issue 등에 없는지...
그러니까 하고싶은 말은, 처음부터 제대로 설치해봅시다.
Prerequisites
NVIDIA Driver 다운로드 - https://www.nvidia.co.kr/Download/index.aspx?lang=kr
nvidia-smi로 설치된 driver 버전 조회 가능
1. CUDA Version 확인하기
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
...
Cuda compilation tools, release 11.6, V11.6.124
...위와 같은 output을 얻을 수 있다. 현재 내가 사용하는 서버의 CUDA 버전은 11.6v 이다.
* nvidia-smi 명령어는 현재 버전과는 조금 다른 cuda 버전(Driver와 호환이 잘 되는 추천 버전)을 출력하기 때문에 위의 명령어로 확인하는 것이 정확하다.
2. CuDNN 설치하기
아래 사이트에서 로그인 후 안내하는 과정을 진행하면, 각 CUDA 버전에 맞는 cuDNN을 추천해주며, 환경에 맞는 파일을 다운로드 받으면 된다.
https://developer.nvidia.com/rdp/cudnn-download
https://developer.nvidia.com/cuda-gpus
CUDA GPUs - Compute Capability
Explore your GPU compute capability and CUDA-enabled products.
developer.nvidia.com
* GPU 용량에 따라 사용가능한 CUDA Version 확인하기 (Optional)
https://en.wikipedia.org/wiki/CUDA
CUDA - Wikipedia
From Wikipedia, the free encyclopedia Parallel computing platform and programming model CUDA (or Compute Unified Device Architecture) is a proprietary and closed source parallel computing platform and application programming interface (API) that allows sof
en.wikipedia.org
3. CUDA Version 에 맞는 Pytorch 설치하기
Pytorch 설치에 앞서, 설치된 driver 버전에 맞는 pytorch 버전 선정이 필요하다. 아래 링크에서 쉽게 확인이 가능하다.
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions
CUDA 12.3 Release Notes
3.1. Notice This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. NVIDIA Corporation (“NVIDIA”) makes no representations or warranties, expressed
docs.nvidia.com
나는 Pytorch 버전이 1.11.0 ~ 1.13.0 사이가 필요하기 때문에, CUDA Version 11.6에 맞는 명령어로 설치를 진행해주었다. 이 과정에서 문제가 발생하는 경우 링크된 이전 포스팅을 참고하여 해결하면 된다.
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
다른 버전을 설치하고 싶은 경우 아래 공식 사이트에서 안내된 Previous PyTorch Version Install 문서를 참조하면 된다.
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