Skip to content

ggml-rpc: abort a lost client's NCCL communicators so a stuck rank recovers - #6

Merged
lukekim merged 2 commits into
spiceai-b11803from
lukim/b11803-rpc-nccl-watchdog
Oct 25, 2026
Merged

lukekim merged 2 commits into
spiceai-b11803from
lukim/b11803-rpc-nccl-watchdog

Conversation

@lukekim

@lukekim lukekim commented Oct 25, 2026 •

Copy link
Copy Markdown

Summary

With GGML_RPC_COMM_NCCL=1 (#5), killing the client mid-decode sometimes leaves one ggml-rpc-server rank stuck: it never logs Client connection closed and never accepts another client. Its main thread is in rpc_server::get_tensor → rpc_server::sync_all_backends → cudaStreamSynchronize, behind an NCCL all-reduce that the client sent to this rank but not to the peer. The peer has already aborted its communicator, so the collective never completes, the thread never reads the closed socket again, and the abort in ~rpc_server never runs.

  • A watchdog thread per client connection waits for the client's TCP connection to close (POLLRDHUP; the RDMA transport keeps that socket open and idle after the upgrade) and then aborts the client's NCCL communicators (rpc_server::abort_comms), which ends the stuck collective. The serving thread then fails its next send or receive as before. The watchdog keeps aborting after the close, so a communicator whose initialization finishes later is aborted too, and it runs only where a close can be seen without reading the socket (Linux).
  • comm_mutex orders the abort against the serving thread's own NCCL calls (initialization, all-reduce enqueue, free), so neither uses a communicator the other freed. An aborted communicator makes later all-reduces fail instead of falling back to the host path.
  • The server sets NCCL_RUNTIME_CONNECT=0 at start unless it is already set. NCCL 2.22 and later otherwise connect a channel inside the first ncclAllReduce that uses it, waiting for the peer without a timeout while comm_mutex is held, where the watchdog could not abort it.
  • Not covered, and listed in the code: a COMM_FREE whose ncclCommDestroy waits behind such a collective, a COMM_INIT that only one rank received, a peer server that dies while the client lives, and a client host that vanishes without closing the connection. The COMM_INIT case extends to rank 1 failing to reach rank 0's address: rank 0's accept() for the pairwise connection has no timeout while rank 1 gives up after about 5 s (from reading rpc_server::comm_init; not reproduced here).

Evidence

Kill test, 2026-10-25: Qwen3.8-Flash-Next UD-Q3_K_XL split over two DGX Sparks with -sm tensor across two ggml-rpc-servers on RoCE addresses, llama-server on a third Spark with GGML_RPC_COMM_NCCL=1. Each kill sends SIGKILL to llama-server once it has streamed at least 40 tokens (66 to 100 in these runs) and polls both ranks' logs for 30 s; a rank that does not log Client connection closed counts as hung, is dumped with gdb, and both ranks restart for the next kill.

Build Kills Hung ranks
3185bd41 (head of #5, merged as d6d4a25f) 20 4, all rank 0, each with its main thread in rpc_server::get_tensor → sync_all_backends → ggml_backend_cuda_synchronize → cudaStreamSynchronize and the GPU at 96%
012c48f1, 043e5a1d (earlier heads of #5) 7, 5 1, 1, both rank 0 with the GPU at 96%: 012c48f1 with the same backtrace, 043e5a1d with its main thread inside libcuda (gdb could not unwind further)
3df556e1 20 0: every kill, both ranks log aborted the NCCL communicator the client left open and Client connection closed within 1.7 s, and after the 20th a new client loads and replies
71fdd870 (head) 10 0: every kill, both ranks log the same two lines within 1.7 s, and after the 10th a new client loads and gives the same 128-token reply as every run above

Decode speed, 2026-10-25: DeepSeek-V4.1-Flash UD-Q2_K_XL split over the same two Sparks with every switch from #5 on and DSpark drafting (3 tokens). Each row is one llama-server load running the same 8 prompts twice at temperature 0, with the loads in the order shown. In every arm, all 8 replies equal the reference run's. The rows for this branch ran a build of its tree (bea6035b).

Build tok/s, first and second run P99 gap between streamed tokens, second run
this branch 33.26, 34.80 86.0 ms
3185bd41 (head of #5) 31.42, 32.19 93.8 ms
3185bd41 (head of #5) 33.97, 34.86 85.0 ms
this branch 32.05, 32.10 94.3 ms
this branch, NCCL_RUNTIME_CONNECT=1 34.71, 35.33 82.7 ms

Two loads of the same build differ by up to 8% (32.10 vs 34.80 tok/s). On the second runs this branch averages 33.45 tok/s and #5 averages 33.53, so the change costs no decode speed measurable on this rig. NCCL_RUNTIME_CONNECT=1, NCCL's default, lands within the same spread as the 0 this branch sets.

71fdd870 adds only one change to 3df556e1: comm_init takes comm_mutex to read the status it logs. Its kill-test row ran on a build of 71fdd870 itself (2026-10-25, 08:21 to 08:31 UTC), where both ranks print that status line (NCCL all-reduce on) for every client, and the build passes the backend tests for #5's switches (DSV4_HC_WEIGHTS, DSV4_HC_COMB, MUL_MAT/MUL_MAT_ID with IQ3 types). The decode runs above ran on 3df556e1's tree and were not repeated: the new lock is taken once per connection, not per token.

…o a rank blocked behind a collective the peer never joins recovers
Copilot AI balanced review requested due to automatic review settings October 25, 2026 05:30
@github-actions github-actions Bot added the ggml label Oct 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The communicator status log reads shared state without synchronization while the watchdog can modify it, causing a C++ data race.

1 open issue
What changed in this PR

This PR extends the opt-in RPC NCCL path with disconnect recovery so a lost client does not leave a server stuck behind an unfinished collective.

Changes:

  • Adds non-consuming peer-close detection and a Linux client watchdog.
  • Synchronizes communicator access and rejects all-reduces after an abort.
  • Defaults NCCL_RUNTIME_CONNECT to 0 unless explicitly configured.
File Description
ggml/​src/​ggml-rpc/​transport.h Declares peer-close detection methods.
ggml/​src/​ggml-rpc/​transport.cpp Implements polling for connection closure without reading data.
ggml/​src/​ggml-rpc/​ggml-rpc.cpp Adds watchdog recovery, communicator locking, and the NCCL connection default.

Review effort: Balanced

Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
The client watchdog can abort the communicator and set state.nccl to null under comm_mutex while the serving thread
is still finishing COMM_INIT, so the status log's unlocked read of state.nccl was a data race. Read it under the same
lock; no other lock is held at that point.
Copilot AI balanced review requested due to automatic review settings October 25, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Cross-thread NCCL teardown needs final human review despite successful hardware kill tests, and the latest locking change has only been compile-checked.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@lukekim

lukekim commented Oct 25, 2026

Copy link
Copy Markdown
Author

Addressed #6 (review): 71fdd870 now has a hardware run, not only a compile.

Kill test on a build of 71fdd870, 2026-10-25 08:21 to 08:31 UTC, with the same rig and harness as the kill-test table in the description:

  • 10 SIGKILLs of the NCCL client mid-decode, after 68 to 77 streamed tokens: 0 hung ranks. Every kill, both ranks log aborted the NCCL communicator the client left open and Client connection closed within 1.7 s.
  • Each rank's log has 11 [comm_init] device 0 NCCL all-reduce on lines (the status this commit reads under comm_mutex) and 11 pairwise joins, one per client. It also has 10 aborts and no errors.
  • The client after the 10th kill loads and replies with the same 128-token text as every earlier kill-test run (byte-identical).
  • The build passes the backend tests for Add opt-in switches for faster two-rank DeepSeek-V4 decoding (Spice.ai) #5's switches: DSV4_HC_WEIGHTS 3/3, DSV4_HC_COMB 11/11, and MUL_MAT_ID 16/16 and MUL_MAT 98/98 with IQ3 types, with and without the small-K path.

I added the row to the description's kill-test table. The decode runs there were not repeated, since the new lock is taken once per connection, not per token. The human review of the cross-thread teardown that the summary asks for is still open.

@lukekim lukekim self-assigned this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants