블로그

파이토치(PyTorch) 설치 방법 (Nvidia CUDA용)

AI · 2023-04-01 · 공개

- 페이스북(메타)의 오픈소스 머신 러닝 라이브러리, 딥러닝 프레임워크

   - 파이토치 이외에 구글의 텐서플로(TensorFlow), 케라스(Keras)

//-------------------------------------
* 최신 버전 설치

https://pytorch.org/get-started/locally/
    - conda 용
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

    - pip 용
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

//-------------------------------------

    - 이전 버전 설치 정보

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

//-------------------------------------
* 설치 확인

    - python 코드
python -c "import torch; print(torch.__version__, torch.cuda.is_available())"  

    - conda 용
conda list torch

    - pip 용
pip list | grep torch

//-------------------------------------
* 제거
    - conda 용
conda uninstall pytorch torchvision torchaudio pytorch-cuda

    - pip 용
pip uninstall torch torchvision torchaudio

//-------------------------------------
* pytorch 최신버전(v2.0) 강제 설치(업데이트)
    - 방법1 : pytorch 제거 후 설치 - conda

    - 방법2 :
    - conda 용 : 
주의! 'conda update pytorch torchvision torchaudio' 제대로 작동 안함

    - pip 용
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 --upgrade

//-----------------------------------------------------------------------------
* 이전 버전 설치
https://pytorch.org/get-started/previous-versions/

Domain Version Compatibility Matrix for PyTorch
https://github.com/pytorch/pytorch/wiki/PyTorch-Versions

//-------------------------------------
예) v1.13.1 , CUDA 11.7

    - conda 용
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia

    - pip 용
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117

//-----------------------------------------------------------------------------

< 참고 > conda vs pip

conda와 pip를 이용한 패키지 설치의 다른점

패키지 사용시 다른점은 없고

pip는 파이썬 패키지만을 설치할 수 있지만

conda는 파이썬 패키지와 python 자체, 운영체체에 필요한 라이브러리까지 설치할 수 있음

pip에서 conda와 같이 부가적인 라이브러리를 설치 하려면 pip wheel을 사용

 

https://pythonspeed.com/articles/conda-vs-pip/

 

 
pip
Conda

Installs Python
No
Yes, as package

3rd-party shared libraries
Inside the wheel
Yes, as package

Executables and tools
No
Yes, as package

Python source code
Yes, as package
Yes, as package

 //

알림