{"record":{"id":"7900b196d6c945f5","repo":"Lightning-AI/pytorch-lightning","slug":"seed-is-not-in-bounds-numpy-accepts-from-min-s","errorCode":null,"errorMessage":"{seed} is not in bounds, numpy accepts from {min_seed_value} to {max_seed_value}","messagePattern":"(.+?) is not in bounds, numpy accepts from (.+?) to (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/seed.py","lineNumber":54,"sourceCode":"        verbose: Whether to print a message on each rank with the seed being set.\n\n    \"\"\"\n    if seed is None:\n        env_seed = os.environ.get(\"PL_GLOBAL_SEED\")\n        if env_seed is None:\n            seed = 0\n            if verbose:\n                rank_zero_warn(f\"No seed found, seed set to {seed}\")\n        else:\n            try:\n                seed = int(env_seed)\n            except ValueError:\n                raise ValueError(f\"Invalid seed specified via PL_GLOBAL_SEED: {repr(env_seed)}\")\n    elif not isinstance(seed, int):\n        seed = int(seed)\n\n    if not (min_seed_value <= seed <= max_seed_value):\n        raise ValueError(f\"{seed} is not in bounds, numpy accepts from {min_seed_value} to {max_seed_value}\")\n\n    if verbose:\n        log.info(rank_prefixed_message(f\"Seed set to {seed}\", _get_rank()))\n\n    os.environ[\"PL_GLOBAL_SEED\"] = str(seed)\n    random.seed(seed)\n    if _NUMPY_AVAILABLE:\n        import numpy as np\n\n        np.random.seed(seed)\n    torch.manual_seed(seed)\n\n    os.environ[\"PL_SEED_WORKERS\"] = f\"{int(workers)}\"\n\n    return seed\n\n\ndef reset_seed() -> None:","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/seed.py#L36-L72","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nseed_everything(int(time.time()))  # or -1, or huge hash -> out of bounds\n\n# after\nseed = int(time.time()) % (2**32)\nseed_everything(seed)","handlingStrategy":"validation","validationCode":"MIN, MAX = 0, 2**32 - 1\nseed = int(seed) % (2**32)\nassert MIN <= seed <= MAX","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp/hash generated seeds into [0, 2**32-1]","Avoid -1/None sentinel seeds"],"tags":["lightning","seeding","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}