TUTORIALAI 与数据科学FETCHED

PyTorch torch.cuda.manual_seed_all 函数

PyTorch torch.cuda.manual_seed_all 函数 Pytorch torch 参考手册 torch.cuda.manual_seed_all 是 PyTorch 中用于设置所有 CUDA 设备随机种子的函数。为所有 CUDA 设备设置随机种子。 函数定义 torch.cuda.manual_seed_all(seed) 使用示例 实例 [mycode4 type='python'..

更新于 2026/7/16

教程详情页默认 noindex。

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 参考手册