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,

相关推荐
AI即插即用2 天前
即插即用系列 | 2025 MambaNeXt-YOLO 炸裂登场!YOLO 激吻 Mamba,打造实时检测新霸主
人工智能·pytorch·深度学习·yolo·目标检测·计算机视觉·视觉检测
忘却的旋律dw2 天前
使用LLM模型的tokenizer报错AttributeError: ‘dict‘ object has no attribute ‘model_type‘
人工智能·pytorch·python
studytosky2 天前
深度学习理论与实战:MNIST 手写数字分类实战
人工智能·pytorch·python·深度学习·机器学习·分类·matplotlib
小女孩真可爱3 天前
大模型学习记录(五)-------调用大模型API接口
pytorch·深度学习·学习
Predestination王瀞潞3 天前
Windows环境下Pytorch的配置
人工智能·pytorch·python
夫唯不争,故无尤也3 天前
PyTorch 的维度变形一站式入门
人工智能·pytorch·python
nix.gnehc3 天前
PyTorch
人工智能·pytorch·python
z樾3 天前
TorchRL-MADDPG
pytorch·python·深度学习
夫唯不争,故无尤也4 天前
梯度累计原理:数学可行性与PyTorch实现
人工智能·pytorch·python
八年。。4 天前
Ai笔记(二)-PyTorch 中各类数据类型(numpy array、list、FloatTensor、LongTensor、Tensor)的区别
人工智能·pytorch·笔记