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,

相关推荐
深耕AI1 天前
【PyTorch训练】准确率计算(代码片段拆解)
人工智能·pytorch·python
nuczzz1 天前
pytorch非线性回归
人工智能·pytorch·机器学习·ai
~-~%%1 天前
Moe机制与pytorch实现
人工智能·pytorch·python
Garfield20051 天前
绕过 FlashAttention-2 限制:在 Turing 架构上使用 PyTorch 实现 FlashAttention
pytorch·flashattention·turing·图灵架构·t4·2080ti
深耕AI1 天前
【PyTorch训练】为什么要有 loss.backward() 和 optimizer.step()?
人工智能·pytorch·python
七芒星20231 天前
ResNet(详细易懂解释):残差网络的革命性突破
人工智能·pytorch·深度学习·神经网络·学习·cnn
九年义务漏网鲨鱼2 天前
【Debug日志 | DDP 下 BatchNorm 统计失真】
pytorch
☼←安于亥时→❦2 天前
PyTorch 梯度与微积分
人工智能·pytorch·python
缘友一世2 天前
PyTorch深度学习实战【10】之神经网络的损失函数
pytorch·深度学习·神经网络
深耕AI2 天前
【参数详解与使用指南】PyTorch MNIST数据集加载
人工智能·pytorch·python