镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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

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
fred-dev added a commit to fred-dev/stable-audio-tools that referenced this pull request Oct 21, 2026
- gradio 6.3.0 -> 6.16.0 (upstream PR Stability-AI#270); lock also updates gradio-client,
  starlette and adds hf-gradio
- generation.py: np.random.randint(0, 2**32 - 1) overflows int32 on Windows when
  seed is -1; use dtype=np.uint32 as line 36 already does (upstream PR Stability-AI#253)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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