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,

相关推荐
Victory_orsh18 小时前
“自然搞懂”深度学习(基于Pytorch架构)——010203
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
Geoking.20 小时前
PyTorch 中 model.eval() 的使用与作用详解
人工智能·pytorch·python
nn在炼金20 小时前
图模式分析:PyTorch Compile组件解析
人工智能·pytorch·python
执笔论英雄20 小时前
【大模型训练】zero2 梯度分片
pytorch·python·深度学习
化作星辰1 天前
深度学习_原理和进阶_PyTorch入门(2)后续语法2
pytorch·深度学习·学习
机器学习ing.2 天前
U-Net保姆级教程:从原理到医学细胞分割实战(PyTorch版)!
人工智能·pytorch·python·深度学习·机器学习
Dev7z2 天前
基于ResNet50和PyTorch的猫狗图像分类系统设计与实现
人工智能·pytorch·分类
天地之于壹炁兮2 天前
PyTorch:AI时代的深度学习利器
pytorch
Francek Chen2 天前
【自然语言处理】预训练04:预训练word2vec
人工智能·pytorch·深度学习·自然语言处理·word2vec
skywalk81632 天前
老显卡老cpu用vllm推理大模型失败Intel(R) Xeon(R) CPU E5-2643 v2
人工智能·pytorch·python·vllm