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,

相关推荐
Nina_71721 小时前
pytorch核心组件以及流程
人工智能·pytorch·python
知行力2 天前
【GitHub每日速递 20251111】PyTorch:GPU加速、动态网络,深度学习平台的不二之选!
pytorch·深度学习·github
love530love2 天前
【笔记】xFormers版本与PyTorch、CUDA对应关系及正确安装方法详解
人工智能·pytorch·windows·笔记·python·深度学习·xformers
为你写首诗ge2 天前
【python】python安装使用pytorch库环境配置
pytorch·python
Danceful_YJ2 天前
30.注意力汇聚:Nadaraya-Watson 核回归
pytorch·python·深度学习
wa的一声哭了2 天前
hf中transformers库中generate的greedy_search
android·java·javascript·pytorch·深度学习·语言模型·transformer
Danceful_YJ2 天前
36.优化方法
人工智能·pytorch·python·深度学习·优化器算法
大连好光景2 天前
LSTM模型做分类任务2(PyTorch实现)
人工智能·pytorch·lstm
Sanlings2 天前
ComfyUI+RX5700XT+Ubuntu25.04运行配置
pytorch·ai·comfyui·amd·rocm·rx5700xt·ubuntu25.04
Danceful_YJ3 天前
31.注意力评分函数
pytorch·python·深度学习