Skip to content

[OMNIML-6228] Fix two flaky tests: MTP causality tolerance and example-runner port collisions - #2900

Merged
shengliangxu merged 2 commits into
mainfrom
shengliangx/ci-flaky-deflake
Oct 21, 2026
Merged

shengliangxu merged 2 commits into
mainfrom
shengliangx/ci-flaky-deflake

Conversation

@shengliangxu

@shengliangxu shengliangxu commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: Bug fix (tests)

Two flaky CI failures from the last two weeks:

  1. test_mtp_later_attention_blocks_remain_causal (tests/unit/torch/models/test_nemotron_h_mtp.py) compared the positions that must not change with rtol=1e-6, atol=1e-9, tighter than float noise, on unseeded random inputs. Over 400 RNG states per checkpoint those positions differ by at most 3e-8, and tiny_checkpoint1 fails 5 of 400 states at the old tolerance (for example 2.4e-9 against the 1e-9 allowed). A serial run sees the same RNG state every time, so serial CI never showed it; under pytest-xdist (the [OMNIML-6178] [1/11] Run the unit tests in parallel with pytest-xdist #2845 stack) the state varies and the test failed on 3 of about 22 unit runs. The new tolerance, rtol=1e-5, atol=1e-6, has no failure in 400 states for either checkpoint, sits 30x above the noise and about 10^5x below what a real leak does (shifting the last position changes the earlier ones by about 0.1).
  2. test_distill_puzzletron_anymodel (tests/examples/megatron_bridge/test_distill.py) failed twice (PR runs on 10-15, which passed on the re-run, and 10-18) with DistNetworkError: The server socket has failed to listen ... name: EADDRINUSE, raised inside Megatron-Bridge's temporary_distributed_context when the HF export step binds the rendezvous port again. I could not reproduce it on CPU (destroying a process group and re-initializing it on the same port worked 300 times out of 300), so the cause of the port being taken is unknown. run_example_command already reruns a step once on a transient HuggingFace error; this PR adds the port collision to the transient markers (EADDRINUSE, Address already in use). The in-process runner picks a new port when the process group is not initialized, and nothing else changes: a real failure still fails on its first attempt.

Usage

N/A

Testing

  • tests/unit/test_example_run_command.py::test_run_example_command_retries_only_transient_errors (3 cases: an HF 5xx and a port collision are rerun once, an assertion failure is not). Without the two new markers the port-collision case fails.
  • MTP tolerance: tests/unit/torch/models/test_nemotron_h_mtp.py passes (72 tests). With every test reseeded from its id and a seed (a small pytest plugin, not part of this PR), the whole tests/unit suite failed this test in 1 of 53 runs at the old tolerance and in 0 of 90 runs of the test file at the new one.
  • Similar tests: I ran tests/unit (5,119 tests) under 52 seeds, 3 shuffled file orders and with every file alone, and measured how close each assert_close/allclose came to failing (about 1,200 assertion sites, 30 seeds). No other test depends on the RNG state or the file order; the only failure in every run is test_qwen_image_pdd_plugin.py::test_mr210_joint_mask_ignores_padded_token_values, which fails the same way on my local CPU host with and without these changes and passes in CI.
  • Not run on GPU: the retry only changes what the example runner does after a step fails with one of the markers.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅ (one parametrized test)
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: ❌ (to be run)

Summary by CodeRabbit

  • Bug Fixes

    • Improved example command retries for transient Hugging Face access and port-binding errors.
    • Non-transient failures, such as assertion errors, continue to propagate without retries.
    • Retry limits and delay behavior remain unchanged.
  • Tests

    • Added coverage for retry behavior across transient and non-transient errors.
    • Updated numerical tolerance checks for causal MTP model testing.

test_mtp_later_attention_blocks_remain_causal compares the positions that must not change
with rtol=1e-6 and atol=1e-9, tighter than float noise, on unseeded random inputs. Over 400
RNG states the earlier positions differ by at most 3e-8, so tiny_checkpoint1 fails for 1.2%
of the states (5 of 400; seed 32 reproduces it: 2.4e-9 against 1e-9 allowed). A serial run
sees the same RNG state every time, but under pytest-xdist it varies, and the test failed
on 3 of about 22 unit runs of a PR stack that runs the unit tests in parallel.

Use rtol=1e-5 and atol=1e-6: no failure in 400 states for either checkpoint, 30x above the
noise and about 10^5x below what a real leak does (the shifted last position changes the
earlier ones by about 0.1).

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
(cherry picked from commit bf7ae348cd6c1048fc4e9f67667d0a63cd22c1af)
test_distill_puzzletron_anymodel failed twice in two weeks (PR 2819 on 10-15, which passed on the
rerun, and PR 2860 on 10-18) with "DistNetworkError: The server socket has failed to listen ...
name: EADDRINUSE" from Megatron-Bridge's temporary_distributed_context, when the HF export step
binds the rendezvous port again. Whoever held the port is gone by the next attempt, and the
in-process runner picks a new port when the process group is not initialized.

run_example_command already reruns a step once on a transient HuggingFace error. Treat a port
collision the same way, and leave everything else (a real failure) failing on the first attempt.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 06cd3eb2-2189-4080-9d53-7544da158925
📥 Commits

Reviewing files that changed from the base of the PR and between 3d90067 and cf8fe0c.

📒 Files selected for processing: 3
  • tests/_test_utils/examples/run_command.py
  • tests/unit/test_example_run_command.py
  • tests/unit/torch/models/test_nemotron_h_mtp.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

📝 Walkthrough

The example command runner now retries on address-in-use errors as well as existing transient errors. A parameterized test checks retry behavior. The causal MTP test uses relaxed numerical tolerances.

Changes: Transient Error Retries

Layer / File(s) Summary
Transient error detection and retry validation
tests/_test_utils/examples/run_command.py, tests/unit/test_example_run_command.py
The runner uses generic transient markers, including EADDRINUSE and “Address already in use,” for in-process and subprocess retries. Retry limits and delays remain unchanged. The test checks retries for transient errors and propagation of assertion failures.

Causal MTP Test Tolerance

Layer / File(s) Summary
Causal MTP assertion tolerance
tests/unit/torch/models/test_nemotron_h_mtp.py
The assertion uses rtol=1e-5 and atol=1e-6 and documents float-noise tolerance.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kevalmorabia97, meenchen

Merge Risk: ⚪ Minimal · up to cf8fe

This change only makes two flaky tests more robust by retrying port collisions and tolerating small floating-point noise. It does not alter production behavior, and no merge-blocking risk remains.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies both main changes: MTP causality tolerance and example-runner port-collision retries. It is specific and related to the pull request objectives.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed PASS. The PR changes only test files and a test helper under tests/. The diff adds transient-error string matching, retry logic, a test, and relaxed numeric tolerances. It adds no `torch.load(..., w…
Full details: Security Anti-Patterns

Explanation

PASS. The PR changes only test files and a test helper under tests/. The diff adds transient-error string matching, retry logic, a test, and relaxed numeric tolerances. It adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, eval(), exec(), # nosec, or dependency changes.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@shengliangxu

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.79%. Comparing base (ff336e7) to head (cf8fe0c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2900      +/-   ##
==========================================
+ Coverage   76.90%   78.79%   +1.88%     
==========================================
  Files         658      659       +1     
  Lines       74029    74155     +126     
==========================================
+ Hits        56932    58429    +1497     
+ Misses      17097    15726    -1371     
Flag Coverage Δ
examples-diffusers 20.05% <ø> (-0.01%) ⬇️
examples-gpt-oss 13.51% <ø> (+<0.01%) ⬆️
examples-hf_ptq 23.19% <ø> (-0.04%) ⬇️
examples-llm_distill 13.59% <ø> (-0.01%) ⬇️
examples-llm_eval 17.24% <ø> (+<0.01%) ⬆️
examples-llm_qat 17.48% <ø> (-0.01%) ⬇️
examples-llm_sparsity 15.77% <ø> (+<0.01%) ⬆️
examples-megatron_bridge 26.41% <ø> (-0.17%) ⬇️
examples-specdec_bench 13.29% <ø> (+<0.01%) ⬆️
examples-speculative_decoding 17.47% <ø> (-0.06%) ⬇️
examples-torch_onnx 21.40% <ø> (-0.01%) ⬇️
examples-torch_trt 15.24% <ø> (+<0.01%) ⬆️
examples-vllm_serve 15.09% <ø> (+<0.01%) ⬆️
gpu 59.28% <ø> (+8.25%) ⬆️
regression 15.10% <ø> (-0.02%) ⬇️
unit 60.50% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shengliangxu
shengliangxu marked this pull request as ready for review October 20, 2026 23:52
@shengliangxu
shengliangxu requested a review from a team as a code owner October 20, 2026 23:52

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

LGTM: the retry change is small and tested; the justified MTP tolerance relaxation needs human sign-off.

Needs action:

  • Confirm the tolerance update in tests/unit/torch/models/test_nemotron_h_mtp.py: the documented float-noise margin justifies relaxing precision while retaining the causality assertion.

No action needed:

  • Retry coverage exercises transient HF errors, port collisions, and immediate propagation of non-transient failures.
  • Reuses the existing bounded retry loop and existing per-attempt port selection; no new retry subsystem is introduced.
  • Tests were inspected, not executed.

@shengliangxu
shengliangxu merged commit 576c66f into main Oct 21, 2026
57 checks passed
@shengliangxu
shengliangxu deleted the shengliangx/ci-flaky-deflake branch October 21, 2026 06:18
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-21 06:18 UTC

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.

3 participants