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, intorch.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/