[https://nvbugs/6084743][fix] Use free port for FLUX/WAN multi-GPU test distributed init#13364
Conversation
…istributed init The Ulysses and combined-optimization multi-GPU tests in test_flux_pipeline.py hardcoded MASTER_PORT=12355 for torch.distributed init. When two multi-GPU test runs land on the same node back-to-back or another process already holds the port, init_process_group fails with "The server socket has failed to listen on any local network address". Thread master_port through _setup_distributed and both worker functions, and allocate a fresh port via get_free_port() at each mp.spawn call site. Same pattern already used by tests/unittest/_torch/visual_gen/multi_gpu/*. Signed-off-by: Kanghwan Jang <861393+karljang@users.noreply.github.com>
|
/bot run --disble-fail-fast |
📝 WalkthroughWalkthroughThe change adds dynamic TCP port selection for distributed multi-GPU test workers by introducing a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/unittest/_torch/visual_gen/test_flux_pipeline.py (2)
974-975: QA list update is unnecessary for this PR.This is a unittest-only fix under
tests/unittest/...; notests/integration/test_lists/qa/changes are needed.As per coding guidelines: "If the PR only touches unittest/ or narrow unit scope, say explicitly whether QA list updates are unnecessary or optional."
Also applies to: 1157-1158
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unittest/_torch/visual_gen/test_flux_pipeline.py` around lines 974 - 975, The change only touches unit tests (function test_ulysses_2gpu_correctness in tests/unittest/_torch/visual_gen/test_flux_pipeline.py), so remove or revert any edits to the QA lists under tests/integration/test_lists/qa/ and update the PR description to explicitly state that QA list updates are unnecessary for this unittest-only PR; ensure the commit message or PR body references the affected unit test (test_ulysses_2gpu_correctness) and clarifies no integration QA changes are required.
1028-1034: Optional hardening: add a bounded retry around spawn for residual port race windows.At Line 1028 and Line 1212, the port is selected in the parent process before children bind; another process can still claim it in between. A small retry loop would make this even less flaky.
💡 Suggested hardening diff
+def _spawn_with_retry(worker_fn, world_size, checkpoint_path, inputs_cpu, return_dict, max_retries=3): + for attempt in range(max_retries): + master_port = get_free_port() + try: + mp.spawn( + worker_fn, + args=(world_size, master_port, checkpoint_path, inputs_cpu, return_dict), + nprocs=world_size, + join=True, + ) + return + except RuntimeError as err: + msg = str(err) + if attempt + 1 < max_retries and ( + "failed to listen on any local network address" in msg + or "Address already in use" in msg + ): + continue + raise @@ - master_port = get_free_port() - mp.spawn( - _run_ulysses_worker, - args=(2, master_port, FLUX1_CHECKPOINT_PATH, inputs_cpu, return_dict), - nprocs=2, - join=True, - ) + _spawn_with_retry( + _run_ulysses_worker, 2, FLUX1_CHECKPOINT_PATH, inputs_cpu, return_dict + ) @@ - master_port = get_free_port() - mp.spawn( - _run_all_optimizations_worker, - args=(2, master_port, FLUX1_CHECKPOINT_PATH, inputs_cpu, return_dict), - nprocs=2, - join=True, - ) + _spawn_with_retry( + _run_all_optimizations_worker, 2, FLUX1_CHECKPOINT_PATH, inputs_cpu, return_dict + )Also applies to: 1212-1218
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unittest/_torch/visual_gen/test_flux_pipeline.py` around lines 1028 - 1034, The test selects master_port via get_free_port() then immediately calls mp.spawn(_run_ulysses_worker...), which can race if another process grabs the port; wrap the get_free_port() + mp.spawn call in a small bounded retry loop (e.g., try up to N times with a short sleep) that re-reads master_port and re-attempts mp.spawn when spawn fails or when a quick port-binding check fails; apply the same pattern to the other occurrence around lines using master_port/get_free_port() and mp.spawn so both spots (the callsites of get_free_port(), mp.spawn, and the target function _run_ulysses_worker) are hardened against transient port races.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unittest/_torch/visual_gen/test_flux_pipeline.py`:
- Around line 974-975: The change only touches unit tests (function
test_ulysses_2gpu_correctness in
tests/unittest/_torch/visual_gen/test_flux_pipeline.py), so remove or revert any
edits to the QA lists under tests/integration/test_lists/qa/ and update the PR
description to explicitly state that QA list updates are unnecessary for this
unittest-only PR; ensure the commit message or PR body references the affected
unit test (test_ulysses_2gpu_correctness) and clarifies no integration QA
changes are required.
- Around line 1028-1034: The test selects master_port via get_free_port() then
immediately calls mp.spawn(_run_ulysses_worker...), which can race if another
process grabs the port; wrap the get_free_port() + mp.spawn call in a small
bounded retry loop (e.g., try up to N times with a short sleep) that re-reads
master_port and re-attempts mp.spawn when spawn fails or when a quick
port-binding check fails; apply the same pattern to the other occurrence around
lines using master_port/get_free_port() and mp.spawn so both spots (the
callsites of get_free_port(), mp.spawn, and the target function
_run_ulysses_worker) are hardened against transient port races.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f46c5caf-3f42-44ed-a22c-2499fd75f526
📒 Files selected for processing (1)
tests/unittest/_torch/visual_gen/test_flux_pipeline.py
|
/bot run --disable-fail-fast |
|
PR_Github #45123 Bot args parsing error: usage: /bot [-h] |
|
PR_Github #45124 [ run ] triggered by Bot. Commit: |
|
PR_Github #45124 [ run ] completed with state |
|
@chang-l , a few unit tests have been fixed by this PR, could you please review? :) |
…st distributed init (NVIDIA#13364) Signed-off-by: Kanghwan Jang <861393+karljang@users.noreply.github.com>
Summary
test_flux_pipeline.py::TestFluxCombinedOptimizations::test_all_optimizations_combinedtracked by nvbug 6084743 / TRTLLM-12007._setup_distributedintests/unittest/_torch/visual_gen/test_flux_pipeline.pyhardcodedMASTER_PORT=12355fortorch.distributedinit. When two multi-GPU tests land on the same node back-to-back, or another process already holds 12355,init_process_groupfails with "The server socket has failed to listen on any local network address".master_portthrough_setup_distributedand both worker functions, and allocate a fresh free port viatensorrt_llm._utils.get_free_port()at eachmp.spawncall site.tests/unittest/_torch/visual_gen/multi_gpu/(e.g.test_flux_ulysses.py,test_ulysses_attention.py).Test plan
python -m py_compile tests/unittest/_torch/visual_gen/test_flux_pipeline.py/bot runSummary by CodeRabbit
Tests