-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix seeding of new generator for multi GPU #3459
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
Fix seeding of new generator for multi GPU #3459
Conversation
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.
Nice catch, thanks!
Yes the same should be done there. Do you want to include it in this PR? |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Thanks for the quick check. Yes I will add it in this PR. I'll try to add a test as well. |
Done. |
The added test fails on main, passes on this branch. Not sure this covers the other line I just changed in the code. |
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.
Thanks for adding a test!
Thanks for the quick review! |
What does this PR do?
Fixes #3398
The initial state of the new generator was always the same, whatever the seed passed to
accelerate.utils.set_seed
. This PR makes sure that we get reproducible results but different numbers for different seeds passed toset_seed
. This is already the case when multi GPU is disabled because generator is None (see https://github.com/pytorch/pytorch/blob/main/torch/utils/data/sampler.py#L170).Before adding a test, I will wait for a first reviewer to confirm this is OK, I am not yet very familiar with accelerate.
Maybe the same should be done for https://github.com/huggingface/accelerate/blob/main/src/accelerate/data_loader.py#L1184 where the seed is set to 42 and thus will always produce the same number whatever the first global initial seed passed to
set_seed
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
Based on git blame I would say @muellerzr :)