fix(nft): seed the sigma shuffle and the corruption noise so NFT runs reproduce - #156
Merged
Merged
Conversation
This was referenced Aug 11, 2026
Rockdu
force-pushed
the
fix/nft-determinism
branch
from
August 12, 2026 01:07
de047e6 to
d732e4e
Compare
Rockdu
marked this pull request as ready for review
August 12, 2026 06:23
Rockdu
force-pushed
the
fix/nft-determinism
branch
from
August 12, 2026 07:44
d732e4e to
b8b5ac8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of three. Base: #155.
What
Seed the two random streams DiffusionNFT draws from, the way SFT already does:
data_conversion_hub/nft.py— the per-sample sigma permutationloss_hub/nft.py— the corruption noise inprepare_nft_batchmiles/utils/hash_utils.py—stable_hash, lifted out ofloss_hub/sft.py's private_seedso the converter (undermiles/ray/) and the loss hub (undermiles/backends/) can share it without importing across that boundaryNothing in miles upstream covers this: its hash helpers are all private and purpose-built (tensor checksums in
local_weight_checksum.py,disk_delta.py), so there was nothing to reuse.hash_utilsrather than a seed-specific name because the thing being solved is general —hash()is randomised per process by PYTHONHASHSEED, so anything derived from it stops agreeing across ranks and runs. Seeding is the first caller, not the only possible one.Why
Both streams ran off the global RNG:
sample_noisealready takes agenerator— the plumbing was there and unused.So NFT training does not reproduce, and
--deterministic-modedoes not make it reproduce. Two recordings of the same configuration on the same pinned stack (same image, same sglang commit, same miles-d commit, onlyNUM_ROLLOUTdiffering) agree bit-for-bit on the rollout side and diverge on the training side from the very first optimizer step:rollout/reward/raw_meanrollout/reward/raw_meantrain/nft_losstrain/nft_t_meanIdentical rollouts, 0.6% apart in loss.
nft_t_meandiffering confirms the sigma assignment itself differed; the rollout agreeing rules out the generation path.This was found while trying to record an e2e standard for NFT (#157) — the standard could never have held.
Seeding scheme
Same as SFT, and byte-identical to it:
stable_hashproduces exactly the integers_seeddid, so SFT's streams are untouched. Keyed on what makes a stream distinct rather than on draw order, so a stream reproduces even when unrelated code changes how much randomness it consumes first.sample.indexsample.indexis the data source's global counter (data_source.py:85), which advances across rollouts and is checkpointed, so each sample draws its own permutation and no two rollouts repeat one.Behaviour
NFT training numbers change. The noise and permutation sequences are different from the unseeded ones — this replaces an arbitrary stream with a fixed one, it does not correct a wrong value. No NFT e2e standard exists yet to re-record. SFT is untouched:
stable_hashreturns exactly what_seedreturned for the same arguments (verified), and its two call sites only change the name they import.Tests
TestNftDeterminism— the shuffle reproduces across calls, each sample gets its own permutation, the corruption noise reproduces, and a different microbatch still draws different noise. Reverting either seeding line fails exactly one of the first two.Stack
Checklist
pre-commit runpasses — on the touched files (black/ruff/isort/autoflake)pytestis green —tests/fast199 passed vs 189 on cleanmain(the +10 are new); the 4 failures there reproduce onmainand are macOS c10d socket issuessglangstubbed out; CI is the real check.python3 train.py --helpstill parses — no flag changes