Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.cuda.manual_seed_all function

PyTorch torch.cuda.manual_seed_all function


PyTorch torch reference manual PyTorch torch reference manual

torch.cuda.manual_seed_all is a PyTorch function for setting random seeds for all CUDA devices. It sets the random seed for every CUDA device.

Function definition

torch.cuda.manual_seed_all(seed)


Usage examples

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 reference manual PyTorch torch reference manual