Skip to content

fix: clamp PYTHONHASHSEED to the uint32 range in seed_everything - #1323

Merged
SWivid merged 2 commits into
SWivid:mainfrom
kyo-zzz:fix/hashseed-uint32
Oct 11, 2026
Merged

SWivid merged 2 commits into
SWivid:mainfrom
kyo-zzz:fix/hashseed-uint32

Conversation

@kyo-zzz

@kyo-zzz kyo-zzz commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #1322.

Problem

F5TTS.infer() with the default seed=None draws random.randint(0, sys.maxsize) — a 64-bit value — and seed_everything writes it verbatim into os.environ["PYTHONHASHSEED"]. CPython only accepts "random" or an integer in [0, 2**32 - 1] for that variable, so on every 64-bit platform the environment is polluted with an invalid value (~99.99999995% probability), and any child Python process inheriting it aborts at pre-initialization:

Fatal Python error: config_init_hash_seed: PYTHONHASHSEED must be "random" or an integer in range [0; 4294967295]

This bites users who spawn subprocesses after inference (batch drivers, job schedulers, notebook %run flows).

Fix

Reduce the environment value modulo 2**32 in seed_everything:

os.environ["PYTHONHASHSEED"] = str(seed % 2**32)

random.seed() and torch.manual_seed() keep the original seed, so reproducibility semantics are unchanged — only the environment variable is made legal. This also covers any other caller passing a large seed, and the finetune_gradio.py site is unaffected (its constant seed 666 is already valid).

Verification

Standalone reproduction against src/f5_tts/model/utils.py (before → after):

seed_everything(2**40 + 123)
PYTHONHASHSEED in env: 1099511627899        -> child: Fatal Python error: config_init_hash_seed
after fix: PYTHONHASHSEED in env: 123       -> child: ok

kyo-zzz and others added 2 commits October 11, 2026 00:50
seed_everything writes the seed into os.environ["PYTHONHASHSEED"], but
CPython only accepts "random" or an integer in [0, 2**32 - 1] there.
api.py draws the default seed with random.randint(0, sys.maxsize), which
is a 64-bit value, so on every 64-bit platform the environment ended up
with an invalid PYTHONHASHSEED and any child Python process inheriting it
aborted at pre-initialization with:

  Fatal Python error: config_init_hash_seed: PYTHONHASHSEED must be
  "random" or an integer in range [0; 4294967295]

Reduce the environment value modulo 2**32 (keeping random.seed and
torch.manual_seed on the original seed) so child processes survive.
Fixes SWivid#1322
@SWivid
SWivid merged commit d852486 into SWivid:main Oct 11, 2026
1 check passed
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: seed_everything sets 64-bit PYTHONHASHSEED exceeding uint32 limit, crashing child Python processes (Fatal Python error: config_init_hash_seed)

2 participants