PyTorch torch.cuda.seed_all Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.cuda.seed_allIt is a function in PyTorch used to set the random seed for all CUDA devices. Sets the random seed for all CUDA devices (functionally identical to manual_seed_all).

Function Definition

torch.cuda.seed_all()

Usage Example

Example

import torch

# Set the random seed for all CUDA devices
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 参考手册Pytorch torch Reference Manual

Other Extensions