Skip to content

Diffusion DDP tests: rendezvous through a FileStore, not a port picked up front (intermittent diffusion-shard timeout) - #18885

Merged
danielhanchen merged 1 commit into
mainfrom
fix/diffusion-ddp-test-filestore
Nov 22, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/diffusion-ddp-test-filestore

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

(Python 3.13, diffusion) fails intermittently on unrelated PRs with the same test:

studio/backend/tests/test_diffusion_ddp.py::test_all_reduce_averages_grads_and_loss_and_flags
tests/test_diffusion_ddp.py:55: in _spawn
    codes = [p.wait(timeout = timeout) for p in procs]
E   Failed: Timeout (>330.0s) from pytest-timeout.

It is the failing test in 3 of the last 6 failed Backend CI runs (studio-wan-vae-2frame, audio-cpp-accelerator-chosen-install, perf/r37-translate-history-memo) and on #18851 and #18702.

The test (from #18771) spawns two gloo ranks and joins them through a TCPStore on a port that _port() found free by binding and closing a socket in the parent. The port is only bound for real later, by rank 0 in its own process, after torch has imported. Under xdist another worker can take that port in the meantime. Rank 0 then fails to bind, rank 1 waits out the store's 300 s timeout, and pytest-timeout kills the test at 330 s. In the failing logs only one of the spawned pairs ever prints the gloo "connected to 1 peer ranks" lines.

Fix

The two spawned ranks rendezvous through a FileStore in a fresh temp directory per spawn (same 300 s store timeout), so there is no port to race for. diffusion_ddp's gate only uses store.set / store.wait, which FileStore provides. Production code is unchanged; this is the test harness only.

Testing

  • studio/backend/tests/test_diffusion_ddp.py: 22 passed, including the gradient all-reduce and the two-rank train spawns.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:05:41.193357Z 5cc4d06 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 5cc4d065a3

ℹ️ 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 5b4b836 into main Nov 22, 2026
@danielhanchen
danielhanchen deleted the fix/diffusion-ddp-test-filestore branch November 22, 2026 13:11
danielhanchen added a commit that referenced this pull request Nov 22, 2026
…tuck rank stack (all-reduce timeout) (#18908)

## Summary


`studio/backend/tests/test_diffusion_ddp.py::test_all_reduce_averages_grads_and_loss_and_flags`
still times out now and then after #18885. It failed again on the
Imagineer99 staging run for #18900, on base `da4430f`, which includes
#18885. That run settles what #18885 got wrong: both ranks print `[Gloo]
Rank N is connected to 1 peer ranks` before the hang, so the rendezvous
works and a port race was not the cause. (The `FileStore` rendezvous
from #18885 is still fine to keep.) The ranks stall after connecting,
and pytest-timeout then kills the test with only the parent's `p.wait()`
stack in the log, so nothing says where.

I could not reproduce it here: 24 runs, 12 at a time, all passed in
about 10 s each.

## Changes (test harness only)

- Each spawned rank calls `dist.destroy_process_group()` on the way out,
as the real workers do in `DistContext.close()`. The children used to
exit with a live gloo group, and that teardown at interpreter exit is
the most likely place for an intermittent stall.
- Each rank arms `faulthandler.dump_traceback_later(240, exit = True)`,
below the 330 s pytest-timeout. If a rank is still running at 240 s it
prints every thread's stack and exits non-zero, `_spawn`'s exit-code
assert fails, and the log says exactly where it was stuck. If this does
not remove the flake, the next failure is self-diagnosing.

## Testing

- `studio/backend/tests/test_diffusion_ddp.py`: 22 passed.
- Sabotage: with rank 1 made to sleep and the dump window shortened to 8
s, the test fails in 19 s with `assert [1, 1] == [0, 0]` and both ranks'
stacks, pointing at the line in `_child_grads` where each was waiting.
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