데스크톱에 gpu가 있는데도 쓰지 않다가 Jupyter Notebook 환경에서 모델 트레이닝을 하게 되면서 설치하게 됐다.
따로 가상환경을 만들어서 사용한다면 가상환경 만들고 활성화 한 다음에 2번부터 하면 된다.
0. Visual Studio 가 설치 되어 있어야 한다.
1. 가상환경 설정
가상환경 새로 만들기
(anaconda prompt를 이용해 로컬에서 만드는 것으로, 서버의 폴더에서 만드는 가상환경과는 차이 존재)
# list of all the envs
conda env list
# creating python virtual env
conda create -n {env_name} python
# to specify the version of python
conda create -n {env_name} python=3.7
#creating with prior library's
conda create -n {env_name} python anaconda
가상환경 실행
# activate env in conda
conda activate {env_name}
2. CUDA 설치
2.1 gpu 확인
내 컴퓨터에 있는 gpu 모델은 [작업관리자 > 성능] 으로 들어가면 확인 가능하다.
2.2 NVIDIA 드라이버 설치
https://www.nvidia.com/Download/index.aspx?lang=kr
NVIDIA 드라이버 다운로드
www.nvidia.com
확인 gpu에 맞게 선택해서 설치해주면 된다.
2.3 cuda toolkit 설치
주의점: 버전은 가장 최근 버전보다 조금 더 낮은 버전을 설치하자
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
latest Release로 자신있게 11.4.2 버전을 설치했다가 온갖 오류로 3시간 정도 고생했다.
구글링으로 원인과 해결방법도 찾아보고, 공식 홈페이지를 보고 따라해봤지만,
import torch
torch.cuda.is_available()
print(torch.version.cuda)
의 결과는 'False'와 'None' 이었다.
많은 글들을 참고하다 버전의 문제일 수 있다는 생각이 들어, 11.4 버전은 다 지우고 10.1버전으로 다시 했더니 10분만에 모든게 해결됐다.
알맞는 os, version, installer type을 선택하면 exe 파일을 다운 받을 수 있다.
3. PyTorch 설치
3.1 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
#version10
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
#version11
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
pytorch를 설치 할 때, 마찬가지로 os, pacakge, language, compute platform 등을 다 선택하면, 입력해야할 명령어를 알려준다.
version 10 과 version11의 코드의 차이가 존재한다. 위 코드는 anaconda promt에서 가상환경에 들어간 뒤 쳐주면 된다.
version11을 하면서 HTTP 연결이 끊겼다는 오류와 torchvision, torch의 설치가 제대로 안 되는 문제들이 발생했는데,
conda install --insecure pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
--insecure 를 써주면 어떻게 어떻게 깔리기는 하지만, 앞서 언급했던 cuda 버전 확인과 is_available()를 했을 때 'false'와 'none'이 나온다. (이후 버전을 10대로 낮추어서 진행할 때는 위와 같은 문제들이 발생하지 않았다.)
3.2 CuDNN 설치
위 명령어를 입력하면, CuDNN도 설치되는 것으로 알고 있지만, 따로 설치가 가능하다.
https://developer.nvidia.com/cudnn
NVIDIA cuDNN
NVIDIA cuDNN The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, nor
developer.nvidia.com
사이트를 통해 다운로드 하는 경우, 회원가입과 로그인이 필요하다.
다운로드한 [cuda > 10.1 > bin, lib, extras] 파일들을 [내pc > c드라이브 > 프로그램파일 > NVIDIA GPU Computing Toolkit > CUDA > 10.1 ] 에 복사해주고 환경 변수 편집으로 [시스템 속성 > 환경 변수 > path ] 에 추가한다.
4. 설치 확인
import torch
torch.cuda.get_device_name(0) #check cuda name
torch.cuda.is_available()
torch.__version__
위 명령어들로 pytorch, cuda가 모두 제대로 설치 되었는지 확인할 수 있다.
'Python' 카테고리의 다른 글
python import module (sys.path) (0) | 2021.11.15 |
---|