Skip to content

Commit

Permalink
refactor: add some comments in pypots.utils.random;
Browse files Browse the repository at this point in the history
  • Loading branch information
WenjieDu committed May 24, 2024
1 parent bb46103 commit a405502
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pypots/utils/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
# Created by Wenjie Du <wenjay.du@gmail.com>
# License: BSD-3-Clause

import random

import numpy as np
import torch
import random

from .logging import logger

RANDOM_SEED = 2204
# Take the birth year of PyPOTS as the default random seed
RANDOM_SEED: int = 2022


def set_random_seed(random_seed: int = RANDOM_SEED) -> None:
Expand All @@ -23,11 +26,11 @@ def set_random_seed(random_seed: int = RANDOM_SEED) -> None:
"""
globals()["RANDOM_SEED"] = random_seed
random.seed(random_seed)
np.random.seed(random_seed)
torch.manual_seed(random_seed)
random.seed(random_seed)
torch.cuda.manual_seed_all(random_seed)
# torch.backends.cudnn.deterministic = True
# torch.backends.cudnn.deterministic = True # This will slow down the training process.
logger.info(f"Have set the random seed as {random_seed} for numpy and pytorch.")


Expand Down

0 comments on commit a405502

Please sign in to comment.