Skip to content

fix(test): avoid singleton rendezvous port races - #5595

Closed
yaoyu-33 wants to merge 1 commit into
mainfrom
yuya/fix-qwen3-adapter-port-race
Closed

yaoyu-33 wants to merge 1 commit into
mainfrom
yuya/fix-qwen3-adapter-port-race

Conversation

@yaoyu-33

Copy link
Copy Markdown
Contributor

Summary

  • use an in-process torch.distributed.HashStore for singleton temporary process groups, avoiding TCP rendezvous ports and inherited distributed environment settings
  • use torchrun --standalone for the Qwen3 adapter TP/PP verification subprocesses
  • update focused unit coverage for both gloo and NCCL singleton initialization

Root cause

Main CI job https://github.com/NVIDIA-NeMo/Megatron-Bridge/actions/runs/31846107309/job/94940794151 failed in TestVerifyAdapter.test_cpu_full_verification with EADDRINUSE on port 43963.

The test selected a free port in the parent process, released it, and then launched a child that spent about 20 seconds loading models before binding that port. Another socket could claim the port during that gap.

Testing

  • uvx --from pre-commit pre-commit run --all-files — passed
  • focused ruff check/format, Python compile, and git diff --check — passed
  • runtime probe initialized and destroyed a gloo process group through HashStore while MASTER_PORT pointed to an occupied socket — passed
  • uv run python -m pytest tests/unit_tests/training/test_model_load_save.py -k temporary_distributed_context -vv — not runnable on macOS ARM because nvidia-resiliency-ext==0.6.0 publishes Linux-only wheels; CI will run the focused coverage on Linux

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

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.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 85b82ce

@claude

claude Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Light review - LGTM

Clean cleanup. Replacing the socket-based init_method with an in-process dist.HashStore() is the right call for a single-process (world_size=1, rank=0) context: it avoids reserving/leaking a TCP port and no longer inherits rendezvous env vars from the caller. Verified the removed os/socket imports and the deleted test_temporary_distributed_context_with_env_vars test (the env-var branch it covered no longer exists), and confirmed no remaining doc/script references to the old behavior.

Call-site trace confirms consistency:

  • CPU tests run verify_adapter.py directly, so gloo + HashStore, no MASTER_PORT needed.
  • GPU test uses torchrun --standalone, which populates MASTER_ADDR/MASTER_PORT for the nccl env:// init path, so dropping the manual MASTER_PORT injection is correct.

No critical bugs or typos found. Note: --standalone alongside --nnodes=1 is redundant but harmless.

Suggested test cases

  • tests/functional_tests/test_groups/models/qwen/test_qwen3_peft_verify.py::TestQwen3PeftVerify::test_cpu_peft_only
  • tests/functional_tests/test_groups/models/qwen/test_qwen3_peft_verify.py::TestQwen3PeftVerify::test_cpu_full_verification
  • tests/functional_tests/test_groups/models/qwen/test_qwen3_peft_verify.py::TestQwen3PeftVerify::test_gpu_parallelism[2-1-TP]
  • tests/functional_tests/test_groups/models/qwen/test_qwen3_peft_verify.py::TestQwen3PeftVerify::test_gpu_parallelism[1-2-PP]
  • tests/unit_tests/training/test_model_load_save.py::TestTemporaryDistributedContext::test_temporary_distributed_context_gloo
  • tests/unit_tests/training/test_model_load_save.py::TestTemporaryDistributedContext::test_temporary_distributed_context_nccl
  • No perf tests impacted.

@yaoyu-33 yaoyu-33 added area:training Training loop, callbacks, and runtime integration bug Something isn't working needs-more-tests Requires additional L0 and L1 test coverage before merge needs-review PR is ready for code review and waiting on a reviewer labels Aug 15, 2026
@yaoyu-33 yaoyu-33 closed this Aug 17, 2026
ManoharPaturi added a commit to ManoharPaturi/Megatron-Bridge that referenced this pull request Sep 7, 2026
…zvous

temporary_distributed_context() picked a free TCP port, closed the
socket, and then asked init_process_group() to bind the same address.
Any process claiming the port in that window makes standalone
checkpoint import/export fail with EADDRINUSE (race seen in public CI).
When MASTER_ADDR/MASTER_PORT were set the context also silently
inherited the caller's rendezvous settings.

The context is always world_size=1 rank=0, so rendezvous over TCP is
not needed at all: pass an in-process dist.HashStore() instead. No host
port is touched and env vars are ignored.

Fixes NVIDIA-NeMo#5967. Approach follows yaoyu-33's NVIDIA-NeMo#5595 (closed before review
finished).

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

This branch was previously deployed

2 inactive deployments
public — 85b82ce4 Deployed Aug 15, 2026 by copy-pr-bot[bot] via release / finalize / notify #4628
test — 85b82ce4 Deployed Aug 15, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #20603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training loop, callbacks, and runtime integration bug Something isn't working needs-more-tests Requires additional L0 and L1 test coverage before merge needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant