Repository navigation
ggml-rpc: reduce a large mesh partial by a reduce-scatter and an all-gather - #35
Conversation
A message longer than one 256 KiB chunk was sent chunk by chunk, each chunk copied into the connection's one send buffer and waited for before the next, and a deferred send longer than one chunk fell back to that blocking send. So a mesh all-reduce's 1 MiB pieces went to one peer, then the next, with the link idle while each chunk was copied. A connection now keeps four send buffers. A chunk is copied into the next free one and posted without waiting, and a send waits only when the send queue or every buffer is taken; a blocking send then waits for all of its chunks. A deferred send of any length is posted chunk by chunk, so a rank posts a piece to every peer before either acknowledges it.
…TS's entries for rank 1 With a map of where each of three ranks reaches the others, as a lab whose ranks share a link per pair needs, the two-rank mesh refused the map's rank-2 entries and its checks did not run.
…comm_mesh_hosts does The two-rank runs kept an entry only when it began with "1:", so one the comm accepts for rank 1, such as "01:0=host", was dropped and the two-rank mesh fell back to rank 0's serving host. They now drop only the entries that parse as rank 2 or up, and keep any other, so an entry that does not parse is reported by the comm as before.
…gather Every rank of a mesh received every peer's whole partial and summed all of them, so a 3-rank all-reduce of a 5 MiB prompt partial copied about nine times its size through one CPU thread: the sends into the send buffers, the receives out of the receive ring, and the sum. A partial over RPC_COMM_MESH_EAGER_BYTES now goes as a reduce-scatter and an all-gather. Each rank receives every peer's floats of its own share, sums them in rank order, and sends that sum to every peer, while it receives each other share's sum from its rank. The ranks end with the same bits as before, the sum in rank order, but each sends, receives and sums a third of the partial. Both phases go in pieces sent to every peer at once, as the chunked exchange does, so a link holds at most two unread pieces. The ranks agree on it when the mesh forms, with a bit beside the chunks', and GGML_RPC_COMM_SCATTER=0 on any rank keeps every partial whole.
There was a problem hiding this comment.
🔵 Needs a closer look
The default-on RDMA protocol changes need transport-maintainer validation of cross-phase ordering and receive-ring bounds with uneven piece counts and 4–8 ranks, beyond the supplied 2–3-rank equal-piece-count hardware coverage.
No open issues 🎉
What changed in this PR
Optimizes large RPC mesh all-reduces on top of #34's RDMA send buffering, using reduce-scatter followed by all-gather while preserving rank-order summation.
Changes:
- Splits partials larger than 1 MiB into aligned shares and exchanges them in bounded pieces.
- Adds mesh-wide agreement and
GGML_RPC_COMM_SCATTER=0opt-out. - Integrates the new path into synchronous and asynchronous exchanges, leaving small partials and pairwise communication unchanged.
| File | Description |
|---|---|
ggml/src/ggml-rpc/ggml-rpc.cpp |
Implements share partitioning, reduce-scatter/all-gather, capability agreement, and exchange-path integration. |
Review effort: Balanced
…es go as different numbers of pieces 786448 floats over three ranks makes shares of 262160, 262160 and 262128 floats: two pieces for the first two shares and one for the last.
|
Re: Copilot's review 5820913484, on uneven piece counts and more than three ranks. Both now have runs, at ec5e2b3. That commit merges #34's tip and adds a test size. The builds were made from the sources pushed here, whose Uneven piece counts:
Three DGX Sparks, one server each, every link RDMA:
Those are the 16 floats past the first piece of each of the two longer shares. The 4000037 line after it reads Six ranks: two servers per Spark, so ranks 0–1, 2–3 and 4–5 share a node. Every pair is on RDMA: same-node pairs at
Not run: seven or eight ranks. Three nodes don't split eight ranks evenly, and 8 is the mesh's maximum ( |
…res differ in piece count A rank with nothing to receive in a phase's last round sends that round's pieces and then the first piece of the next phase, or of the next all-reduce, before its peers have read either. So a link holds at most two unread pieces plus a short one, at most 12 of the 24 messages the RDMA transport keeps posted, not two.
There was a problem hiding this comment.
🔵 Needs a closer look
The new default RDMA collective changes wire agreement and cross-phase receive-ring occupancy, requiring maintainer validation of flow control and rollout compatibility on supported hardware because static review cannot confirm the supplied lab results.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
Re: Copilot's review 5821277090, with no open issues, which asks for hardware validation of flow control and of rollout compatibility. Both ran on three DGX Sparks over RDMA, reported in the description:
This PR now waits on a maintainer's review. |
…reduce-scatter mesh all-reduce and opt-in BF16 loads of F32 weights (spiceai#16174) * perf(llama-cpp): pin the llama.cpp fork with RDMA sends in flight and a reduce-scatter mesh all-reduce Moves llama-cpp-src to the squash of spiceai/llama.cpp#35 on spiceai-b11999, which adds spiceai#34 and spiceai#35 to the current pin: - spiceai#34: an RDMA connection keeps several sends in flight, from four send buffers. - spiceai#35: on a mesh of more than two ranks whose links are all RDMA, an all-reduce partial over 1 MiB is reduced by a reduce-scatter and an all-gather. The sums keep the same bits. Both are perf-only, so the fork-patch ledger gains two GAP rows. * perf(llama-cpp): pin the llama.cpp fork with F32 weights that hold only BF16 values loaded as BF16 Moves llama-cpp-src to e53115d2, the squash of spiceai/llama.cpp#36 on spiceai-b11999. An F32 weight of a matrix multiply whose every value is a BF16 value loads as BF16 where every device behind its buffer keeps BF16 values as given and multiplies BF16 weights, so those weights are read at two bytes a value instead of four. docs/dev/fork_patches.md: the new pin, a row for spiceai#36, and spiceai#36 in the perf-only gaps (62 GAP rows). * perf(llama-cpp): keep F32 weights F32 unless LLAMA_NARROW_F32_TO_BF16=1 Pins spiceai/llama.cpp#37's branch (TEMPORARY), which makes spiceai#36's BF16 narrowing opt-in. Narrowing slowed DeepSeek-V4.1's slowest 200-token request from 5.21-5.42 s to 5.89-6.05 s; the RDMA (spiceai#34) and mesh (spiceai#35) patches stay. * perf(llama-cpp): repin spiceai/llama.cpp#37's branch at b04e9151 * perf(llama-cpp): repin to spiceai/llama.cpp#37's squash on spiceai-b11999 (8829a408, same tree as b04e9151)

Follows #34, merged as 6fbeb5e: this branch has
spiceai-b11999merged in, so the diff here is this change alone.What
In a mesh, every rank received every peer's whole partial and summed all of them. On three ranks, a 512-token prompt partial (5 MiB) was copied about nine times its size through the one thread that runs the exchange: once into the send buffers, once out of the receive ring, and again in the sum. With #34's send ring, that all-reduce still took about 1.7 ms. Across the 882 all-reduces of a 3754-token prompt, the GPU sat idle for 1.3–1.5 s of a 4.8–4.9 s read.
The change (
ggml/src/ggml-rpc/ggml-rpc.cpp):RPC_COMM_MESH_EAGER_BYTES(1 MiB) is split into one share per rank (rpc_comm_mesh_share), each starting on a 64-byte boundary. Each rank receives every peer's floats of its own share and sums them with its own in rank order,((p0 + p1) + p2) + …. It then sends that sum to every peer, and receives each other share's sum from the rank it belongs to.RPC_COMM_MESH_AGREE_SCATTER). It needs the chunked exchange, so a mesh with a TCP link keeps exchanging pair by pair.GGML_RPC_COMM_SCATTER=0on any rank keeps every partial whole.Tests
test-rpc-comm-mesh(from #34) checks that every rank ends with the same bits, the F32 sum of the partials in rank order. It runs over the mesh of every endpoint given, a two-rank mesh and the pairwise comm. This PR adds 786448 floats to its 1, 7168, 300007 and 4000037. Three of those sizes take the new path, and over three ranks their shares go as these numbers of pieces:Runs on three DGX Spark (GB10) nodes, every link RDMA:
The b20c7a2 and #34 rows and the reverse-order mutation ran with the four sizes before this PR added 786448.
Six ranks: two servers per Spark. Same-node pairs meet at
127.0.0.1over the NIC's RoCE loopback and the others on their shared link, so every pair is on RDMA, and each server logsover RDMAfor all five peers. With this PR all six agree on the reduce-scatter (the mesh reduces partials …). Seven or eight ranks did not run: three nodes don't split eight evenly, and 8 is the mesh's maximum (RPC_COMM_MAX_WORLD).The reverse order fails at both sizes on the new path, on every rank, with the same bits on all three. So the all-gather spreads one rank's sum, and the test checks the order:
With two ranks the reverse order is the same sum (
a + b == b + a), so those rows pass.Pieces counted from the shortest share fails at 786448 floats on every rank. The 32 floats that differ are the 16 past the first piece of each of the two longer shares:
The test's status line for the next size reads
FAILEDas well, because it counts every failure so far: no floats differ at 4000037.Mixed builds: a peer of a build without the bit answers the agreement as something else, so a mesh that mixes the two builds fails to form, naming the agreement. It doesn't exchange partials two ways.
Tests
test-rpc-comm-mesh(from #34) checks that every rank ends with the same bits, the F32 sum of the partials in rank order, for 1, 7168, 300007 and 4000037 floats, over the three-rank mesh, a two-rank mesh and the pairwise comm. Two of those sizes take the new path. 300007 floats is one piece per share, and its last share is shorter than the others. 4000037 floats is six pieces per share. It ran on three DGX Spark (GB10) nodes, every link RDMA:The reverse order fails at both sizes on the new path, on every rank, with the same bits on all three. So the all-gather spreads one rank's sum, and the test checks the order:
With two ranks the reverse order is the same sum (
a + b == b + a), so those rows pass.Mixed builds: this PR's server on one rank, #34's on the other two. The three-rank and two-rank meshes fail to form, and each #34 rank logs:
The pairwise comm, which has no agreement, still passes 4/4.
Opt-out: this PR on every rank, with
GGML_RPC_COMM_SCATTER=0on rank 2 only. The three-rank mesh agrees on whole partials, and every rank logsthe mesh exchanges partials over 1048576 bytes in pieces sent to every peer at once. The two-rank mesh, of ranks 0 and 1, logsthe mesh reduces partials over 1048576 bytes by a reduce-scatter and an all-gather, …. All 12 checks pass, exit 0.Lab A/B:
llama-server, #34 against this PRSetup: the same as #34: three DGX Spark (GB10) nodes over RDMA RPC,
-sm tensor, the mesh comm, and Qwen3.8-Flash-Next UD-Q3_K_XL with its Q8_0 MTP head (--spec-type draft-mtp --spec-draft-n-max 3),-fa on -c 8192 -b 512 -ub 512 -np 1. Both builds are CUDA builds of the same source, with and without this PR. Each session is fresh. Dates 2026-11-09.Sessions in order: #34, this PR, this PR, #34, this PR. A fourth #34 session failed to start, because rank 2's server could not bind its port (
Failed to create server socket), so one more pair ran after.Prompt read, one-token requests after an unrelated flush, median of 3 per length:
Decode, 8 prompts × 200 tokens, temperature 0, two counted runs per session:
Multi-turn, 4 conversations × 5 turns × 200 tokens, the whole history re-sent each turn (n=20 turns):
All-reduce cost, from
test-rpc-comm-mesh's bench mode (three ranks, a mean per all-reduce, so it measures the transport alone). Interleaved b20c7a2, #34, this PR, this PR, #34, b20c7a2:The profile, a cold 3754-token read, Nsight Systems on two of the three ranks'
ggml-rpc-server, three windows each:What the numbers say:
llama-server, the same model and b20c7a2's build, measured 2026-11-08.