{"record":{"id":"878a05777650954f","repo":"unslothai/unsloth","slug":"seed-must-fit-in-torch-s-64-bit-range","errorCode":null,"errorMessage":"seed must fit in torch's 64-bit range","messagePattern":"seed must fit in torch's 64-bit range","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_train_common.py","lineNumber":1038,"sourceCode":"            )\n        if self.resolution < 64 or self.resolution % 8 != 0:\n            raise ValueError(\"resolution must be a multiple of 8 and >= 64\")\n        # A video family's VAE compresses space by 32, so an off-grid resolution changes the\n        # latent geometry silently. Refuse it here, before the GPU models are evicted.\n        if (\n            resolved_family in TRAINABLE_VIDEO_FAMILIES\n            and self.resolution % _VIDEO_RESOLUTION_MULTIPLE != 0\n        ):\n            raise ValueError(\n                f\"'{resolved_family}' trains at a resolution that is a multiple of \"\n                f\"{_VIDEO_RESOLUTION_MULTIPLE} (its VAE compresses space by that factor); \"\n                f\"got {self.resolution}.\"\n            )\n        if self.mixed_precision not in (\"bf16\", \"fp16\", \"no\"):\n            raise ValueError(\"mixed_precision must be one of bf16 / fp16 / no\")\n        # torch.manual_seed unpacks int64/uint64, so anything wider raises inside the trainer, after eviction. Catch it here.\n        if not -(2**63) <= int(self.seed) <= 2**64 - 1:\n            raise ValueError(\"seed must fit in torch's 64-bit range\")\n        # Refuse fp16 for a bf16-only DiT family up front, before evicting resident models.\n        if self.mixed_precision == \"fp16\" and resolved_family in _FORCE_BF16_FAMILIES:\n            raise ValueError(\n                f\"'{resolved_family}' LoRA training requires bf16: fp16 overflows its fp32 \"\n                f\"RoPE / embedder internals. Set mixed precision to bf16.\"\n            )\n        if str(self.lr_scheduler) not in _LR_SCHEDULERS:\n            raise ValueError(\n                f\"lr_scheduler must be one of {', '.join(sorted(_LR_SCHEDULERS))}; \"\n                f\"got {self.lr_scheduler!r}\"\n            )\n        if not 1 <= int(self.cache_variants) <= 16:\n            raise ValueError(\"cache_variants must be between 1 and 16\")\n        # Checkpointing knobs. Rejected here, before the route evicts resident GPU models, rather than deep in the loop.\n        try:\n            save_steps = int(self.save_steps or 0)\n            save_total_limit = int(self.save_total_limit or 0)\n        except (TypeError, ValueError) as exc:","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_train_common.py#L1020-L1056","documentation":"The validator rejected a seed outside the range torch can accept. torch.manual_seed unpacks its argument as int64/uint64, so anything wider raises inside the trainer — after resident GPU models have already been evicted, wasting time. This check fails fast during validation instead.","triggerScenarios":"Passing seed = 2**64 (or larger), a negative value below -(2**63), or a string that parses to such a number. Typical sources: generating seeds from 128-bit UUIDs/hashes, numpy seeds cast incorrectly, or randomness sources that produce arbitrarily large Python ints.","commonSituations":"seed = int.from_bytes(uuid4().bytes, 'big'); seed derived from a hash (blake2/sha) truncated to 128 bits; porting seeds from libraries that allow arbitrary ints (Python's random accepts any non-negative int).","solutions":["Clamp the seed to [-(2**63), 2**64 - 1]; for practical purposes use 0 <= seed < 2**63 - 1.","When deriving from a hash, truncate: seed = int.from_bytes(h.digest()[:8], 'big').","Prefer plain small integers from random.randrange(2**63 - 1)."],"exampleFix":"# before\nseed = int.from_bytes(uuid.uuid4().bytes, 'big')  # 128-bit, too wide\n\n# after\nseed = int.from_bytes(uuid.uuid4().bytes[:8], 'big')  # 64-bit","handlingStrategy":"validation","validationCode":"SEED_MIN, SEED_MAX = -(2**63), 2**64 - 1\n\ndef check_seed(v) -> int:\n    s = int(v)\n    if not SEED_MIN <= s <= SEED_MAX:\n        raise ValueError(f\"seed must fit [{SEED_MIN}, {SEED_MAX}], got {s}\")\n    return s\n\ndef clamp_seed(v) -> int:\n    return max(0, min(int(v), 2**63 - 1))","typeGuard":"def is_valid_seed(v) -> bool:\n    try:\n        return -(2**63) <= int(v) <= 2**64 - 1\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    session.submit_training(config)\nexcept ValueError as e:\n    if \"seed\" in str(e):\n        config.seed = config.seed % (2**63)  # fold into range and retry\n        session.submit_training(config)\n    else:\n        raise","preventionTips":["Never forward raw hash/UUID integers as seeds — truncate to 64 bits first.","Generate seeds with random.randrange(2**63 - 1).","Treat 'seed must fit torch's 64-bit range' as the canonical constraint when building reproducibility tooling."],"tags":["training","seed","pytorch","validation","configuration"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}