Archived
libr4d: the exact two-shot all-reduce takes every prefill-sized message
R4D_AR_TWOSHOT_WIDE_MAX_ELEMS was 20971520 -- a 4096-token chunk of a 5120-wide residual -- and the band above it went back to the one-shot, which sends (ws-1)*N bytes a rank where the two-shot sends 2*(ws-1)/ws*N. At the default --max-num-batched-tokens 8192, Gemma 4 26B-A4B's attention reduce is 8192 x 2816 = 23M elements and its feed-forward reduce, which carries both branches for their own post-norms, 46M: both over the bound, so every full prefill chunk went one-shot at twice the bytes. --profile-ops on 4x R9700, tp 4, a 20489-token prefill (chunks of 8192, 8192, 4105) fits one link rate across all of it: the attention reduces 16.8 ms the three calls (two one-shot, one two-shot) and the feed-forward reduces ~37 ms (all one-shot), 1.6 s of the 2.7 s prefill. The same rate with every call two-shot is ~9 and ~19 ms: about 0.8 s less a 20k prefill. The bound guards the kernel's int word offsets and nothing else -- the scratch already holds a full message per slot (r4d_ar_entry.hip build()), twice what the two-shot uses -- so it is now 2^28 elements, 2^26 words at fp32. The fold is the one-shot's, fp32 in ascending rank order, so the band edge moves no bits. Fewer bands also means one scratch set less: the old 20971520 band was its own instance, ~335 MiB a rank at tp 4. plugin_test: a 16384-token chunk is two-shot to its end, and the one-shot still takes a message past the bound. r4d_selftest's three-rank pattern walks a 46137344-element message, past the old ceiling. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d95046f6f
commit
a378b41abb
5 files changed
+22
-12
No files matched your search
+6
-2
@@ -418,8 +418,12 @@ void r4d_ar_wide_dims(int* max_blocks, int* nb_design, int* max_peers);
|
||||
// Shards are as even as the word count allows (the first n16 % ws take one more word), so a
|
||||
// message need not divide by the rank count -- at three it almost never does. Regions A and B sit
|
||||
// at 0 and the longest shard, so the slot stride must hold twice that. Above this bound the caller
|
||||
// falls back:
|
||||
enum { R4D_AR_TWOSHOT_WIDE_MAX_ELEMS = 20971520 }; // a 4096-token hidden-5120 prefill chunk
|
||||
// falls back to the one-shot. The bound guards the kernel's int word offsets (the message, the
|
||||
// slot stride) and nothing else: 2^28 elements is 2^26 words at fp32. It was 20971520 -- a
|
||||
// 4096-token chunk of a 5120-wide residual -- which handed every larger prefill chunk back to the
|
||||
// one-shot and its (ws-1)*N send: an 8192-token chunk at Gemma 4's 2816 is 23M elements at the
|
||||
// attention's reduce and 46M at the feed-forward's, which carries both branches.
|
||||
enum { R4D_AR_TWOSHOT_WIDE_MAX_ELEMS = 268435456 };
|
||||
void r4d_ar_twoshot_3rank_exact(long peer_scratch0, long peer_scratch1, long peer_flags0,
|
||||
long peer_flags1, long my_scratch, long my_flags, long seq_ctrs,
|
||||
long slot_stride16, long inp, long out, long n_elem, long dtype,
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
static_assert(R4D_AR_TWOSHOT_WIDE_MAX_ELEMS == 20971520,
|
||||
static_assert(R4D_AR_TWOSHOT_WIDE_MAX_ELEMS == 268435456,
|
||||
"r4d_rows.cpp restates this bound; libr4d changed it");
|
||||
static_assert(R4D_MAX_RANKS == 8, "the 8-rank entry point names exactly seven peers");
|
||||
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@
|
||||
|
||||
/* libr4d's R4D_AR_TWOSHOT_WIDE_MAX_ELEMS, restated because this file must not include r4d.h.
|
||||
* r4d_ar_entry.hip static_asserts the two against each other. */
|
||||
#define R4D_AR_TWOSHOT_WIDE_MAX_ELEMS 20971520
|
||||
#define R4D_AR_TWOSHOT_WIDE_MAX_ELEMS 268435456
|
||||
|
||||
/* The largest message, in elements, a 4- or 8-rank exact all-reduce keeps on the one-shot; above it
|
||||
* the two-shot rows take it. 1 MiB of a 16-bit payload. The one-shot sends (ws-1)*N bytes a rank
|
||||
|
||||
@@ -11241,7 +11241,7 @@ static void ar_three_rank(const Plugin& pl, const std::vector<int>& devs, const
|
||||
* sums correctly. This one gives every element its own value, so a word reduced by the wrong
|
||||
* owner, gathered from the wrong slot or dropped at a short shard's end is a wrong number at a
|
||||
* known index. The sizes walk the uneven split: words % 3 of 0, 1 and 2, from a 16-word message
|
||||
* to the row's 20971520-element ceiling, in place (how every block issues it) and once out of
|
||||
* to past the old 20971520 ceiling, in place (how every block issues it) and once out of
|
||||
* place, back to back on ONE instance so the slot parity and the changing block count are
|
||||
* exercised the way a step's mixed messages exercise them. The oracle is the fold the kernel
|
||||
* claims -- fp32 in ascending rank order, rounded once -- so it is bit for bit, and so it is also
|
||||
@@ -11320,8 +11320,9 @@ static void ar_three_rank_pattern(const Plugin& pl, const std::vector<int>& devs
|
||||
struct Run { const char* dtype; std::vector<int64_t> sizes; int oop; };
|
||||
const std::vector<Run> runs = {
|
||||
/* bf16, the residual: words = numel / 8. 2048 x 2048 rows is words % 3 == 2, x 2049 is
|
||||
* 0, x 2050 is 1; 128 is 16 words (1), 24008 is 3001 (1); 20971520 the ceiling (1). */
|
||||
{ "bf16", { 4194304, 128, 4196352, 24008, 4198400, 20971520, 4194304 }, 2 },
|
||||
* 0, x 2050 is 1; 128 is 16 words (1), 24008 is 3001 (1); 20971520 the old ceiling (1);
|
||||
* 46137344, Gemma 4's feed-forward reduce at an 8192-token chunk, past it (1). */
|
||||
{ "bf16", { 4194304, 128, 4196352, 24008, 4198400, 20971520, 46137344, 4194304 }, 2 },
|
||||
/* fp32: words = numel / 4. 8196 -> 2049 (0), 4100 -> 1025 (2), 1048580 -> 262145 (2). */
|
||||
{ "fp32", { 8196, 4100, 1048580 }, 0 },
|
||||
};
|
||||
|
||||
+10
-5
@@ -901,13 +901,18 @@ TEST(libr4d_resolves_the_all_reduce_by_message_size) {
|
||||
CHECK_EQ(names(bands(2, 1, chunk)),
|
||||
"524288:ar_oneshot_2rank_exact 5242880:ar_oneshot_2rank_exact ");
|
||||
|
||||
/* Above the two-shot's cap the one-shot takes the message back. */
|
||||
/* A 16384-token chunk is two-shot to its end: the two-shot's bound is a guard on its word
|
||||
* offsets, not a prefill size, and a chunk past the old 20971520 went back to the one-shot's
|
||||
* twice-as-heavy send. */
|
||||
CHECK_EQ(names(bands(4, 1, 16384)),
|
||||
"524288:ar_oneshot_4rank_exact 20971520:ar_twoshot_4rank_exact "
|
||||
"41943040:ar_oneshot_4rank_exact ");
|
||||
"524288:ar_oneshot_4rank_exact 41943040:ar_twoshot_4rank_exact ");
|
||||
CHECK_EQ(names(bands(3, 1, 16384)),
|
||||
"524288:ar_oneshot_3rank_exact 20971520:ar_twoshot_3rank_exact "
|
||||
"41943040:ar_oneshot_3rank_exact ");
|
||||
"524288:ar_oneshot_3rank_exact 41943040:ar_twoshot_3rank_exact ");
|
||||
|
||||
/* Above the two-shot's bound the one-shot takes the message back. */
|
||||
CHECK_EQ(names(bands(4, 1, 131072)),
|
||||
"524288:ar_oneshot_4rank_exact 268435456:ar_twoshot_4rank_exact "
|
||||
"335544320:ar_oneshot_4rank_exact ");
|
||||
|
||||
/* A step that never exceeds the bound has one band, and it is the one-shot's. */
|
||||
CHECK_EQ(names(bands(4, 1, 128)), "327680:ar_oneshot_4rank_exact ");
|
||||
|
||||
Reference in new issue
Block a user