libr4d: a three-rank two-shot all-reduce, with shards one word uneven

At three ranks the exact all-reduce was the one-shot at every size: the two-shot required the
message to shard evenly, and a 2048-wide bf16 row is 256 16-byte words, a multiple of 3 only one
step in three. Every prefill chunk therefore sent twice its message per rank where the two-shot
sends 4/3.

The two-shot kernel now splits n16 words into shards of n16/ws, the first n16 % ws one word longer,
with region B at the longest shard. At 4 and 8 ranks every message the entries accept divides, so
nothing there changes. ar_twoshot_3rank_exact takes the band above R4D_AR_WIDE_ONESHOT_MAX_ELEMS the
way the 4- and 8-rank rows do. Its fold is the one-shot's -- fp32, ascending rank order -- so the
band edge between the two rows changes no bits.

r4d_selftest runs both three-rank rows through a per-element oracle (bf16 and fp32, words % 3 of 0,
1 and 2, 16 words to the 20971520-element ceiling, in and out of place, back to back on one
instance).
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-08 17:16:10 +02:00
1 parent a97985e7c2
commit 6b4a67f52e
7 files changed
+282 -41

No files matched your search

+6
View File
@@ -127,6 +127,12 @@ radiance --model qwen3.8-next-flash-fp8-iq4r-moe.rad --tp 3 --tp-wire exact --ma
--num-speculative-tokens 3 --max-num-batched-tokens 2048
```
The exact all-reduce at three ranks is the wide family's one-shot up to 1 MiB a message (every
decode step) and its two-shot above it (every prefill chunk): reduce-scatter + all-gather, which
sends 4/3 of the message per rank instead of twice it. A message rarely divides into thirds -- a
2048-wide bf16 row is 256 16-byte words -- so the first `words % 3` shards take one word more.
Both rows fold in fp32 in ascending rank order, so the band edge between them changes no bits.
The log says what the geometry did:
```