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/

相关推荐
Wis4e16 分钟前
基于PyTorch的深度学习5——神经网络工具箱
pytorch·深度学习·神经网络
闲人编程22 分钟前
调试与性能优化技巧
人工智能·pytorch·深度学习
T0uken1 小时前
【深度学习】Pytorch:更换激活函数
人工智能·pytorch·深度学习
张琪杭1 小时前
pytorch tensor创建tensor
人工智能·pytorch·python
轻口味1 小时前
【每日学点HarmonyOS Next知识】状态栏控制、片段按钮点击回调、绘制组件、取消按钮与输入框对齐、父调子组件方法
pytorch·华为·harmonyos·harmonyosnext
Tianwen_Burning2 小时前
yolov5训练自己数据集的全流程+踩过的坑
pytorch·yolo
Wis4e4 小时前
基于PyTorch的深度学习3——非标量反向传播
人工智能·pytorch·深度学习
机器学习小小白5 小时前
【深入解析Inception网络:从V1到V3的理论演进与对比,包含pytorch实现Inception模块的代码】
pytorch·深度学习·神经网络·inception
Wis4e7 小时前
基于PyTorch的深度学习4——使用numpy实现机器学习vs使用Tensor及Antograd实现机器学习
pytorch·深度学习·机器学习
Wis4e16 小时前
基于PyTorch的深度学习3——基于autograd的反向传播
人工智能·pytorch·深度学习