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,

相关推荐
小陈99cyh2 小时前
安装NVIDIA Container Toolkit,让gpu容器环境跑通
运维·pytorch·docker·nvidia
Yuanxl9033 小时前
PyTorch模型训练全流程详解
人工智能·pytorch·深度学习
独隅3 小时前
PyTorch模型转TensorFlow Lite的Android部署全流程指南
android·pytorch·tensorflow
橘子编程4 小时前
PyTorch深度学习全栈指南
人工智能·pytorch·深度学习
郝学胜-神的一滴4 小时前
深度学习入门:极简神经网络搭建与参数计算全攻略
人工智能·pytorch·python·深度学习·神经网络·机器学习
重生之我要成为代码大佬4 小时前
pytorch与视觉检测
人工智能·pytorch·深度学习·大模型·视觉检测
Yuanxl9035 小时前
网络模型的保存和读取
人工智能·pytorch·深度学习
<-->14 小时前
Megatron(全称 Megatron-LM,由 NVIDIA 开发)和 DeepSpeed(由 Microsoft 开发)
人工智能·pytorch·python·深度学习·transformer
学弟17 小时前
【内涵】深度学习中的三种变量及pytorch中对应的三种tensor
人工智能·pytorch·python
Yuanxl9031 天前
Torchvision 0.26:深度学习视觉库全面解析
网络·人工智能·pytorch·深度学习