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

PyTorch torch.cuda.seed function

PyTorch torch.cuda.seed function


PyTorch torch reference manual PyTorch torch reference manual

torch.cuda.seed is a PyTorch function for setting the CUDA random seed. It sets the random seed for the current CUDA device (same as manual_seed).

Function definition

torch.cuda.seed()


Usage examples

Example

import

torch

Set the CUDA random seed

if

torch.

cuda

.

is_available

(

)

:

    torch.

cuda

.

seed

(

)

    x

=

torch.

randn

(

3

,

3

)

.

cuda

(

)

   

print

(

f

"Random tensor on CUDA: {x}"

)

else

:

   

print

(

"CUDA not available"

)


PyTorch torch reference manual PyTorch torch reference manual