-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Seeding fixes, seed random, generate strong seed (#76)
Summary: Pull Request resolved: https://github.com/fairinternal/pythia-internal/pull/76 Reviewed By: vedanuj Differential Revision: D21105265 Pulled By: apsdehal fbshipit-source-id: 4f991a81a9614bf4ff2536fe7aff6dac7e2b341a
- Loading branch information
Showing
4 changed files
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import random | ||
from datetime import datetime | ||
|
||
import numpy as np | ||
import torch | ||
|
||
|
||
def set_seed(seed): | ||
if seed: | ||
if seed == -1: | ||
# From detectron2 | ||
seed = ( | ||
os.getpid() | ||
+ int(datetime.now().strftime("%S%f")) | ||
+ int.from_bytes(os.urandom(2), "big") | ||
) | ||
np.random.seed(seed) | ||
torch.manual_seed(seed) | ||
random.seed(seed) | ||
|
||
return seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters