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
+14
-5
@@ -351,11 +351,13 @@ int build(ArInst* in, int rank, int world, long long max_numel, int dtype_code,
|
||||
sq = r4d_ar_ipc_alloc(kSeqWords(maxb) * 4, 0, handle, &hlen));
|
||||
|
||||
/* This rank's own packed copy, for the rotated 6-bit wire only: the reduce must fold exactly
|
||||
* the bytes it sent. The 6-bit payload is 3/8 of the bf16 message and the scales 1/64, so half
|
||||
* the message plus a thirty-second plus a page is ample. */
|
||||
* the bytes it sent. The 6-bit payload is 3/8 of the bf16 message and the f32 scales 1/32 of
|
||||
* it, laid out from half the slot; a row padded to whole 512-element chunks
|
||||
* (ar_rmsnorm_quant_fp8) adds up to 7 groups' scales a row, so the scales get a sixteenth
|
||||
* (enough for any row of 512 or more) plus a page. ar_rmsnorm_quant checks the fit. */
|
||||
if (in->dtype != 2) {
|
||||
R4D_TRY("ar_ipc_alloc(locpack)",
|
||||
lp = r4d_ar_ipc_alloc(in->slot_bytes / 2 + in->slot_bytes / 32 + 4096, 0,
|
||||
lp = r4d_ar_ipc_alloc(in->slot_bytes / 2 + in->slot_bytes / 16 + 4096, 0,
|
||||
handle, &hlen));
|
||||
}
|
||||
|
||||
@@ -1353,11 +1355,18 @@ static int rad_ar_rmsnorm_quant(const RadArgs* a, RadStream s, bool hi8) {
|
||||
if (wire != 0 && wire != 6) return RAD_E_INVAL;
|
||||
if (wire == 6) {
|
||||
const int ce = r4d_ar_rmsnorm_quant_fp8_chunk_elems();
|
||||
if (ce <= 0 || K % ce) return RAD_E_SHAPE;
|
||||
/* Whole 64-element groups a row; the last 512-element chunk may be partial (padded). */
|
||||
if (ce <= 0 || K % 64) return RAD_E_SHAPE;
|
||||
/* This rank's packed-half side buffer exists for every bf16 instance; missing means a
|
||||
* broken init. */
|
||||
if (!in->locpack) return RAD_E_STATE;
|
||||
if (wpo) return RAD_E_UNSUPPORTED; // the post-norm is the exact wire's only
|
||||
/* The padded message must fit: payload (3/4 byte an element) in the peer slot's half and
|
||||
* in locpack's, the bf16 scales in the slot's other half, the f32 ones in locpack after
|
||||
* half the slot (its allocation: a sixteenth of the slot plus a page). */
|
||||
const long long chunks = M * ((K + ce - 1) / ce), groups = chunks * (ce / 64);
|
||||
if (chunks * (ce * 6 / 8) > in->slot_bytes / 2 || groups * 2 > in->slot_bytes / 2 ||
|
||||
groups * 4 > in->slot_bytes / 16 + 4096)
|
||||
return RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
R4dArCfg cfgv;
|
||||
|
||||
Reference in new issue
Block a user