Skip to content

ggml-rpc: reduce a large mesh partial by a reduce-scatter and an all-gather - #35

Merged
lukekim merged 9 commits into
spiceai-b11999from
lukim/rdma-mesh-scatter
Nov 9, 2026
Merged

lukekim merged 9 commits into
spiceai-b11999from
lukim/rdma-mesh-scatter

Conversation

@lukekim

@lukekim lukekim commented Nov 9, 2026 •

Copy link
Copy Markdown

Follows #34, merged as 6fbeb5e: this branch has spiceai-b11999 merged 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):

  • Reduce-scatter, then all-gather: a partial over 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.
  • Same bits: every rank ends with the sum in rank order, the same bits as when each rank summed every partial whole. Each rank now sends, receives and sums only its share, a third of the partial on three ranks.
  • Flow control: both phases go in pieces of at most 1 MiB, each sent to every peer before any is received, as the chunked exchange does. So a link never holds more than two unread pieces, which fits the RDMA receive ring.
  • Agreement: the ranks agree on it when the mesh forms, through a second bit beside the chunks' (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=0 on any rank keeps every partial whole.
  • 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.
  • Unchanged: decode-sized partials (1 MiB or less) and the pairwise comm.

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:

floats world 2 world 3 world 6
300007 1, 1 1, 1, 1 (the last share 41 floats shorter) 1 each
786448 2, 2 2, 2, 1 1 each
4000037 8, 8 6, 6, 6 3 each

Runs on three DGX Spark (GB10) nodes, every link RDMA:

servers and client mesh of all endpoints two-rank mesh pairwise exit
b20c7a2, three ranks 4/4 ok 4/4 ok 4/4 ok 0
#34, three ranks 4/4 ok 4/4 ok 4/4 ok 0
this PR, three ranks 5/5 ok 5/5 ok 5/5 ok 0
this PR, each share summed in reverse rank order, three ranks, two runs 2/4, 2/4 4/4, 4/4 4/4, 4/4 1, 1
this PR, pieces counted from the shortest share, three ranks, two runs 4/5, 4/5 5/5, 5/5 5/5, 5/5 1, 1
b20c7a2, six ranks 5/5 ok 5/5 ok 5/5 ok 0
this PR, six ranks 5/5 ok 5/5 ok 5/5 ok 0

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.1 over the NIC's RoCE loopback and the others on their shared link, so every pair is on RDMA, and each server logs over RDMA for 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:

world 3, 300007 floats, rank 0: 97442 floats differ from the rank-order sum, first at 2 (-640.950439, want -640.9505)
world 3, 300007 floats, rank 1: 97442 floats differ from the rank-order sum, first at 2 (-640.950439, want -640.9505)

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:

world 3, 786448 floats, rank 0: 32 floats differ from the rank-order sum, first at 262144 (-786.634827, want 179.621887)
world 3, 786448 floats, rank 1: 32 floats differ from the rank-order sum, first at 262144 (0, want 179.621887)

The test's status line for the next size reads FAILED as 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.

  • Unchanged: decode-sized partials (1 MiB or less) and the pairwise comm.

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:

servers and client three-rank mesh two-rank mesh pairwise exit
b20c7a2 4/4 ok 4/4 ok 4/4 ok 0
#34 4/4 ok 4/4 ok 4/4 ok 0
this PR 4/4 ok 4/4 ok 4/4 ok 0
this PR, each share summed in reverse rank order, two runs 2/4, 2/4 4/4, 4/4 4/4, 4/4 1, 1

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:

world 3, 300007 floats, rank 0: 97442 floats differ from the rank-order sum, first at 2 (-640.950439, want -640.9505)
world 3, 300007 floats, rank 1: 97442 floats differ from the rank-order sum, first at 2 (-640.950439, want -640.9505)

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:

[rpc_comm_mesh_agree] rank 1: rank 0 answered the mesh's agreement with something else, so the mesh comm is not initialized; every rank must run a build that agrees on it

The pairwise comm, which has no agreement, still passes 4/4.

Opt-out: this PR on every rank, with GGML_RPC_COMM_SCATTER=0 on rank 2 only. The three-rank mesh agrees on whole partials, and every rank logs the mesh exchanges partials over 1048576 bytes in pieces sent to every peer at once. The two-rank mesh, of ranks 0 and 1, logs the 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 PR

Setup: 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:

arm cold 59 / 966 / 3754 tokens, ms cold 3754, max of 3, ms per prompt token, 966→3754, ms warm 3754, ms
#34 (1) 285 / 1530 / 4992 5011 1.242 120
this PR (1) 283 / 1360 / 4322 4478 1.062 124
this PR (2) 284 / 1344 / 4320 4355 1.067 120
#34 (2) 286 / 1486 / 4850 4908 1.207 121
this PR (3) 289 / 1382 / 4392 4416 1.080 121

Decode, 8 prompts × 200 tokens, temperature 0, two counted runs per session:

arm pooled tok/s time to 200 tokens, max of 8, s texts equal to the first #34 run
#34 (1) 60.18, 60.08 3.79, 3.90 8/8, 8/8
this PR (1) 60.90, 59.45 3.78, 3.89 8/8, 8/8
this PR (2) 60.22, 60.33 3.82, 3.79 8/8, 8/8
#34 (2) 61.77, 59.47 3.70, 3.91 8/8, 8/8
this PR (3) 60.77, 62.12 3.91, 3.73 8/8, 8/8

Multi-turn, 4 conversations × 5 turns × 200 tokens, the whole history re-sent each turn (n=20 turns):

arm concurrency 1: output tok/s, first token P50 / P99 ms, turn P99 s concurrency 2: output tok/s, first token P50 / P99 ms, turn P99 s
#34 (1) 54.28, 686 / 867, 4.13 56.99, 3953 / 4240, 7.38
this PR (1) 54.16, 665 / 850, 4.08 57.51, 3907 / 4117, 7.33
this PR (2) 54.16, 649 / 867, 4.19 57.37, 3915 / 4136, 7.35
#34 (2) 54.12, 682 / 919, 4.28 57.37, 3943 / 4136, 7.40
this PR (3) 54.01, 645 / 884, 4.21 57.23, 3918 / 4209, 7.49

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:

floats b20c7a2, µs #34, µs this PR, µs
1310720 (a 512-token partial, 5 MiB), ×300 2737.7, 2761.7 1717.1, 1720.7 1099.1, 1073.3
2560 (one decode token), ×2000 16.4, 16.4 16.0, 16.1 16.1, 16.0
10240 (four decode tokens), ×2000 26.4, 26.4 26.3, 26.4 26.2, 26.4

The profile, a cold 3754-token read, Nsight Systems on two of the three ranks' ggml-rpc-server, three windows each:

b20c7a2 #34 this PR
window per rank, ms 5439–5482 4769–4934 4260–4306
waiting on all-reduces, ms 1927–2023 1310–1460 818–887
5 MiB all-reduce wait, P50 / P99, µs 2524–2648 / 3978–4209 1628–1801 / 3188–3435 926–1031 / 2462–2607
GPU kernels, ms 2250–2514 2281–2499 2292–2511

What the numbers say:

  • Prompt reads: 10–15% faster than ggml-rpc: keep several RDMA sends in flight #34 per prompt token from 966 tokens up (1.06–1.08 against 1.21–1.24 ms), and 20–23% under b20c7a2's 1.36–1.38 ms. That is level with one Spark at the same batch: 1.09 ms per token for single-node llama-server, the same model and b20c7a2's build, measured 2026-11-08.
  • Decode: inside the noise, with every text identical: a decode partial is under 1 MiB and takes the same path as before.
  • Multi-turn at concurrency 1: first-token P50 645–665 against 682–686 ms, with the P99s overlapping (850–884 against 867–919). At concurrency 2 the arms are within the noise.
  • What's left: all-reduces still hold each rank's GPU for 0.82–0.89 s of a 4.3 s read. Of the rest, the kernels take 2.29–2.51 s per rank against one Spark's 4.35 s, and 0.7–1.0 s is other GPU idle.

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.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 02:07
@github-actions github-actions Bot added the ggml label Nov 9, 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.

🔵 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=0 opt-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.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 03:00
@lukekim

lukekim commented Nov 9, 2026

Copy link
Copy Markdown
Author

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 ggml-rpc.cpp, transport.cpp and test hash 1b03141b518a, ede2f724941e and ac589901cc07.

Uneven piece counts: test-rpc-comm-mesh now also reduces 786448 floats. Over three ranks that size makes shares of 262160, 262160 and 262128 floats, which go as 2, 2 and 1 pieces. The other sizes have equal piece counts:

floats world 2 pieces world 3 pieces world 6 pieces
300007 1, 1 1, 1, 1 1 each
786448 2, 2 2, 2, 1 1 each
4000037 8, 8 6, 6, 6 3 each

Three DGX Sparks, one server each, every link RDMA:

  • This PR: 15/15 ok, exit 0, and every rank logs the mesh reduces partials ….
  • Mutation, two runs: counting the pieces from the shortest share, so the longer shares' second piece is never exchanged, fails at 786448 floats on every rank, the same way both times:
world 3, 786448 floats, rank 0: 32 floats differ from the rank-order sum, first at 262144 (-786.634827, want 179.621887)
world 3, 786448 floats, rank 1: 32 floats differ from the rank-order sum, first at 262144 (0, want 179.621887)
world 3, 786448 floats, rank 2: 32 floats differ from the rank-order sum, first at 262144 (0, want 179.621887)

Those are the 16 floats past the first piece of each of the two longer shares. The 4000037 line after it reads FAILED too, but only because the test's status line counts every failure so far: no rank's floats differ at that size.

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 127.0.0.1 over the NIC's RoCE loopback, the others on their shared link. Each server logs over RDMA for all five peers.

  • This PR: 15/15 ok, exit 0. All six ranks agreed on the reduce-scatter (the mesh reduces partials …).
  • b20c7a2: 15/15 ok, exit 0, with every rank exchanging partials whole.

Not run: seven or eight ranks. Three nodes don't split eight ranks evenly, and 8 is the mesh's maximum (RPC_COMM_MAX_WORLD). The phases' ordering doesn't depend on the rank count. Each link carries one piece at a time in each direction, in the order both ends compute from the partial's size, and the all-gather starts only after the rank has read every piece of the reduce-scatter. That part is from code inspection.

@lukekim
lukekim changed the base branch from lukim/rdma-send-ring to spiceai-b11999 November 9, 2026 03:02

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 documented two-unread-piece bound overlooks an extra short piece at the scatter/gather boundary and needs clarification to avoid misleading future RDMA ring sizing.

1 open issue

Review effort: Balanced

Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
…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.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 03:10

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

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

@lukekim

lukekim commented Nov 9, 2026 •

Copy link
Copy Markdown
Author

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:

  • Flow control:
    • Correctness: test-rpc-comm-mesh passes 15/15 at three ranks and at six. Six ranks means two servers per Spark, every pair on RDMA, and every rank agreed on the reduce-scatter.
    • Uneven piece counts: this includes 786448 floats, whose three-rank shares go as 2, 2 and 1 pieces. That is the case where a link holds two full pieces and a short one.
    • Mutations: summing a share in reverse rank order fails, and so does counting the pieces from the shortest share. Each failure is the floats the mutation should break.
    • Load: six sessions with this PR on Qwen3.8 split three ways read 3754-token prompts: three llama-server A/B sessions, two spiced sessions and one profiled llama-server session. The five A/B sessions' saved logs (14 files) have no abort, wc error, lost rank, GGML_ASSERT or SIGSEGV, and every decode text equals the baseline build's, 8/8. The profiled session finished its three reads, and its logs weren't kept.
  • Rollout compatibility:
    • Mixed builds: this PR's server on one rank and ggml-rpc: keep several RDMA sends in flight #34's on the other two. The mesh refuses to form, and ggml-rpc: keep several RDMA sends in flight #34's ranks log rank 0 answered the mesh's agreement with something else, so the mesh comm is not initialized; every rank must run a build that agrees on it. The pairwise comm still passes.
    • Opt-out: GGML_RPC_COMM_SCATTER=0 on one rank makes the three-rank mesh exchange whole partials, and all 12 checks pass.

This PR now waits on a maintainer's review.

@lukekim lukekim self-assigned this Nov 9, 2026
@lukekim
lukekim merged commit 250bdf9 into spiceai-b11999 Nov 9, 2026
21 of 28 checks passed
vatsalp2008 pushed a commit to vatsalp2008/spiceai that referenced this pull request Nov 11, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants