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,

相关推荐
hxxjxw18 小时前
Pytorch分布式训练/多卡训练(六) —— Expert Parallelism (MoE的特殊策略)
人工智能·pytorch·python
Sherlock Ma1 天前
AI大模型面试题集锦:(1)基础入门题
人工智能·pytorch·自然语言处理·大模型·跳槽·机器翻译·改行学it
这张生成的图像能检测吗1 天前
Wonder3D: 跨域扩散的单图像3D重建技术
pytorch·深度学习·机器学习·计算机视觉·3d·三维重建·扩散模型
小孟的CDN1 天前
使用pytorch进行batch_size分批训练,并使用adam+lbfgs算法——波士顿房价预测
pytorch·算法·batch·代码·adam+lbfgs
爱ZW的小白猿1 天前
【pytorch】tensorboard的使用
pytorch
淮北4941 天前
图神经网络与pytorch
人工智能·pytorch·神经网络
爱ZW的小白猿1 天前
【pytorch】transform的使用
pytorch
laocooon5238578861 天前
TensorFlow与 PyTorch有什么关联么
人工智能·pytorch·tensorflow
盼小辉丶1 天前
生成模型实战 | 残差流(Residual Flow)详解与实现
pytorch·深度学习·生成模型
IT老兵20252 天前
PyTorch DDP多GPU训练实践问题总结
人工智能·pytorch·python·分布式训练·ddp