본문 바로가기
Development/Python

[Python] Pytorch 설치 && 설치 후 GPU Test

by 성딱이 2021. 10. 13.
반응형

 

사전 준비 : OS, CUDA Version

 

 

1. 파이토치 공식 홈페이지에서 구성요소를 선택 후, Run this Command에 뜬 shell 명령어가 확인

 

2. shell command 입력 (가상환경 있다면 활성화 후)

$ pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

 

 

3. GPU 잘 붙는지 확인 (파이썬 실행 후)

import torch

torch.cuda.is_available()
>>> True

torch.cuda.current_device()
>>> 0

torch.cuda.device(0)
>>> <torch.cuda.device at 0x7efce0b03be0>

torch.cuda.device_count()
>>> 1

torch.cuda.get_device_name(0)
>>> 'GeForce GTX 950M'

 

 

 

출처 1 : 파이토치 공식 홈페이지 

출처 2 : https://stackoverflow.com/questions/48152674/how-to-check-if-pytorch-is-using-the-gpu

 

How to check if pytorch is using the GPU?

I would like to know if pytorch is using my GPU. It's possible to detect with nvidia-smi if there is any activity from the GPU during the process, but I want something written in a python script. Is

stackoverflow.com

 

반응형

댓글