pipelined prefill: review fixes

The parts of the series' review rounds that concern the pipelined prefill and the second lane,
carried over when the series was split:

- qwen35_fp8: a trunk whose norms write rotated int8 codes (qwen35_w8a8 where libr4d serves the
  `_had_quant_i8g` forms) prefills serially -- the boundary norms on the second lane issue the E4M3
  pair only, and before the fix libr4d refused them for the int8 op, failing every one-sequence
  prefill step of 1024 rows or more; a pipelined step whose bounds have no storage fails the step
  rather than falling back on one rank only.
- The three- and eight-rank overlap all-reduce rows accept every tunable pin their wide rows accept
  (r4d_selftest checks it).
- rad_builder.h: the window joins lane 1 into lane 0 at its end only, so an op declared before it
  must not be issued again while lane 1 has work pending.
- tests: arch_test for the w8a8 trunk; plugin_test's lane-row comment.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:10:08 +02:00
1 parent 48e41fda1e
commit 4ec175549c
6 files changed
+87 -8

No files matched your search

+4 -1
View File
@@ -453,7 +453,10 @@ int rad_buf_concurrent(RadBuilder* b, rad_buf buf);
* (a drafter's, the heads') can share its bytes. The runtime holds the architecture to it: an op
* issued on lane 1 outside the window fails the step by name, and the first op past the window
* issued on lane 0 joins lane 1 first when lane 1 has work pending. Optional, one window a program;
* call both at declare, in order. Additive export; RAD_ABI_VERSION does not move. */
* call both at declare, in order. The runtime joins lane 1 into lane 0 at the window's end only, so an
* op declared before the window must not be issued again while lane 1 has work pending (a transient
* it uses may share bytes with a concurrent buffer the window keeps live). Additive export;
* RAD_ABI_VERSION does not move. */
int rad_lane1_window_begin(RadBuilder* b);
int rad_lane1_window_end(RadBuilder* b);
+19 -5
View File
@@ -878,9 +878,9 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
* min_bytes stays 0 for the same reason.
*
* The second lane's window opens here and closes after the final norm (rad_lane1_window_begin):
* the embedding's reduction, the pipelined prefill's boundaries, the GDN a|b lane and the MoE
* shared arm are all declared inside it, so the concurrent buffers stay live only there and the
* drafter and the heads can share their bytes. */
* the embedding's reduction and the pipelined prefill's boundaries are declared inside it, so
* the concurrent buffers stay live only there and the drafter and the heads can share their
* bytes. */
RAD_ARCH_TRY(rad_lane1_window_begin(b));
if (g.world > 1)
m.op_embed_ar = rw(b, RAD_OP(b, "all_reduce",
@@ -896,7 +896,15 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
* leave the sharing pool (the drafter taps are copied on the first lane: pipe_taps)
* (Ctx::lane1_); the bounds also because no declared op reads them, which would leave a
* transient dead before the kernels that take them raw. */
{
/* Not on a trunk whose norms write rotated int8 codes (qwen35_w8a8 where libr4d serves the
* `_had_quant_i8g` forms, a_h.q8_fed): the boundary norms on the second lane
* (NormQuantFP8::step_plain) issue the E4M3 pair only, and that int8 path is unmeasured, so such a
* trunk prefills serially, as before this pipeline. */
if (m.a_h.q8_fed) {
if (g.world > 1 && g.max_tok >= kPipeMinRows && ctx->rank == 0)
fprintf(stderr, "radiance: qwen35: the pipelined prefill stays off on this trunk: its norms "
"write rotated int8 codes, which the pipeline's boundary norms do not\n");
} else {
m.pipe_on = g.max_tok >= kPipeMinRows && rad::arch::prefill_pipeline(b, (int)g.world, "qwen35");
}
if (m.pipe_on) {
@@ -1317,7 +1325,13 @@ static const int32_t* pipe_ready(RadCtx* c, const RadBatch* batch, Model& m, boo
if (rope_mixed(batch) || batch->n_mm_rows > 0) return serial("media rows in the step");
if (dbg_resid_on()) return serial("residual debugging is on");
int32_t* d = (int32_t*)rad_buf_ptr(c, m.b_pipe_cu);
if (!d) return nullptr;
if (!d) {
/* Not a rank-local fallback to the serial step: the other rank would pipeline, and the two
* would issue different collectives. Fail the step, as gemma3 does. */
rad_step_fail(c, "qwen35: the pipelined prefill's bounds have no storage");
*failed = true;
return nullptr;
}
const int64_t R = pipe_rows(T);
ArPieces pc{};
pc.rows = R; pc.done = pipe_hand; pc.cu = d; pc.in_ready = true;
+2 -1
View File
@@ -5057,10 +5057,11 @@ static int64_t ar_lane38_nblocks() {
return e && e[0] == '1' && !e[1] ? 4 : 0;
}
static const RadTunable tArTs38Lane[] = {
{ "nblocks", kArNblocksLane4, NELEM(kArNblocksLane4), ar_lane38_nblocks(), "blocks in the grid. 0 = scale with the message and clamp (the wide rows' launch, the default); 4 under R4D_AR_LANE_3_8=1" },
{ "nblocks", kArNblocks, NELEM(kArNblocks), ar_lane38_nblocks(), "blocks in the grid. 0 = scale with the message and clamp (the wide rows' launch, the default); 4 under R4D_AR_LANE_3_8=1" },
{ "nthreads", kArNthreads, NELEM(kArNthreads), 1024, "threads per block" },
{ "drain", kArDrain, NELEM(kArDrain), 3, "store-drain wait before the flag: 3 = s_wait_storecnt, 1 = vmcnt" },
{ "acq", kArAcq, NELEM(kArAcq), 0, "acquire fence after the flag read" },
{ "ts_min", kArTsMin, NELEM(kArTsMin), 32768, "unused here (tAr says why it is declared)" },
};
/* The same axes with narrow defaults, for a collective issued beside compute (`overlap` 1). The
* wide launch (up to 24 blocks of 1024 threads spinning on peer flags) suits an all-reduce that has
+27
View File
@@ -439,6 +439,33 @@ static void cross_check(const Plugin& pl) {
ok(narrow ? "the 3/8-rank overlap rows take the narrow launch (R4D_AR_LANE_3_8=1)"
: "the 3/8-rank overlap rows launch as their wide rows (R4D_AR_LANE_3_8 unset)",
bad == 0, detail);
/* And they accept every pin their wide rows accept: a RADIANCE_TUNE all_reduce pin is applied
* to every row serving the op, and a key or value a serving row lacks fails the selection. */
int bad_axis = 0;
std::string axis_detail;
for (const auto& pr : pairs) {
const RadKernelInfo* l = row(pr[0]);
const RadKernelInfo* w = row(pr[1]);
if (!l || !w) continue;
for (int v = 0; v < w->n_tunables; ++v) {
const RadTunable& wt = w->tunables[v];
const RadTunable* lt = nullptr;
for (int u = 0; u < l->n_tunables; ++u)
if (!std::strcmp(l->tunables[u].key, wt.key)) lt = &l->tunables[u];
if (!lt) { ++bad_axis; axis_detail += std::string(pr[0]) + " lacks " + wt.key + "; "; continue; }
for (int i = 0; i < wt.n_values; ++i) {
bool has = false;
for (int j = 0; j < lt->n_values; ++j) has = has || lt->values[j] == wt.values[i];
if (!has) {
++bad_axis;
axis_detail += std::string(pr[0]) + ":" + wt.key + " lacks " +
std::to_string((long long)wt.values[i]) + "; ";
}
}
}
}
ok("the 3/8-rank overlap rows accept every tunable pin of their wide rows", bad_axis == 0,
axis_detail);
}
/* The libr4d orderings the integer priority has to preserve. */
+33
View File
@@ -9233,6 +9233,39 @@ TEST(qwen35_pipe_off_is_the_serial_graph_and_steps) {
CHECK_EQ(pinned_steps(b, qwen35_fp8::step, 1, 2), 0xc03bdef23d685cc5ull);
}
/* qwen35_w8a8 at two ranks where libr4d serves the `_had_quant_i8g` norms (a_h.q8_fed): the norms write
* rotated int8 codes, which the pipelined prefill's boundary norms (NormQuantFP8::step_plain) do not issue,
* so the prefill stays serial there: the step whole, nothing on the second lane, no step failure. Where
* the forms are not served each projection quantises its own input and the pipeline runs as on
* qwen35_fp8. (Before the fix the pipeline ran with q8_fed and libr4d refused the boundary norm's E4M3
* codes for the int8 op, failing every one-sequence prefill step of 1024 rows or more.) */
TEST(qwen35_w8a8_with_int8_codes_from_the_norms_prefills_serially) {
MetaKV mk = with_dflash2(q35w8a8_meta());
for (bool fused : { true, false })
for (int rank = 0; rank < 2; ++rank) {
RadBuilder b;
if (!fused)
for (const char* op : kW8a8Fused) b.undeclared.insert(op);
w8a8_encs(&b);
RadBuildCtx ctx = spec_ctx(rank, 2, 7);
ctx.max_tok = 2048;
REQUIRE_EQ(stderr_of_rc([&] { return qwen35_w8a8::declare(&b, mk.meta(), &ctx); }),
RAD_OK);
const qwen35_w8a8::Model& m = qwen35_w8a8::g_model[rank];
CHECK_EQ(m.a_h.q8_fed, fused);
CHECK_EQ(m.pipe_on, !fused);
const auto pf = kit(b, {}, { 2048 }, 0);
const auto v = run_passes(b, qwen35_w8a8::step, { pf.get() }, rank, 2);
CHECK_PASSES(b, v);
const RadCtx& c = *v[0];
CHECK(c.step_fail.empty());
int lane1 = 0;
for (const RecIssue& i : c.issues) lane1 += i.lane == 1;
if (fused) CHECK_EQ(lane1, 0);
else CHECK(lane1 > 0);
}
}
/* A Qwen3.5/3.8 prefill step of one sequence at two ranks runs in two pieces of 1024 rows
* (step_pipelined): every collective is on the second lane, the layers' all-reduces a piece at a
* time at `overlap` 1, the embedding's whole (standalone, or folded into layer 0's norm where the
+2 -1
View File
@@ -901,7 +901,8 @@ TEST(libr4d_resolves_the_all_reduce_by_message_size) {
"41943040:ar_twoshot_3rank_exact ");
/* At `overlap` 1 (a pipelined prefill's all-reduce beside compute) the two-shot band takes the
* narrow lane row at three, four and eight ranks, exact and, where it exists, lossy; the
* lane row at three, four and eight ranks, exact and, where it exists, lossy (at three and
* eight launched as the wide rows unless R4D_AR_LANE_3_8=1); the
* one-shot band has no lane row past two ranks. The lists split at the eight-rank one-shot edge
* as above; at eight ranks the band between it and the wide one-shot bound stays on the plain
* two-shot. */