Megatron-LM icon indicating copy to clipboard operation
Megatron-LM copied to clipboard

test(elastification): make Flextron gumbel test deterministic

Open Williams500 opened this issue 5 months ago • 3 comments

  • [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_dev quarantine once the test controls the extra Python RNG source.
  • [ ] 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.sh
    • black, isort, pylint, and ruff passed for the changed file.
    • The script reached mypy, but local .venv does not contain mypy; the repository script handles this with || true and exits 0.
  • [x] uv run python - <<'PY' ... verified random.seed(0) produces the same hard_sample draw (0.84442185152504812, below hard_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_determinism did not run locally: the local uv environment fails while loading tests/unit_tests/conftest.py with ModuleNotFoundError: No module named 'torch'. This machine also has no local NVIDIA GPU, so the CUDA-backed target test needs CI validation.

Williams500 avatar Jun 05 '26 12:06 Williams500

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.

copy-pr-bot[bot] avatar Jun 05 '26 12:06 copy-pr-bot[bot]

/claude review

guihong-nv avatar Jun 11 '26 19:06 guihong-nv

/ok to test 091e02e

guihong-nv avatar Jun 11 '26 20:06 guihong-nv