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,

相关推荐
隔壁大炮9 小时前
Day06-08.CNN概述介绍
人工智能·pytorch·深度学习·算法·计算机视觉·cnn·numpy
QiZhang | UESTC10 小时前
从基础 RoPE 到 YaRN:源码学习路线揭秘
pytorch·深度学习·学习
光之后裔12 小时前
Numpy以及Pytorch中多维数组的维度数与维度值以及轴axis理解
pytorch·python·numpy
Jmayday13 小时前
Pytorch:神经网络基础
人工智能·pytorch·神经网络
Cho1yon15 小时前
【AI Agent 第十期:基于 scrcpy + PyTorch 的车载系统多屏自动化测试工具开发】
人工智能·pytorch·ui·车载系统·自动化
蓝博AI17 小时前
基于深度学习的蔬菜识别系统,resnet50,vgg16,resnet34【pytorch框架,python代码】
人工智能·pytorch·python·深度学习·机器学习·cnn
努力学习_小白17 小时前
DenseNet——Pytorch学习记录
人工智能·pytorch·机器学习·densenet
用户990193052451 天前
Nano-vLLM-MS:基于 nano-vLLM ,支持 MoE 模型和 Speculative Decoding
pytorch·llm
eqwaak02 天前
PyTorch入门:10分钟搭建首个神经网络
开发语言·人工智能·pytorch·python
IRevers2 天前
【Agent】基于Langchain的Agent数据库查询助手
数据库·人工智能·pytorch·sql·深度学习·langchain·agent