查看Pytorch是否使用GPU

下面的命令可以帮助我们查看Pytorch是否使用GPU

# 返回当前设备索引
torch.cuda.current_device()

  
  
    # 返回GPU的数量
    torch.cuda.device_count()
    
      
      
      # 返回gpu名字,设备索引默认从0开始
      torch.cuda.get_device_name(0)
      
        
        
        # cuda是否可用
        torch.cuda.is_available()
        
          
          

          我的结果是:

          [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Bj0dLYom-1609642835880)(C:\Users\Administrator\Desktop\查看pytorch是否使用GPU.png)]

          转载自:https://blog.csdn.net/weixin_43593330/article/details/112132428