stable-baselines3/torchy_baselines/common/utils.py
Antonin Raffin 46d8d9725b Init: TD3
2019-09-05 17:29:41 +02:00

20 lines
416 B
Python

import random
import torch as th
import numpy as np
def set_random_seed(seed, using_cuda=False):
"""
Seed the different random generators
:param seed: (int)
:param using_cuda: (bool)
"""
random.seed(seed)
np.random.seed(seed)
th.manual_seed(seed)
if using_cuda:
# Make CuDNN Determinist
th.backends.cudnn.deterministic = True
th.cuda.manual_seed(seed)