메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

파이썬 gpu 정보

DB CAFE
Dbcafe (토론 | 기여)님의 2024년 10월 2일 (수) 01:03 판 (새 문서: = 파이썬에서 GPU 정보와 GPU 사용 유무 확인 = == 파이토치 이용 torch == * 파이토치 설치 확인 <source lang=python> pip install torch </source> <source lang=python> import torch print(torch.cuda.is_available()) print(torch.cuda.device_count()) print(torch.cuda.get_device_name(torch.cuda.current_device())) </source> === 파이토치 방법 2 === <source lang=python> from torch import cuda assert cuda.is_available() assert cuda.device_count() > 0 print(...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

파이썬에서 GPU 정보와 GPU 사용 유무 확인

파이토치 이용 torch

  • 파이토치 설치 확인
pip install torch
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.get_device_name(torch.cuda.current_device()))

파이토치 방법 2

from torch import cuda
assert cuda.is_available()
assert cuda.device_count() > 0
print(cuda.get_device_name(cuda.current_device()))

텐서플로우 이용 tensorflow

  • 텐서플로우 설치 확인
pip install tensorflow
import tensorflow as tf
tf.__version__

텐서플로우 방법 2 : 모든 사용 가능한 GPU List 보기

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

방법 3

tf.config.list_physical_devices('GPU')

방법 4

tf.config.experimental.list_physical_devices('GPU')

방법 5

tf.debugging.set_log_device_placement(True)
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)

방법 3 : 케라스 이용 confirm Keras sees the GPU

from keras import backend
assert len(backend.tensorflow_backend._get_available_gpus()) > 0

주로 사용하는 GPU 확인 조회 코드

import tensorflow as tf
from tensorflow.python.client import device_lib

device_lib.list_local_devices()
tf.config.list_physical_devices('GPU')

주로 사용하는 인식한 GPU 개수 출력 코드

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))