TUTORIALAI 与数据科学FETCHED
PyTorch torch.cuda.seed_all 函数
PyTorch torch.cuda.seed_all 函数 Pytorch torch 参考手册 torch.cuda.seed_all 是 PyTorch 中用于设置所有 CUDA 设备随机种子的函数。为所有 CUDA 设备设置随机种子(功能与 manual_seed_all 相同)。 函数定义 torch.cuda.seed_all() 使用示例 实例 [mycode4 type='python']..
更新于 2026/7/16
教程详情页默认 noindex。
PyTorch torch.cuda.seed_all 函数
torch.cuda.seed_all 是 PyTorch 中用于设置所有 CUDA 设备随机种子的函数。为所有 CUDA 设备设置随机种子(功能与 manual_seed_all 相同)。
函数定义
torch.cuda.seed_all()
使用示例
实例
import torch
# 为所有 CUDA 设备设置随机种子
if torch.cuda.is_available():
torch.cuda.seed_all()
x = torch.randn(3, 3).cuda()
print(f"Random tensor: {x}")
print(f"CUDA device count: {torch.cuda.device_count()}")
else:
print("CUDA not available")
# 为所有 CUDA 设备设置随机种子
if torch.cuda.is_available():
torch.cuda.seed_all()
x = torch.randn(3, 3).cuda()
print(f"Random tensor: {x}")
print(f"CUDA device count: {torch.cuda.device_count()}")
else:
print("CUDA not available")
Pytorch torch 参考手册