PyTorch torch.cuda.manual_seed_all Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.cuda.manual_seed_allIt is a function in PyTorch used to set the random seed for all CUDA devices. Set the random seed for all CUDA devices.

Function Definition

torch.cuda.manual_seed_all(seed)

Usage Example

Example

import torch

# Set random seeds for all CUDA devices
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 Reference Manual

Other Extensions