Skip to content

fix: avoid int32 overflow in random seed generation#253

Open
rodriguescarson wants to merge 1 commit into
Stability-AI:mainfrom
rodriguescarson:fix/seed-int32-overflow
Open

fix: avoid int32 overflow in random seed generation#253
rodriguescarson wants to merge 1 commit into
Stability-AI:mainfrom
rodriguescarson:fix/seed-int32-overflow

Conversation

@rodriguescarson

Copy link
Copy Markdown

Fixes #195

Problem

Three call sites generate a random seed with:

seed = seed if seed != -1 else np.random.randint(0, 2**32 - 1)

np.random.randint uses numpy's default integer dtype, which is int32 on some platforms (notably Windows). The high bound 2**32 - 1 exceeds int32's max (2**31 - 1), so numpy raises:

ValueError: high is out of bounds for int32

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

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
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.

[BUG] Int32 Overflow Error in Random Seed Generation

1 participant