Skip to content

Skip interpreter teardown in the DDP trainable-embeddings worker - #18238

Merged
danielhanchen merged 1 commit into
mainfrom
ci/ddp-embeddings-worker-teardown
Nov 18, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/ddp-embeddings-worker-teardown

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Skip interpreter teardown in the DDP trainable-embeddings worker

tests/test_ddp_find_unused_default.py::test_trainable_embeddings_train_under_ddp_reentrant_checkpointing has hung on Repo tests (CPU, rest-2) twice: on #12258, and on #18220, whose base is current main.

E   Failed: ['.../tests/_ddp_trainable_embeddings_worker.py', '.../ddp'] hung past 150s:
E   [Gloo] Rank 0 is connected to 1 peer ranks. ...
E   RANK_OK find_unused=FalseRANK_OK find_unused=False

Both ranks had finished. They printed RANK_OK after writing their results, and then the processes never exited. Locally the whole test takes about 12 s.

Cause

After RANK_OK, tests/_ddp_trainable_embeddings_worker.py calls dist.destroy_process_group() and returns to normal interpreter teardown. The repo's other gloo workers do not do that. tests/test_tp_native_gloo.py, test_tp_host_input_embedding_gloo.py, test_sharded_load_bnb4_gloo.py, the pp_*_gloo workers and others all:

  • barrier before tearing the group down, because rank 0 hosts the TCPStore;
  • call os._exit(0) once results are saved, because interpreter teardown can wedge or abort on a gloo C++ thread after the work is done.

This worker predates that pattern. That is the failure seen here: the run is finished, but the process never exits.

I could not trigger the CI hang itself: 48 local torchrun launches, 8 in parallel, all exited 0. So the hang is shown with an injected teardown wedge (see Verification).

Fix

On the distributed path, after RANK_OK, the worker now does what the other gloo workers do:

  • dist.barrier(), then dist.destroy_process_group();
  • flush stdout and stderr, then os._exit(0).

Nothing before RANK_OK changes. That includes the training steps, the result files and the single-process reference run. The test's assertions are unchanged, and a rank that fails before RANK_OK still exits non-zero.

Verification

  • tests/test_ddp_find_unused_default.py: 63 passed.
  • Sabotage check: after RANK_OK on the distributed path, I injected a thread that never ends, standing in for a teardown thread that wedges.
    • main: hung past 150s with both RANK_OK lines printed, which is the CI signature.
    • This change: the test passes in 10.8 s.
  • ruff is clean.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 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-18T02:56:42.830708Z 721c18b 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. Keep it up!

Reviewed commit: 721c18b6f3

ℹ️ 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 c67b972 into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the ci/ddp-embeddings-worker-teardown branch November 18, 2026 02:58
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