Archived
gemma3 + libr4d: the fused all-reduce junction on the lossy wire, for rows of whole 64-element groups
Under --tp-wire wht6 a TranslateGemma step of 2-3 sequences (16-24 rows) sent its junction as three launches (the standalone lossy all_reduce, rmsnorm, rmsnorm_quant_fp8): the fused ar_rmsnorm_post_quant_fp8 sent the exact wire only, and the compressed fused form needed a row of whole 512-element chunks, which Gemma 3 27B's 5376 is not (10.5). - r4d_fused_quant_fp8.hip: a row of whole 64-element groups that is not whole chunks ends in a partial chunk whose missing groups go out as zeros and are not stored back. Every real group is the same 64 elements as in the flat message, so its bytes and the sum are the standalone wire's. The (row, chunk) mapping is a template parameter (PAD, wire 6 only), so a row of whole chunks (Qwen3.8's 5120) runs exactly the code it ran before; as a runtime branch it cost a Qwen3.8 x4 step 1.3-1.6 %. POST (the sandwich post-norm) on either wire. - r4d_ar_entry.hip: K % 64 instead of K % 512 for wire 6, a size check of the padded message against the slot and the local pack, and the local pack's scale region a sixteenth of the slot instead of a thirty-second (padding adds up to 7 groups a row: a 2048-row prefill chunk would have overrun the old size). - gemma3: the junction declares its lossy twin (op_ar6) and takes it up to kAr6MaxRows (24); a taller step keeps the standalone all-reduce, which spread over more blocks wins there (the fused kernel gives a block one row). TranslateGemma-27B MXFP4 + DFlash2, 2x R9700, --tp-wire wht6 --draft-short-from 8, greedy, aggregate tok/s, two rounds, junction limit never / 24 / any: 2 streams (16 rows) 350.7 346.2 / 370.4 367.0 / 357.7 356.0 3 streams (24 rows) 455.8 451.2 / 462.8 460.6 / 437.3 436.8 4 streams (32 rows) 553.7 553.6 / 553.9 560.2 / 521.0 523.0 8 streams (32 rows) 717.4 718.0 / 716.7 720.8 / 662.4 661.9 So 2 streams +6 %, 3 +2 %, 4 and 8 unchanged. Bit identity: with --tp-wire-min-kb 1 (one stream's steps go out lossy) the fused path gives the unfused one's greedy top-5 logprobs, 300 of 300 tokens, max |d| 0, on two pieces (x1 there 197.6 -> 212.6 tok/s). Qwen3.8-27B MXFP4: 300 of 300 identical on two prompts, speed unchanged. Tests: arch_test (the lossy-wire junction test now also expects a 24-row step to fuse through the twin, other op instances than the 8-row step's, and the 64-row prefill to stay unfused). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9497bf9061
commit
812cdeceb0
6 files changed
+156
-45
No files matched your search
+28
-5
@@ -8226,10 +8226,12 @@ TEST(gemma3_without_fused_junctions_every_linear_quantises_into_what_it_reads) {
|
||||
CHECK(quant >= 2 * (int)m.layers.size());
|
||||
}
|
||||
|
||||
/* Under a lossy --tp-wire the fused all-reduce junctions, which send the exact wire only, still
|
||||
* serve the steps whose message goes out exact anyway: a decode step's few rows fold every
|
||||
* junction's all-reduce in, while a prefill chunk above --tp-wire-min-kb keeps the lossy
|
||||
* all-reduce, unfused. Both families: the MXFP4 trunk's fp8 junction and a w4a8 trunk's int8 one. */
|
||||
/* Under a lossy --tp-wire a decode step's few rows, whose message goes out exact, fold every
|
||||
* junction's all-reduce in. On the MXFP4 trunk a lossy step up to kAr6MaxRows (24) does too,
|
||||
* through the fp8 junction's lossy twin (ar_rmsnorm_post_quant_fp8 at wire 6; TranslateGemma's
|
||||
* 5376-wide row is whole 64-element groups, its last 512-element chunk padded); a taller one, like a
|
||||
* prefill chunk, keeps the lossy all-reduce, unfused. A w4a8 trunk's int8 junction sends the exact
|
||||
* wire only. Both families: the MXFP4 trunk's fp8 junction and a w4a8 trunk's int8 one. */
|
||||
TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
MetaKV mk = gemma3_meta();
|
||||
const RadEncoding mx = rad_enc_affine(RAD_FP4E2M1, RAD_E8M0, 1, rad::arch::RAD_MX_GROUP);
|
||||
@@ -8244,7 +8246,7 @@ TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
ctx.tp_wire_min_bytes = 128 * 1024;
|
||||
REQUIRE_EQ(gemma3::declare(&b, mk.meta(), &ctx), RAD_OK);
|
||||
const gemma3::Model& m = gemma3::g_model[rank];
|
||||
if (is_mx) CHECK(m.fuse_mx && m.fuse_mx_ar);
|
||||
if (is_mx) CHECK(m.fuse_mx && m.fuse_mx_ar && m.fuse_mx_ar6);
|
||||
else CHECK(!m.fuse_mx && m.fuse && m.fuse_ar);
|
||||
auto issued = [&](const RadCtx& c, std::initializer_list<const char*> names) {
|
||||
int n = 0;
|
||||
@@ -8263,6 +8265,27 @@ TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
CHECK_EQ(fused_pre, 0);
|
||||
/* Every junction the decode step fused is an all-reduce the prefill step issues alone. */
|
||||
CHECK_EQ(issued(*v[1], { "all_reduce" }), issued(*v[0], { "all_reduce" }) + fused_dec);
|
||||
/* 24 rows (24 x 5376 x 2 bytes, above the floor): the MXFP4 trunk fuses the same junctions
|
||||
* through the lossy twin, other op instances than the decode step's; the int8 one cannot. */
|
||||
const auto mid = kit(b, {}, { 24 });
|
||||
const auto vm = run_passes(b, gemma3::step, { mid.get() }, rank, 2);
|
||||
CHECK_PASSES(b, vm);
|
||||
const int fused_mid = issued(*vm[0], { "ar_rmsnorm_quant_i8", "ar_rmsnorm_post_quant_fp8" });
|
||||
if (is_mx) {
|
||||
CHECK_EQ(fused_mid, fused_dec);
|
||||
CHECK_EQ(issued(*vm[0], { "all_reduce" }), issued(*v[0], { "all_reduce" }));
|
||||
std::vector<int> dec_ids;
|
||||
for (const RecIssue& i : v[0]->issues)
|
||||
if (const RecOp* o = b.op_of(i.op); o && o->op == "ar_rmsnorm_post_quant_fp8")
|
||||
dec_ids.push_back((int)i.op);
|
||||
int shared = 0;
|
||||
for (const RecIssue& i : vm[0]->issues)
|
||||
if (const RecOp* o = b.op_of(i.op); o && o->op == "ar_rmsnorm_post_quant_fp8")
|
||||
shared += std::find(dec_ids.begin(), dec_ids.end(), (int)i.op) != dec_ids.end();
|
||||
CHECK_EQ(shared, 0);
|
||||
} else {
|
||||
CHECK_EQ(fused_mid, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user