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/

相关推荐
承渊政道6 小时前
【从零开始大模型开发与微调:基于PyTorch与ChatGLM】(从ChatGLM本地化到LoRA、PEFT的高级微调)
android·人工智能·pytorch·chatglm·本地化部署·大模型开发与微调
Smoothcloud润云8 小时前
GPU算力平台推荐:新手租GPU时,镜像环境和显存应该怎么选?
大数据·人工智能·pytorch·分布式·深度学习·gpu算力
田里的水稻1 天前
PyTorch_TensorBoard展示
人工智能·pytorch·python·深度学习·神经网络
想七想八不如114081 天前
元学习简单入门
人工智能·pytorch·python·深度学习·学习·机器学习
田里的水稻1 天前
PyTorch_torchvision---数据集下载\TensorBoard可视化
人工智能·pytorch·python·深度学习·机器学习
智恒百亿1 天前
5090 八卡服务器踩坑实录:架构、多卡通信、PyTorch Distributed 一次说清楚
服务器·pytorch·架构
田里的水稻2 天前
PyTorch-Dataset\DataLoader数据加载
人工智能·pytorch·python
智码看视界2 天前
深度学习:环境搭建PyTorch vs TensorFlow 选型
pytorch·深度学习·tensorflow·gpu·环境搭建·cuda·框架选型
论文复现现场2 天前
InfiniteTalk 需要多少显存?RTX 3090 24GB 单卡如何验证 480P、排查 OOM
pytorch·模型部署·ai视频生成·显存优化·infinitetalk·rtx3090·cuda oom
Zip-List2 天前
工作小记-pytorch的算子优化: 转gpu核函数 python调c
c语言·c++·pytorch·python·cuda