Repository navigation
fix: clamp PYTHONHASHSEED to the uint32 range in seed_everything - #1323
Merged
Merged
Conversation
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
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 #1322.
Problem
F5TTS.infer()with the defaultseed=Nonedrawsrandom.randint(0, sys.maxsize)— a 64-bit value — andseed_everythingwrites it verbatim intoos.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: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:random.seed()andtorch.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 thefinetune_gradio.pysite is unaffected (its constant seed 666 is already valid).Verification
Standalone reproduction against
src/f5_tts/model/utils.py(before → after):