Skip to content

Commit

Permalink
Update on "PYTHONHASHSEED needs to be in the range of [0,2**32 - 1]"
Browse files Browse the repository at this point in the history
Otherwise it complaints:
> Fatal Python error: config_init_hash_seed: PYTHONHASHSEED must be "random" or an integer in range [0; 4294967295]

Reference: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED



[ghstack-poisoned]
  • Loading branch information
tianyu-l committed Dec 12, 2024
1 parent 61c08eb commit fb7f801
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions torchtitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_determinism(
if c10d.get_world_size() > 1 and "pp" in world_mesh.mesh_dim_names:
pp_mesh = world_mesh["pp"]
seed += pp_mesh.get_local_rank()
seed %= 2**64 - 1
seed %= 2**64

logger.debug(
f"PP rank {pp_mesh.get_local_rank()}, Global rank {c10d.get_rank()} using seed: {seed}"
Expand All @@ -106,8 +106,8 @@ def set_determinism(

# The native RNGs and python RNG may not be important, except for the 1-D PP case, but we seed them for consistency.
torch.manual_seed(seed)
# PYTHONHASHSEED can be a decimal number in the range [0,2**32 - 1]
os.environ["PYTHONHASHSEED"] = str(seed % (2**32 - 1))
# PYTHONHASHSEED can be a decimal number in the range [0, 2**32 - 1]
os.environ["PYTHONHASHSEED"] = str(seed % 2**32)

# As long as we are not in the 1-D (PP-only) case, we will have a seed to use for all ranks of the SPMD mesh.
# IF PP is also used, this seed is unique per PP rank.
Expand Down

0 comments on commit fb7f801

Please sign in to comment.