Archived
gemma3: a prefill step of one sequence in two pieces, block boundaries on the second lane
qwen35_fp8's pipelined prefill on Gemma 3's MXFP4 trunk at two ranks: every block runs a piece at a time on lane 0 (the attention over its own query bounds and positions, the GeGLU MLP), and the work between two blocks a piece at a time on lane 1 -- the block's all-reduce at `overlap` 1, its post-norm and the fp8 junction (the add and the next norm with its quantiser), after the last block the add, the DFlash2 taps and the final norm. RADIANCE_GEMMA3_PIPE=0 turns it off. - Every q|k|v and gate|up reads one shared E4M3 input pair under the pipeline (the junctions write it), so the second lane's buffers cost one pair, not one a linear (rad_buf_concurrent keeps them live for the whole program). - A window KV group's seqused counts from its rebased first block, so the first piece's cannot be its position: it is the group's seqused less the second piece's rows, computed on the card by a new libr4d op, sub_i32 (y = x - s[0], int32; documented in OPS.md, a selftest case). The first try used the position and faulted on a 12k prompt past the 1024-token window. - G3Linear and G3JunctionFP8 row-sliced forms; each block's overlap all-reduce. Bit for bit the serial step: TranslateGemma's KL recordings at chunk 2048 and one sequence a step (so a document's steps from 1024 rows pipeline) compare equal with the pipeline on and off. Prefill on two R9700s, chunk 2048: 6k tokens 1.27 -> 1.21 s, 12k 2.48 -> 2.42 s; at chunk 1024 (pieces of 512) no gain, so a deployment wants 2048 (against 1024: -9 % / -7 %). arch_test: a 2048-row TP2 step runs in pieces with its collectives on lane 1 and the shared pair; RADIANCE_GEMMA3_PIPE=0 runs it serially. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
57d2cb4043
commit
73b1d039a0
7 files changed
+502
-9
No files matched your search
@@ -6555,6 +6555,71 @@ TEST(gemma3_steps_lint_clean_at_one_and_two_ranks) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The pipelined prefill on the MXFP4 trunk at two ranks: a 2048-row step of one sequence runs in two
|
||||
* pieces of 1024; every collective is on the second lane, the layers' all-reduces a piece at a time
|
||||
* at `overlap` 1 (two blocks a layer, two pieces a block) and the embedding's whole; the attention and
|
||||
* the DFlash2 taps run a piece at a time; q|k|v and gate|up read one shared input pair. A prompt's
|
||||
* first chunk and a later one alike. RADIANCE_GEMMA3_PIPE=0 runs the same step serially. */
|
||||
TEST(gemma3_a_wide_prefill_runs_in_two_pieces_with_its_boundaries_on_the_second_lane) {
|
||||
MetaKV mk = gemma3_dflash2_meta();
|
||||
const RadEncoding mx = rad_enc_affine(RAD_FP4E2M1, RAD_E8M0, 1, rad::arch::RAD_MX_GROUP);
|
||||
for (int off : { 0, 1 })
|
||||
for (int rank = 0; rank < 2; ++rank)
|
||||
for (int32_t pctx : { 0, 4096 }) {
|
||||
if (off) setenv("RADIANCE_GEMMA3_PIPE", "0", 1);
|
||||
RadBuilder b;
|
||||
b.encs = { { "blk.", mx } };
|
||||
RadBuildCtx ctx = spec_ctx(rank, 2, 7);
|
||||
ctx.max_tok = 2048;
|
||||
const int rc = stderr_of_rc([&] { return gemma3::declare(&b, mk.meta(), &ctx); });
|
||||
if (off) unsetenv("RADIANCE_GEMMA3_PIPE");
|
||||
REQUIRE_EQ(rc, RAD_OK);
|
||||
const gemma3::Model& m = gemma3::g_model[rank];
|
||||
CHECK(m.fuse_mx);
|
||||
CHECK_EQ(m.pipe_on, !off);
|
||||
CHECK(m.n_taps > 0);
|
||||
const auto pf = kit(b, {}, { 2048 }, pctx);
|
||||
const auto v = run_passes(b, gemma3::step, { pf.get() }, rank, 2);
|
||||
CHECK_PASSES(b, v);
|
||||
const RadCtx& c = *v[0];
|
||||
CHECK(c.step_fail.empty());
|
||||
const int64_t E = m.g.n_embd, L = (int64_t)m.layers.size();
|
||||
int ar = 0, ar_lane0 = 0, ar_piece = 0, ar_overlap = 0;
|
||||
int attn = 0, wide_attn = 0, taps = 0, wide_taps = 0;
|
||||
for (const RecIssue& i : c.issues) {
|
||||
const RecOp* o = b.op_of(i.op);
|
||||
if (!o) continue;
|
||||
if (o->op == "all_reduce") {
|
||||
++ar;
|
||||
ar_lane0 += i.lane == 0;
|
||||
ar_piece += i.n == 1024 * E;
|
||||
ar_overlap += pint(o, "overlap") == 1;
|
||||
}
|
||||
if (o->op == "attn_paged") { ++attn; wide_attn += i.n > 1024; }
|
||||
if (o->op == "cast") { ++taps; wide_taps += i.n > 1024; }
|
||||
}
|
||||
if (off) {
|
||||
CHECK(c.joins.empty());
|
||||
CHECK_EQ(ar_lane0, ar);
|
||||
CHECK_EQ(attn, (int)L);
|
||||
continue;
|
||||
}
|
||||
CHECK_EQ(ar_lane0, 0);
|
||||
CHECK_EQ(ar, 4 * (int)L + 1);
|
||||
CHECK_EQ(ar_piece, 4 * (int)L);
|
||||
CHECK_EQ(ar_overlap, 4 * (int)L);
|
||||
CHECK_EQ(attn, 2 * (int)L);
|
||||
CHECK_EQ(wide_attn, 0);
|
||||
CHECK_EQ(taps, 2 * m.n_taps);
|
||||
CHECK_EQ(wide_taps, 0);
|
||||
CHECK(!c.joins.empty());
|
||||
for (const gemma3::Layer& l : m.layers) {
|
||||
CHECK(l.attn.ln_q.q8 == m.pipe_in.q8);
|
||||
CHECK(l.mlp.ln_gu.q8 == m.pipe_in.q8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The DFlash2 drafter: a block of 8 (depth 7, fixed), taps copied out after the named layers into
|
||||
* one column-sliced buffer, the mask token from the config, and the drafter's own KV group after
|
||||
* the trunk's two. Its input_embedding_scale must be the trunk's sqrt(hidden) held in bf16
|
||||
|
||||
Reference in new issue
Block a user