fix: use a stable seed in the PyTorch integration - #3072
Open
marcus-campbell wants to merge 1 commit into
Open
Conversation
Replace process-randomized string hashes with a fixed seed so the deterministic-behavior example remains reproducible across Python processes.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The PyTorch integration page says this setup ensures deterministic behavior, but it doesn't appear to actually do that. This is because it derives its seeds from
hash("..."). By default, Python randomizes string hashes between interpreter processes, so the example can initialize its RNGs differently across runs.This fix replaces the hash-derived values with one named integer seed.
Before:
After:
Why this matters
A small exploratory search found the same recognizable recipe in at least 24 other repositories. This suggests that the pattern has propagated beyond W&B's own docs, so correcting the bug here can help prevent it from spreading further.
The problem was also noted in the technical-review notes for #2673, but it wasn't fixed as it was out-of-scope for that PR (it was a style guide pass).
The corresponding notebooks are updated in wandb/examples#644.
Testing
git diff --checksucceeds.PYTHONHASHSEED.