TUTORIALAI & dataFETCHED
PyTorch torch.cuda.seed 函数
PyTorch torch.cuda.seed 函数 Pytorch torch 参考手册 torch.cuda.seed 是 PyTorch 中用于设置 CUDA 随机种子的函数。为当前 CUDA 设备设置随机种子(功能与 manual_seed 相同)。 函数定义 torch.cuda.seed() 使用示例 实例 [mycode4 type='python'] import torch # 设置 ..
Updated 7/16/2026
Tutorial detail pages default to noindex.
PyTorch torch.cuda.seed 函数
torch.cuda.seed 是 PyTorch 中用于设置 CUDA 随机种子的函数。为当前 CUDA 设备设置随机种子(功能与 manual_seed 相同)。
函数定义
torch.cuda.seed()
使用示例
实例
import torch
# 设置 CUDA 随机种子
if torch.cuda.is_available():
torch.cuda.seed()
x = torch.randn(3, 3).cuda()
print(f"Random tensor on CUDA: {x}")
else:
print("CUDA not available")
# 设置 CUDA 随机种子
if torch.cuda.is_available():
torch.cuda.seed()
x = torch.randn(3, 3).cuda()
print(f"Random tensor on CUDA: {x}")
else:
print("CUDA not available")
Pytorch torch 参考手册