Skip to content

Conversation

@SkafteNicki
Copy link
Collaborator

@SkafteNicki SkafteNicki commented Dec 1, 2025

What does this PR do?

Fixes #20412
Currently the _generate_seed_sequence function does not produce unique seeds. The reason for this is that small base seeds (e.g. 0-999) after left-shifting by 32 bits have all zeros in the lower 32 bits. The LCG algorithm currently being used with c=1, then produces seeds that all have lower_32_bits=1 which in turn causes torch.manual_seed() to treat them identically since Pytorch primarily uses the lower bits.

Implements a simple hash mixing that ensures even small seeds produce well-distributed bit patterns across the full 64-bit space, preventing the current seed collision we are seeing.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--21399.org.readthedocs.build/en/21399/

@SkafteNicki SkafteNicki added the bug Something isn't working label Dec 1, 2025
@github-actions github-actions bot added the fabric lightning.fabric.Fabric label Dec 1, 2025
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (79ffe50) to head (d451eca).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21399   +/-   ##
=======================================
- Coverage      87%      87%   -0%     
=======================================
  Files         269      269           
  Lines       23804    23809    +5     
=======================================
+ Hits        20626    20628    +2     
- Misses       3178     3181    +3     

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package

Projects

None yet

1 participant