Skip to content

Commit

Permalink
add protocols for other users and add a seed fixing util
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongyw12382 committed Sep 7, 2021
1 parent f60f07c commit fdaf884
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Util Collections
# Utils Collection

## Motivation
When we implement codes, we often search for util functions that are already implemented.
Expand All @@ -8,6 +8,23 @@ Here, we are going to share util functions that are often used by others.
- You should provide a code in folder and short description about the code.
- Never push on master. We have prohibited direct push on main branch. Use pull request to avoid confusion.
- After adding an util function, add an item in the list below.
- Please refer to other formats.
- It is not necessary to be a python code. Feel free to add util functions.
- We strongly recommend to add the description as the following format:

Example
```
Author: YoonwooJeong
Description: Example for Addition
Input (Optional):
torch.Tensor a : the first number to add
torch.Tensor b : the second number to add
Output (Optional):
torch.Tensor out: the addition of "a" and "b".
Requirements (Optional):
numpy >= 0.0.1, torch >= 0.0.1
```

## Util Functions
- Fixing the seed
- Fixing the seed (torch_function/fix_seed.py)
- A function to completely fix the seeds of torch, numpy, and random.
7 changes: 7 additions & 0 deletions description_format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Author:
Description:
Input (Optional):
Output (Optional):
Requirements (Optional)
"""
23 changes: 23 additions & 0 deletions torch_function/fix_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
import torch
import random
"""
Author: Boseung Jeong and Yoonwoo Jeong
Description: Fixing the seed. When deterministic is true, the seed is
completely fixed, but the speed of programs might be slower.
Input (Optional):
int seed : seed to fix
bool deterministic: fix the torch.backends.cudnn.deterministic
Output (Optional): None
Requirements (Optional):
numpy, torch, random
"""
def fix_seed(seed, deterministic=True):
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed) # if use multi-GPU
torch.backends.cudnn.deterministic = deterministic
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)

0 comments on commit fdaf884

Please sign in to comment.