fix: avoid int32 overflow in random seed generation#253
Open
rodriguescarson wants to merge 1 commit into
Open
Conversation
np.random.randint(0, 2**32 - 1) uses numpy's default integer dtype, which is int32 on some platforms (notably Windows). The high bound 2**32 - 1 exceeds int32's max, so numpy raises 'ValueError: high is out of bounds for int32' on every seed=-1 (auto-seed) generation. Line 36 already fixes this with dtype=np.uint32; apply the same fix to the two remaining occurrences (lines 198 and 468). Fixes Stability-AI#195
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.
Fixes #195
Problem
Three call sites generate a random seed with:
np.random.randintuses numpy's default integer dtype, which is int32 on some platforms (notably Windows). The high bound2**32 - 1exceeds int32's max (2**31 - 1), so numpy raises:on every auto-seed (
seed == -1) generation.Fix
Line 36 already handles this correctly with
dtype=np.uint32. This applies the maintainers' own fix to the two remaining occurrences (lines 198 and 468), so all three seed sites are consistent.Verifiable by inspection — mirrors the existing fix on line 36.
🤖 Generated with Claude Code