Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active October 22, 2021 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/d3dde9820b3c734c8b8ebc839a6a7e96 to your computer and use it in GitHub Desktop.
Save YiLi225/d3dde9820b3c734c8b8ebc839a6a7e96 to your computer and use it in GitHub Desktop.
### 6. Set random seed
def reset_random_seeds(CUR_SEED=1234):
os.environ['PYTHONHASHSEED']=str(CUR_SEED)
tensorflow.random.set_seed(CUR_SEED)
numpy.random.seed(CUR_SEED)
random.seed(CUR_SEED)
torch.manual_seed(CUR_SEED)
torch.cuda.manual_seed(CUR_SEED)
torch.cuda.manual_seed_all(CUR_SEED)
torch.backends.cudnn.deterministic = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment