现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.cuda.manual_seed_all 函数


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

torch.cuda.manual_seed_all 是 PyTorch 中用于设置所有 CUDA 设备随机种子的函数。为所有 CUDA 设备设置随机种子。

函数定义

torch.cuda.manual_seed_all(seed)

使用示例

实例

import torch

# 为所有 CUDA 设备设置随机种子
if torch.cuda.is_available():
    torch.cuda.manual_seed_all(42)
    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 参考手册 Pytorch torch 参考手册