[컴][머신러닝] PyTorch 설치

파이토치 / 텐서플로우 / tensor / flow / 설치 방법

PyTorch 설치

CUDA 설치

CUDA 설치 를 참고하자

version 확인:

D:\>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

PyTorch 설치

여기선 virtualenv 를 만들어서 설치했다.

D:\diffusion>virtualenv env

주의할 점은 자신의 cuda version 이 11.8 이라해도, pytorch 의 cuda 버전은 11.6을 택해야 한다. 11.8에 대한 경로가 없어서, cuda 가 없는 경우에 대한 pytorch 를 설치하게 된다.

설치

D:\diffusion>.\env\Scripts\activate.bat
(env) D:\diffusion>pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu116
Collecting torch
  Downloading https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp39-cp39-win_amd64.whl (2388.0 MB)
     ---------------------------------------- 2.4/2.4 GB 877.5 kB/s eta 0:00:00
Collecting torchvision
  Downloading https://download.pytorch.org/whl/cu116/torchvision-0.13.1%2Bcu116-cp39-cp39-win_amd64.whl (2.6 MB)
     ---------------------------------------- 2.6/2.6 MB 9.6 MB/s eta 0:00:00
Collecting torchaudio
  Downloading https://download.pytorch.org/whl/cu116/torchaudio-0.12.1%2Bcu116-cp39-cp39-win_amd64.whl (1.2 MB)
     ---------------------------------------- 1.2/1.2 MB 10.9 MB/s eta 0:00:00
Collecting typing-extensions
  Using cached typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Collecting requests
  Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting pillow!=8.3.*,>=5.3.0
  Using cached Pillow-9.2.0-cp39-cp39-win_amd64.whl (3.3 MB)
Collecting numpy
  Using cached numpy-1.23.3-cp39-cp39-win_amd64.whl (14.7 MB)
Collecting charset-normalizer<3,>=2
  Using cached charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2022.9.24-py3-none-any.whl (161 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
Installing collected packages: urllib3, typing-extensions, pillow, numpy, idna, charset-normalizer, certifi, torch, requests, torchvision, torchaudio
Successfully installed certifi-2022.9.24 charset-normalizer-2.1.1 idna-3.4 numpy-1.23.3 pillow-9.2.0 requests-2.28.1 torch-1.12.1+cu116 torchaudio-0.12.1+cu116 torchvision-0.13.1+cu116 typing-extensions-4.4.0 urllib3-1.26.12

CUDA 를 사용안하는 PyTorch 가 설치된 경우

D:\diffusion>.\env\Scripts\activate.bat
(env) D:\diffusion>pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
Collecting torch
  Downloading torch-1.12.1-cp39-cp39-win_amd64.whl (161.8 MB)
     ---------------------------------------- 161.8/161.8 MB 2.7 MB/s eta 0:00:00
Collecting torchvision
  Downloading torchvision-0.13.1-cp39-cp39-win_amd64.whl (1.1 MB)
     ---------------------------------------- 1.1/1.1 MB 13.5 MB/s eta 0:00:00
Collecting torchaudio
  Downloading torchaudio-0.12.1-cp39-cp39-win_amd64.whl (969 kB)
     ---------------------------------------- 969.6/969.6 kB 10.2 MB/s eta 0:00:00
Collecting typing-extensions
  Downloading typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Collecting numpy
  Downloading numpy-1.23.3-cp39-cp39-win_amd64.whl (14.7 MB)
     ---------------------------------------- 14.7/14.7 MB 6.5 MB/s eta 0:00:00
Collecting pillow!=8.3.*,>=5.3.0
  Downloading Pillow-9.2.0-cp39-cp39-win_amd64.whl (3.3 MB)
     ---------------------------------------- 3.3/3.3 MB 11.6 MB/s eta 0:00:00
Collecting requests
  Downloading requests-2.28.1-py3-none-any.whl (62 kB)
     ---------------------------------------- 62.8/62.8 kB ? eta 0:00:00
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
     ---------------------------------------- 140.4/140.4 kB 8.1 MB/s eta 0:00:00
Collecting idna<4,>=2.5
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ---------------------------------------- 61.5/61.5 kB ? eta 0:00:00
Collecting certifi>=2017.4.17
  Downloading certifi-2022.9.24-py3-none-any.whl (161 kB)
     ---------------------------------------- 161.1/161.1 kB 9.4 MB/s eta 0:00:00
Collecting charset-normalizer<3,>=2
  Downloading charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Installing collected packages: urllib3, typing-extensions, pillow, numpy, idna, charset-normalizer, certifi, torch, requests, torchvision, torchaudio
Successfully installed certifi-2022.9.24 charset-normalizer-2.1.1 idna-3.4 numpy-1.23.3 pillow-9.2.0 requests-2.28.1 torch-1.12.1 torchaudio-0.12.1 torchvision-0.13.1 typing-extensions-4.4.0 urllib3-1.26.12

설치 확인

(env) D:\diffusion>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5,3)
>>> print(x)
tensor([[0.7964, 0.4330, 0.9297],
        [0.1587, 0.6058, 0.9949],
        [0.9037, 0.8595, 0.1423],
        [0.1058, 0.2947, 0.9277],
        [0.1316, 0.2070, 0.1998]])
>>> torch.cuda.is_available()
False
>>>

댓글 없음:

댓글 쓰기