test(elastification): make Flextron gumbel test deterministic
- [x] I, the PR author, have personally reviewed every line of this PR.
What does this PR do ?
Make TestFlextronRouter::test_gumbel_determinism deterministic by controlling the Python random draw that selects the router hard/soft branch.
Issue tracking
Linked issue: Fixes #5155
Contribution process
Pre-checks
- [ ] I have added relevant unit tests
- N/A: this is a test-only fix that updates an existing unit test and removes the
flaky_in_devquarantine once the test controls the extra Python RNG source.
- N/A: this is a test-only fix that updates an existing unit test and removes the
- [ ] I have added relevant functional tests
- N/A: this PR only fixes a unit-test flake and does not change production training behavior or numerics.
- [ ] I have added proper typing to my code Typing guidelines
- N/A: no public API, production code, or type signatures changed.
- [ ] I have added relevant documentation
- N/A: no user-facing behavior or docs surface changed.
- [x] I have run the autoformatter.sh on my PR
Summary
test_gumbel_determinism compares two FlextronRouter instances bit-for-bit after copying weights. The Gumbel path is torch-seeded, but FlextronRouter.forward() also samples hard_sample from Python random.random(). If the two forwards draw different hard/soft branches, the bit-exact assertion can fail even though the Gumbel seed path is deterministic.
This change seeds Python random identically before each router forward in the test, restores the previous Python RNG state afterward, and removes the flaky_in_dev quarantine. Production router behavior is unchanged.
Test plan
- [x]
uv run isort --check-only tests/unit_tests/elastification/test_hybrid_flex_router.py - [x]
uv run python -m py_compile tests/unit_tests/elastification/test_hybrid_flex_router.py - [x]
git diff --check - [x]
PATH="$PWD/.venv/bin:$PATH" BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.shblack,isort,pylint, andruffpassed for the changed file.- The script reached
mypy, but local.venvdoes not containmypy; the repository script handles this with|| trueand exits 0.
- [x]
uv run python - <<'PY' ...verifiedrandom.seed(0)produces the samehard_sampledraw (0.84442185152504812, belowhard_sample_th=0.996) for both forwards. - [ ]
uv run python -m pytest -q tests/unit_tests/elastification/test_hybrid_flex_router.py::TestFlextronRouter::test_gumbel_determinismdid not run locally: the local uv environment fails while loadingtests/unit_tests/conftest.pywithModuleNotFoundError: No module named 'torch'. This machine also has no local NVIDIA GPU, so the CUDA-backed target test needs CI validation.
This pull request requires additional validation before any workflows can run on NVIDIA's runners.
Pull request vetters can view their responsibilities here.
Contributors can view more details about this message here.
/claude review
/ok to test 091e02e