728x90

파이토치(PyTorch)에서 연산 장치 설정하기 (GPU, CPU)

들어가며

  • 파이토치(PyTorch)에서 연산 장치(GPU/CPU)를 설정하는 코드를 알아보자.

 

방법

  • GPU 사용이 가능한 경우 @torch.device@를 @cuda@를 설정하고, 그렇지 않을 경우 @cpu@를 연산 장치로 설정한다.
# GPU 설정 (사용 가능한 경우)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

print("device >>" , device)

 

728x90