To check if PyTorch is using CUDA, run this code:

import torch

if torch.cuda.is_available():
    device = torch.device('cuda')          # a CUDA device object
    print(f'Using {torch.cuda.get_device_name(0)}')
else:
    device = torch.device('cpu')
    print('Using CPU')

This code checks if CUDA is available and prints the device name if it is. If CUDA is not available, it uses the CPU instead.


原文地址: https://www.cveoy.top/t/topic/oCHk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录