8000 Fix seeding of new generator for multi GPU by albertcthomas · Pull Request #3459 · huggingface/accelerate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Mar 28, 2025

Conversation

albertcthomas
Copy link
Contributor
@albertcthomas albertcthomas commented Mar 26, 2025

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 to set_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

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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 :)

Copy link
Contributor
@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

@muellerzr
Copy link
Contributor

Yes the same should be done there. Do you want to include it in this PR?

@HuggingFaceDocBuilderDev

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.

@albertcthomas
Copy link
Contributor Author

Yes the same should be done there. Do you want to include it in this PR?

Thanks for the quick check. Yes I will add it in this PR. I'll try to add a test as well.

@albertcthomas
Copy link
Contributor Author

Yes I will add it in this PR. I'll try to add a test as well.

Done.

@albertcthomas
Copy link
Contributor Author
albertcthomas commented Mar 27, 2025

The added test fails on main, passes on this branch. Not sure this covers the other line I just changed in the code.

Copy link
Contributor
@muellerzr muellerzr left a 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!

@muellerzr muellerzr merged commit 3f636d6 into huggingface:main Mar 28, 2025
25 checks passed
@albertcthomas
Copy link
Contributor Author

Thanks for the quick review!

@albertcthomas albertcthomas deleted the fix_different_seeds branch March 31, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomization with seed not working
3 participants
0