Skip to content
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

Allow for ACCELERATE_SEED env var #2126

Merged
merged 7 commits into from
Nov 7, 2023
Merged

Allow for ACCELERATE_SEED env var #2126

merged 7 commits into from
Nov 7, 2023

Conversation

muellerzr
Copy link
Collaborator

What does this PR do?

This PR introduces ACCELERATE_SEED as part of set_seed. Doing so will allow for the custom random samplers to rely on it for setting the seed, rather than the generator (as this can lead to imperfect issues). Solves related trainer test failures.

Fixes # (issue)

Internal slack thread

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.

@LysandreJik @BenjaminBossan

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 6, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Implementation-wise, this looks good to me. I think the documentation could be improved, LMK if you agree.

docs/source/package_reference/utilities.md Outdated Show resolved Hide resolved
docs/source/package_reference/utilities.md Show resolved Hide resolved
@@ -30,7 +31,8 @@

def set_seed(seed: int, device_specific: bool = False):
"""
Helper function for reproducible behavior to set the seed in `random`, `numpy`, `torch`.
Helper function for reproducible behavior to set the seed in `random`, `numpy`, `torch`. Also will set the random
seed for `SeedableRandomSampler` through the `ACCELERATE_SEED` environment variable.
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment to the one above: Users don't really care about SeedableRandomSampler, as this is an implementation detail of accelerate. They will care more about knowing when this function needs to be used.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Nice and simple. So in the end, users should call set_seed to ensure reproducibility and that's enough, right?

@muellerzr
Copy link
Collaborator Author

@BenjaminBossan yep! set_seed, and in the Trainer just having it set the torch seed will be enough for general users

@muellerzr muellerzr merged commit 183c9dd into main Nov 7, 2023
26 checks passed
@muellerzr muellerzr deleted the fix-repr-bug branch November 7, 2023 17:05
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.

None yet

3 participants