1. Try
seed = 0 # any number you want
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
2. More strictly,
seed = 0 # any number you want
os.environ['PYTHONHASHSEED'] = str(seed)
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
#References
https://pytorch.org/docs/stable/notes/randomness.html
https://discuss.pytorch.org/t/random-seed-initialization/7854/17
https://discuss.pytorch.org/t/how-to-get-deterministic-behavior/18177/11
'LANGUAGE > PyTorch' 카테고리의 다른 글
BiLSTM (0) | 2019.08.01 |
---|---|
PyTorch Examples (0) | 2019.08.01 |
Difference between model.eval() and torch.no_grad() (0) | 2019.07.15 |
Hide/Disable TensorFlow Debugging Information (Message) (0) | 2019.07.12 |
How to use TensorBoard for PyTorch? (0) | 2019.07.12 |