PyTorch torch.cuda.manual_seed function
PyTorch torch reference manual
torch.cuda.manual_seed is a PyTorch function for setting the CUDA random seed. It sets the random seed for the current CUDA device to ensure reproducible CUDA operations.
Function definition
torch.cuda.manual_seed(seed)
Usage examples
Example
import
torch
Set the CUDA random seed
if
torch.
cuda
.
is_available
(
)
:
torch.
cuda
.
manual_seed
(
42
)
x
=
torch.
randn
(
3
,
3
)
.
cuda
(
)
(
f
"Random tensor on CUDA: {x}"
)
The same seed produces the same results
torch.
cuda
.
manual_seed
(
42
)
y
=
torch.
randn
(
3
,
3
)
.
cuda
(
)
(
f
"Random tensor with same seed: {y}"
)
else
:
(
"CUDA not available"
)