Lightning-AI/pytorch-lightning · error · ValueError
{seed} is not in bounds, numpy accepts from {min_seed_value}
Error message
{seed} is not in bounds, numpy accepts from {min_seed_value} to {max_seed_value} What it means
`seed_everything` requires the seed to be within [4294967292? no —] `min_seed_value`..`max_seed_value`, the range numpy accepts (0 to 2**32 - 1). After parsing the seed (from the argument or PL_GLOBAL_SEED) it validates the bounds and raises ValueError otherwise.
Source
Thrown at src/lightning/fabric/utilities/seed.py:54
verbose: Whether to print a message on each rank with the seed being set.
"""
if seed is None:
env_seed = os.environ.get("PL_GLOBAL_SEED")
if env_seed is None:
seed = 0
if verbose:
rank_zero_warn(f"No seed found, seed set to {seed}")
else:
try:
seed = int(env_seed)
except ValueError:
raise ValueError(f"Invalid seed specified via PL_GLOBAL_SEED: {repr(env_seed)}")
elif not isinstance(seed, int):
seed = int(seed)
if not (min_seed_value <= seed <= max_seed_value):
raise ValueError(f"{seed} is not in bounds, numpy accepts from {min_seed_value} to {max_seed_value}")
if verbose:
log.info(rank_prefixed_message(f"Seed set to {seed}", _get_rank()))
os.environ["PL_GLOBAL_SEED"] = str(seed)
random.seed(seed)
if _NUMPY_AVAILABLE:
import numpy as np
np.random.seed(seed)
torch.manual_seed(seed)
os.environ["PL_SEED_WORKERS"] = f"{int(workers)}"
return seed
def reset_seed() -> None:View on GitHub (pinned to 9fed5c27d2)
Solutions
- Use a seed in [0, 4294967295], e.g. `seed_everything(42)`
- If generating seeds from hashes/time, clamp: `seed = seed % (2**32)`
- Avoid -1/None sentinels; guard configs that feed seed values
Example fix
# before seed_everything(int(time.time())) # or -1, or huge hash -> out of bounds # after seed = int(time.time()) % (2**32) seed_everything(seed)
Defensive patterns
Strategy: validation
Validate before calling
MIN, MAX = 0, 2**32 - 1 seed = int(seed) % (2**32) assert MIN <= seed <= MAX
Prevention
- Clamp/hash generated seeds into [0, 2**32-1]
- Avoid -1/None sentinel seeds
When it happens
Trigger: Calling `seed_everything(seed)` with a negative integer, a value > 4294967295, or something like `seed_everything(-1)`; a float/string argument that converts to an out-of-range int; PL_GLOBAL_SEED set to a huge number.
Common situations: Using `-1` or `None`-sentinel values as seeds, using a 64-bit hash or timestamp-derived value that overflows numpy's range, generated seeds from config sweeps exceeding 2**32-1.
Related errors
- Invalid seed specified via PL_GLOBAL_SEED: {repr(env_seed)}
- Expected samples ({samples}) to be greater or equal than bat
- Unknown configuration for model optimizers. Output from `mod
- The lr scheduler dict must have the key "scheduler" with its
- The "interval" key in lr scheduler dict must be "step" or "e
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/7900b196d6c945f5.
Report an issue: GitHub.