TUTORIALAI 与数据科学FETCHED

PyTorch torch.cuda.is_available 函数

PyTorch torch.cuda.is_available 函数 Pytorch torch 参考手册 torch.cuda.is_available 是 PyTorch 中用于检查 CUDA 是否可用的函数。 函数定义 torch.cuda.is_available() 使用示例 实例 [mycode4 type='python'] import torch # 检查 CUDA 是否可用 ..

更新于 2026/7/16

教程详情页默认 noindex。

PyTorch torch.cuda.is_available 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.cuda.is_available 是 PyTorch 中用于检查 CUDA 是否可用的函数。

函数定义

torch.cuda.is_available()

使用示例

实例

import torch

# 检查 CUDA 是否可用
if torch.cuda.is_available():
    print("CUDA 可用!")
    print("GPU 数量:", torch.cuda.device_count())
    print("GPU 名称:", torch.cuda.get_device_name(0))
else:
    print("CUDA 不可用")

Pytorch torch 参考手册 Pytorch torch 参考手册