# 检查gpu是否可用
if torch.cuda.is_available():
device = torch.device("cuda:0")
else:
device = torch.device("cpu")
# 创建tensor
print(torch.cuda.device_count())
data = torch.rand(3, 3, device=device)
# 检查gpu是否可用
if torch.cuda.is_available():
device = torch.device("cuda:0")
else:
device = torch.device("cpu")
# 创建tensor
print(torch.cuda.device_count())
data = torch.rand(3, 3, device=device)