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, https://yongqiang.blog.csdn.net/

相关推荐
zhangfeng11339 小时前
超算/曙光DCU集群 昆山站 根目录文件夹逐项释义(HTC调度集群环境、国产DCU算力节点)
人工智能·pytorch·机器学习
zhangfeng113313 小时前
国家超算中心 htc 如果只有gpu资源 没有cpu资源 操作文件的时候会不会很卡呢
人工智能·pytorch·python·机器学习
zhangfeng113317 小时前
DeepSeek V4 适配华为昇腾950 难度及开源情况
人工智能·pytorch·python·机器学习·华为·开源
承渊政道19 小时前
【从零开始大模型开发与微调:基于PyTorch与ChatGLM】(新时代的曙光之大模型与人工智能)
人工智能·pytorch·python·深度学习·机器学习·语言模型·自然语言处理
lqjun08272 天前
PyTorch梯度计算
人工智能·pytorch·python
花落yu2 天前
【无标题】
pytorch·python·深度学习
扫地僧9852 天前
一个基于 PyTorch 手语翻译模型Xuanmen_Net
人工智能·pytorch·python
盼小辉丶2 天前
PyTorch深度学习实战(56)——在iOS上构建PyTorch应用
pytorch·深度学习·ios
心中有国也有家2 天前
GE图引擎深度解析——CANN的计算图优化与执行引擎
人工智能·pytorch·python·学习·numpy
瑶总迷弟2 天前
使用 mis-tei 在昇腾310P上部署 bge-m3模型
pytorch·python·华为·语言模型·自然语言处理·cnn·unix