Skip to content

Distributed tests: take every MASTER_PORT from the shared rendezvous helper - #15679

Merged
danielhanchen merged 1 commit into
mainfrom
ci-rendezvous-port-everywhere
Oct 28, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-rendezvous-port-everywhere

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, gloo) has failed twice with every rank dying before the test starts:

torch.distributed.DistNetworkError: The server socket has failed to listen on any local network address. port: 45095, useIpv6: false, code: -98, name: EADDRINUSE
AssertionError: rank exit codes [1, 1]

#14334 fixed this race by adding tests/_rendezvous_port.free_port():

  • It draws MASTER_PORT from below the kernel's ephemeral range (32768-60999 on Linux), in a slice per xdist worker.
  • So neither another worker nor an outgoing gloo connection can take the port between the test releasing it and rank 0 listening on it.

That PR moved 21 tests onto the helper, but 15 distributed tests still pick their port with bind(("127.0.0.1", 0)), tests/test_tp_native_gloo.py among them. Both failing ports above are inside the ephemeral range.

Change

  • 14 test files: their local _free_port() now delegates to tests._rendezvous_port.free_port(), the same three lines the other 21 files use, and their now-unused socket imports are dropped:
    • test_tp_native_gloo.py, test_pp_native_gloo.py, test_pp_fsdp2_gloo.py, test_parallel_general_gloo.py
    • test_moe_dw_accumulate.py, test_ddp_find_unused_default.py, test_ddp_comm_defaults.py
    • test_fast_inference_torchrun_agreement.py, test_cudnn_sdpa_grad_layout_dtensor.py
    • five under tests/python/: block compile DDP, GRPO DDP sync, plain trainer DDP, sentence transformer DDP and FSDP2 save
  • tests/test_token_budget_batches.py: the inline bind(0) before MASTER_PORT now uses the helper.
  • tests/test_rendezvous_port_everywhere.py (new): any test outside tests/studio that sets up a torch rendezvous (MASTER_PORT, master_port, init_process_group or TCPStore) must either define _free_port through the helper or not bind port 0 at all.
    • Studio tests are out of scope: their ports are for HTTP servers they start themselves.
    • It includes self-tests for both shapes of the mistake, and a check that the helper stays below the ephemeral range for several worker ids.

Testing

  • tests/test_rendezvous_port_everywhere.py: 6 passed.
  • Sabotage: with tests/test_tp_native_gloo.py and tests/test_token_budget_batches.py restored from main, the guard fails and names both files.
  • The 14 converted files plus tests/test_token_budget_batches.py and the new guard, under -n 4: 243 passed, 2 skipped. On main the same 14 files plus test_token_budget_batches.py (without the guard): 237 passed, 2 skipped.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T06:02:34.777448Z 0869d2a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 0869d2a035

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 3c63f72 into main Oct 28, 2026
0 of 15 checks passed
@danielhanchen
danielhanchen deleted the ci-rendezvous-port-everywhere branch October 28, 2026 06:08
danielhanchen added a commit that referenced this pull request Oct 28, 2026
#15745)

## Summary

`Repo tests (CPU, rest)` fails on main with three guard failures. It
shows on every staging CI run of recent PRs (#15613, #15615, #15673 and
others), whatever the PR changes:

```
tests/test_rendezvous_port_everywhere.py::test_distributed_tests_take_their_port_from_the_shared_helper
    tests/test_gc_skip_auto_dist_cells.py: _free_port does not use tests._rendezvous_port
    tests/test_gc_skip_auto_dist_gloo.py: _free_port does not use tests._rendezvous_port
tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[5]
    tests/test_mamba_fused_lora_adapters.py:464: read_text()
tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[13]
    tests/test_refresh_moved_layer_devices.py:81: read_text()
```

These tests landed around the same time as the guards that now catch
them:
- 570b9b8 added the two `gc_skip_auto_dist` gloo tests with their own
`bind(("127.0.0.1", 0))` port picker. That is the ephemeral-range race
that #15679 moved every distributed test off, which produces
`EADDRINUSE`.
- 986558e and 7f3c5a1 read checked-in source with the platform
default encoding, which breaks on Windows once the file gains a
non-ASCII byte.

The guards are right in all three cases, so the tests change, not the
guards.

## Change

- `tests/test_gc_skip_auto_dist_cells.py`,
`tests/test_gc_skip_auto_dist_gloo.py`: `_free_port()` delegates to
`tests._rendezvous_port.free_port()`, the same three lines every other
distributed test uses. The now-unused `import socket` is dropped.
- `tests/test_mamba_fused_lora_adapters.py:464`,
`tests/test_refresh_moved_layer_devices.py:81`: `read_text(encoding =
"utf-8")`.

## Testing

- `tests/test_source_read_encoding.py` +
`tests/test_rendezvous_port_everywhere.py`: 3 failed on main, 22 passed
with this change.
- The four touched test files under `-n 4`: 43 passed, 4 skipped.
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Oct 28, 2026
…d helper (unslothai#15729)

`tests/test_rendezvous_port_everywhere.py::test_distributed_tests_take_their_port_from_the_shared_helper`
fails on main: `test_gc_skip_auto_dist_cells.py` and
`test_gc_skip_auto_dist_gloo.py` (added in unslothai#15545) still bind their own
`127.0.0.1:0` socket for the rendezvous port. unslothai#15679 added the check
right after them, so they were never moved to
`tests._rendezvous_port.free_port()`.

Both `_free_port()` helpers now call the shared helper, and the unused
`import socket` goes.

- `test_rendezvous_port_everywhere.py`: 1 failed / 5 passed on main, 6
passed here.
- `test_gc_skip_auto_dist_gloo.py`: passes (CPU gloo).
`test_gc_skip_auto_dist_cells.py` needs a CUDA device for its NCCL
cases; on a CPU-only host the same 5 fail on main and here ("No CUDA
GPUs are available"), 8 pass.

Tests only; no library or Studio code changes.
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.

1 participant