-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Fix seeding random module in DataLoader #7886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Good find, but can we instead change the code on line 249? |
torch/utils/data/dataloader.py
Outdated
| self.sample_iter = iter(self.batch_sampler) | ||
|
|
||
| base_seed = torch.LongTensor(1).random_()[0] | ||
| base_seed = int(torch.LongTensor(1).random_()[0]) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
@pytorchbot retest this please |
|
Can we also add a test for this? |
ssnl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_distributed seems broken on master.
|
@pytorchbot retest this please |
1 similar comment
|
@pytorchbot retest this please |
* fix seeding random module * make base seed int * follow 0.4 idiom * add a test for random seeding
|
is this bug fixed? |
Fix #7882
The
randommodule is seeded here. The problem with that line is thatseedis not anintbut aTensor. Python then will usehash(seed)to seed the random module (docs). Without a hash function forTensor, the actually seed will be the address of the tensor. And it changes every time!The line should be changed to:
random.seed(int(seed))Test on fllowing script from #7882
Before
First run
Next run
After
First run
Next run