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, https://yongqiang.blog.csdn.net/

相关推荐
培之13 小时前
RTX 5090 安装 pytorch3d
人工智能·pytorch·python
延卿13 小时前
nnDetection:基于 PyTorch 的目标检测框架
人工智能·pytorch·目标检测
不懒不懒15 小时前
Windows 深度学习环境配置(CUDA12.8 + cuDNN9.x + PyTorch)最简避坑指南(2026 最新)
人工智能·pytorch·深度学习
丨白色风车丨15 小时前
PyTorch 迁移学习实战:ResNet18 实现 20 类食物图像分类(完整可运行代码)
pytorch·分类·迁移学习
七夜zippoe16 小时前
深入解析CANN仓库中的HCCL分布式通信库
pytorch·分布式·cann·hccl·通信库
All The Way North-18 小时前
【TorchMetrics精通系列③】模型评估进阶:ClasswiseWrapper 实战与多分类细粒度指标深度解析
pytorch·模型评估·分类指标·包装器·评估指标·torchmetrics
不如语冰2 天前
AI大模型入门-模块导入import
数据结构·人工智能·pytorch·python
FriendshipT2 天前
Ultralytics:解读CBLinear模块
人工智能·pytorch·python·深度学习·目标检测
不如语冰2 天前
AI大模型入门-参数的传递
数据结构·人工智能·pytorch·python
m沐沐2 天前
【深度学习】深入理解长短期记忆网络 LSTM
人工智能·pytorch·深度学习·神经网络·lstm