Skip to content

Commit

Permalink
[#41] add set random seed helper
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondng76 committed Dec 10, 2021
1 parent a2b4701 commit 0333bab
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sgnlp/models/sentic_asgcn/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import argparse
import json
import random
import pathlib

import numpy as np
import torch

from .data_class import SenticASGCNTrainArgs


Expand All @@ -23,3 +27,17 @@ def parse_args_and_load_config(

sentic_asgcn_args = SenticASGCNTrainArgs(**cfg)
return sentic_asgcn_args


def set_random_seed(seed: int = 776) -> None:
"""Helper method to set random seeds for python, numpy and torch
Args:
seed (int, optional): seed value to set. Defaults to 776.
"""
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

0 comments on commit 0333bab

Please sign in to comment.