TUTORIALAI & dataFETCHED

PyTorch torch.is_available 函数

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

Updated 7/16/2026

Tutorial detail pages default to noindex.

PyTorch torch.is_available 函数


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

torch.is_available 是 PyTorch 中用于检查 CUDA 是否可用的函数。返回 True 表示 CUDA 可用,False 表示不可用。

函数定义

torch.is_available()

使用示例

实例

import torch

# 检查 CUDA 是否可用
if torch.is_available():
    print("CUDA is available!")
    print(f"CUDA device count: {torch.cuda.device_count()}")
else:
    print("CUDA is not available")

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