Skip to content

fix(inference): reject out-of-range seeds before generation - #337

Open
rwagwani wants to merge 1 commit into
NVIDIA:mainfrom
rwagwani:fix/seed-range
Open

rwagwani wants to merge 1 commit into
NVIDIA:mainfrom
rwagwani:fix/seed-range

Conversation

@rwagwani

Copy link
Copy Markdown
Collaborator

Related: #336 (same pattern: a value accepted at startup that fails only after the model has loaded).

Summary

seed was a plain int | None with no range, but the samplers accept only part of it: the bidirectional sampler seeds NumPy's RandomState (0 to 2**32 - 1, via misc.arch_invariant_rand), and torch.Generator overflows at 2**64. A request with seed: 18446744073709551616 loaded the model and then failed with ValueError: Overflow when unpacking long long when the first noise was drawn.

Change

  • seed becomes Annotated[int, Field(ge=0, le=2**32 - 1)] (MAX_SEED), the range every sampler accepts. An out-of-range seed is rejected when the request is parsed, before the model loads.
  • num_outputs > 1 uses seed + i per output, so the built sample also checks that the last per-output seed stays in range. This check runs when the sample is built, still before generation.
  • Chunked bidirectional transfer (transfer.py) and chunked multiview (multiview.py) add the chunk index to the seed. Those sums now wrap within the range, so a seed at the top of the range cannot fail on a later chunk. Nothing changes for any seed that runs today.
  • A missing seed is unchanged: it falls back to the per-sample derived seed (already within 31 bits).
  • docs/inference.md states the range and the fallback.

Behaviour change: negative seeds currently run on the causal (Sim-Transfer) path, because torch.Generator accepts them; on normal models they already fail after model load (Seed must be between 0 and 2**32 - 1, reproduced on Cosmos3-Nano with --seed -1). They are now rejected at startup on every model, so one range holds everywhere. No seed in the repository's specs, docs, tests or notebooks is outside the range.

Not covered here: the action policy servers (scripts/action_policy_server_*.py) take their own seed argument and are unchanged.

Verification

  • New L0 tests: 0, 2025 and 2**32 - 1 accepted; -1, 2**32 and 2**64 rejected; seed = 2**32 - 1 with num_outputs = 2 rejected, both directly and through build_sample.
  • args_test.py, common/args_test.py, transfer_test.py, multiview_test.py: 194 passed.
  • The CI unit-test job (-m L0, same command as gpu-tests.yml), replicated on a single GB300: 791 passed vs 784 on main 1a2f03a, with the same single failure that main shows on this machine (activation_marks_test.py).
  • GPU: on this branch, --seed -1 and --seed 18446744073709551616 are rejected at parse, before the model loads (Input should be greater than or equal to 0 / less than or equal to 4294967295). --seed 2025 gives the same video as main.

🤖 Generated with Claude Code

`seed` accepted any integer, but the samplers cannot take all of them:
the bidirectional sampler seeds NumPy's RandomState (0..2**32-1) and
torch.Generator overflows at 2**64. A request with seed=2**64 therefore
loaded the model and then failed with "Overflow when unpacking long
long" when the first noise was drawn.

Constrain `seed` to 0..2**32-1, the range every sampler accepts. An
out-of-range seed is rejected when the request is parsed, before the
model loads. num_outputs > 1 uses seed + i per output, so the built
sample also checks the last per-output seed (this check runs when the
sample is built, still before generation). Chunked bidirectional
transfer and chunked multiview add the chunk index to the seed; those
sums now wrap within the range, which changes nothing for any seed that
runs today. A missing seed still falls back to the per-sample derived
seed, which is within 31 bits. docs/inference.md states the range.

Behaviour change: negative seeds currently run on the causal
(Sim-Transfer) path, because torch.Generator accepts them. They are now
rejected on every model, so one range holds for all of them. No seed in
the repository's specs, docs, tests or notebooks is outside the range.

Signed-off-by: rwagwani <rwagwani@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant