PyTorch torch.cuda.is_available()

PyTorch torch.cuda.is_available{}

  • [1. `torch.cuda.is_available()`](#1. torch.cuda.is_available())
  • [2. `torch.cuda.is_available()`](#2. torch.cuda.is_available())
  • References

PyTorch documentation
https://pytorch.org/docs/master/index.html

PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.

  • torch.cuda.is_available (Python function, in torch.cuda.is_available)

1. torch.cuda.is_available()

https://pytorch.org/docs/stable/generated/torch.cuda.is_available.html

Return a bool indicating if CUDA is currently available.

Return type

bool

2. torch.cuda.is_available()

复制代码
import torch

device = 'cuda' if torch.cuda.is_available() else 'cpu'  # examples: 'cpu', 'cuda', 'cuda:0', 'cuda:1', etc.
device_type = 'cuda' if 'cuda' in device else 'cpu'  # for later use in torch.autocast

print("device =", device)
print("device_type =", device_type)

/home/yongqiang/miniconda3/bin/python /home/yongqiang/llm_work/llama2.c/yongqiang.py 
device = cpu
device_type = cpu

Process finished with exit code 0

References

1\] Yongqiang Cheng,

相关推荐
晓枫-迷麟4 小时前
【使用conda】安装pytorch
人工智能·pytorch·conda
爱补鱼的猫猫5 小时前
Pytorch知识点2
人工智能·pytorch·python
deephub5 小时前
提升模型泛化能力:PyTorch的L1、L2、ElasticNet正则化技术深度解析与代码实现
人工智能·pytorch·python·深度学习·机器学习·正则化
Cl_rown去掉l变成C7 小时前
第J3-1周:DenseNet算法 实现乳腺癌识别
人工智能·pytorch·算法
Vertira9 小时前
Pytorch安装后 如何快速查看经典的网络模型.py文件(例如Alexnet,VGG)(已解决)
人工智能·pytorch·python
DX_dove10 小时前
pytorch3d+pytorch1.10+MinkowskiEngine安装
人工智能·pytorch·python
点云SLAM11 小时前
PyTorch中matmul函数使用详解和示例代码
人工智能·pytorch·python·深度学习·计算机视觉·矩阵乘法·3d深度学习
MYH51612 小时前
sklearn 和 pytorch tensorflow什么关系
pytorch·tensorflow·sklearn
YYXZZ。。14 小时前
PyTorch——非线性激活(5)
人工智能·pytorch·python
QQ676580081 天前
基于 PyTorch 的 VGG16 深度学习人脸识别检测系统的实现+ui界面
人工智能·pytorch·python·深度学习·ui·人脸识别