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,

相关推荐
石迹耿千秋7 小时前
迁移学习--基于torchvision中VGG16模型的实战
人工智能·pytorch·机器学习·迁移学习
LGGGGGQ14 小时前
嵌入式学习-PyTorch(7)-day23
人工智能·pytorch·学习
甄卷14 小时前
李沐动手学深度学习Pytorch-v2笔记【08线性回归+基础优化算法】2
pytorch·深度学习·算法
PyAIExplorer14 小时前
PyTorch 损失函数详解:从理论到实践
人工智能·pytorch·python
霖0018 小时前
神经网络项目--基于FPGA的AI简易项目(1-9图片数字识别)
人工智能·pytorch·深度学习·神经网络·机器学习·fpga开发
聚客AI19 小时前
💡大模型开发从入门到部署:3个月避开87%的新手雷区
人工智能·pytorch·llm
盼小辉丶20 小时前
PyTorch生成式人工智能(18)——循环神经网络详解与实现
pytorch·rnn·自然语言处理
胖达不服输2 天前
「日拱一码」027 深度学习库——PyTorch Geometric(PyG)
人工智能·pytorch·深度学习·pyg·深度学习库
笑小枫2 天前
Pytorch使用GPU训练全过程,包含安装CUDA、cuDNN、PyTorch
人工智能·pytorch·python
Mister Leon2 天前
Pytorch 使用报错 RuntimeError: Caught RuntimeError in DataLoader worker process 0.
人工智能·pytorch·python