review notes of the pipelined prefill past two ranks; selftest timings warm the clocks first

Independent review of fa118d8 / 14fb72c: no defect. Notes taken:

- RADIANCE_PREFILL_PIPELINE takes 1 / true as on and 0 / false as off (the old per-arch switches
  took 0 for off; such a value must not leave the pipeline on); the header says that past two
  ranks only the two-shot band is narrow and that eight ranks pipeline on the exact wire only; the
  note says the switch allows the pipeline (gemma3 may still turn it off); "rad_arch.h" as the other
  common headers include it; comment lines rewrapped.
- plugin_test resolves the all-reduce at `overlap` 1 against the real libr4d: the two-shot band
  takes the lane row at three, four and eight ranks, exact and ti8; the one-shot band keeps the wide
  row. arch_test: every spelling of the switch, off at two ranks in all three; no three-rank arch
  case (neither test model's heads split three ways, nor do the real models' KV heads).
- r4d_selftest: gemv_wide's two column tiles at four row tiles and on the per-row scale.
- r4d_selftest: every timed pass is preceded by an untimed one. A fresh process otherwise times its
  first pass while the clocks ramp up from idle (up to 1.5x slow, +-30 % between runs); two builds
  of the same machine code read 13 % apart until both warmed.

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 284feda3a6
commit ad01fcaf19
5 files changed
+80 -29

No files matched your search

+16 -11
View File
@@ -4,15 +4,18 @@
// compute) uses it.
//
// auto (or unset) at two ranks, where it was measured (Qwen3.8-27B 41k prefill -6.6 %,
// TranslateGemma-27B 6k -12 %, bit for bit the serial step);
// on also at three, four and eight ranks: libr4d has the narrow `overlap` all-reduce
// there (the wide rows' entry points at a launch that leaves the CUs to compute),
// but the step has not been measured on such hardware;
// off never.
// TranslateGemma-27B 6k -4.7 % at a 2048 chunk, bit for bit the serial step);
// on (1, true) also at three, four and eight ranks: libr4d has the narrow `overlap` two-shot
// all-reduce there (the wide rows' entry points at a launch that leaves the CUs to
// compute), but the step has not been measured on such hardware;
// off (0, false) never.
//
// Any other rank count has no narrow row, and a wide all-reduce beside the GEMMs ate the whole gain at
// two (it slows the GEMM 1.45-2.1x), so those stay serial.
#include <arch/rad_arch.h>
// two (it slows the GEMM 1.45-2.1x), so those stay serial. Past two ranks only the two-shot band is
// narrow: a piece small enough for the one-shot band (at most 524288 elements, e.g. 512 rows of a model
// 1024 wide) still gets the wide one-shot; and eight ranks have no lossy wire, so `on` there pipelines
// on the exact wire only.
#include "rad_arch.h"
#include <cstdlib>
#include <cstring>
@@ -21,14 +24,16 @@ namespace rad::arch {
inline bool prefill_pipeline(RadBuilder* b, int world, const char* who) {
const char* e = std::getenv("RADIANCE_PREFILL_PIPELINE");
const bool on = e && !std::strcmp(e, "on"), off = e && !std::strcmp(e, "off");
if (e && *e && !on && !off && std::strcmp(e, "auto") != 0)
auto is = [&](const char* v) { return e && !std::strcmp(e, v); };
const bool on = is("on") || is("1") || is("true"), off = is("off") || is("0") || is("false");
if (e && *e && !on && !off && !is("auto"))
rad_note(b, "%s: RADIANCE_PREFILL_PIPELINE=%s is not auto, on or off; taken as auto", who, e);
if (off || world < 2) return false;
if (world == 2) return true;
if (on && (world == 3 || world == 4 || world == 8)) {
rad_note(b, "%s: the pipelined prefill at %d ranks (RADIANCE_PREFILL_PIPELINE=on) is not yet "
"measured on hardware", who, world);
rad_note(b, "%s: RADIANCE_PREFILL_PIPELINE=on allows the pipelined prefill at %d ranks, not "
"yet measured on such hardware (it still needs what the architecture checks)",
who, world);
return true;
}
return false;
+4 -4
View File
@@ -1190,10 +1190,10 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
/* The pipelined prefill (step_pipelined) wherever a step can be wide enough, on an MXFP4 trunk
* with fused junctions (decided below), at the rank counts RADIANCE_PREFILL_PIPELINE allows
* (rad_prefill_pipe.h: two by default). Its
* second lane touches the stream, the branch output, the shared input pair, the taps and the
* bounds, so those leave the sharing pool (Ctx::lane1_); the pair is one for every block so
* that this costs one pair, not one a linear. */
* (rad_prefill_pipe.h: two by default). Its second lane touches the stream, the branch
* output, the shared input pair, the taps and the bounds, so those leave the sharing pool
* (Ctx::lane1_); the pair is one for every block so that this costs one pair, not one a
* linear. */
{
m.pipe_on = g.max_tok >= kPipeMinRows && !calib_dir() &&
rad::arch::prefill_pipeline(b, (int)g.world, "gemma3");
+3 -2
View File
@@ -885,8 +885,9 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
{m.b_x}, {m.b_x});
#if !QWEN35_MOE
/* The pipelined prefill (step_pipelined), wherever a step can be wide enough, at the rank
* counts RADIANCE_PREFILL_PIPELINE allows (rad_prefill_pipe.h: two by default). Its second lane touches the residual stream, the normed
* input in both forms, the taps and the bounds, so those leave the sharing pool
* counts RADIANCE_PREFILL_PIPELINE allows (rad_prefill_pipe.h: two by default). Its second
* lane touches the residual stream, the normed input in both forms, the taps and the bounds,
* so those leave the sharing pool
* (Ctx::lane1_); the bounds also because no declared op reads them, which would leave a
* transient dead before the kernels that take them raw. */
{
+32 -12
View File
@@ -9299,15 +9299,19 @@ TEST(qwen35_a_wide_prefill_runs_in_two_pieces_with_its_boundaries_on_the_second_
}
}
/* Past two ranks the pipelined prefill is opt-in (RADIANCE_PREFILL_PIPELINE=on): unset, the step is
* serial; asked, a 2048-row step of one sequence runs in two pieces with every collective on the
* second lane, the layers' all-reduces a piece at a time at `overlap` 1 (libr4d's narrow lane rows),
* the embedding's whole, on every rank. At four and eight ranks. */
static void four_rank_pipe_case(int world, bool gemma) {
/* Past two ranks the pipelined prefill is opt-in (RADIANCE_PREFILL_PIPELINE=on, or 1, or true): unset,
* auto or an unknown value, the step is serial; asked, a 2048-row step of one sequence runs in two
* pieces with every collective on the second lane, the layers' all-reduces a piece at a time at
* `overlap` 1 (libr4d's narrow lane rows), the embedding's whole, on every rank. At four and eight
* ranks: neither test model's heads split three ways (nor do Qwen3.8's 4 or TranslateGemma's 16 KV
* heads); plugin_test checks that the three-rank lane rows resolve. */
static void n_rank_pipe_case(int world, bool gemma) {
const char* env = "RADIANCE_PREFILL_PIPELINE";
for (int ask : { 0, 1 })
const char* vals[] = { nullptr, "auto", "maybe", "on", "1", "true" };
for (const char* val : vals)
for (int rank = 0; rank < world; ++rank) {
if (ask) setenv(env, "on", 1);
const int ask = val && (!strcmp(val, "on") || !strcmp(val, "1") || !strcmp(val, "true"));
if (val) setenv(env, val, 1);
RadBuilder b;
RadBuildCtx ctx = spec_ctx(rank, world, 7);
ctx.max_tok = 2048;
@@ -9316,7 +9320,7 @@ static void four_rank_pipe_case(int world, bool gemma) {
const int rc = stderr_of_rc([&] {
return gemma ? gemma3::declare(&b, mk.meta(), &ctx) : qwen35_fp8::declare(&b, mk.meta(), &ctx);
});
if (ask) unsetenv(env);
if (val) unsetenv(env);
REQUIRE_EQ(rc, RAD_OK);
const bool on = gemma ? gemma3::g_model[rank].pipe_on : qwen35_fp8::g_model[rank].pipe_on;
const int64_t L = gemma ? (int64_t)gemma3::g_model[rank].layers.size()
@@ -9344,10 +9348,26 @@ static void four_rank_pipe_case(int world, bool gemma) {
CHECK(!c.joins.empty());
}
}
TEST(qwen35_four_ranks_pipeline_only_when_asked) { four_rank_pipe_case(4, false); }
TEST(gemma3_four_ranks_pipeline_only_when_asked) { four_rank_pipe_case(4, true); }
TEST(qwen35_eight_ranks_pipeline_only_when_asked) { four_rank_pipe_case(8, false); }
TEST(gemma3_eight_ranks_pipeline_only_when_asked) { four_rank_pipe_case(8, true); }
TEST(qwen35_four_ranks_pipeline_only_when_asked) { n_rank_pipe_case(4, false); }
TEST(gemma3_four_ranks_pipeline_only_when_asked) { n_rank_pipe_case(4, true); }
TEST(qwen35_eight_ranks_pipeline_only_when_asked) { n_rank_pipe_case(8, false); }
TEST(gemma3_eight_ranks_pipeline_only_when_asked) { n_rank_pipe_case(8, true); }
/* At two ranks "off", "0" and "false" all run the pipelined prefill's step serially (the old switches
* took 0 for off; such a value must not leave it on). */
TEST(two_ranks_pipeline_off_in_every_spelling) {
MetaKV mk = with_dflash2(q35fp8_meta());
for (const char* v : { "off", "0", "false" }) {
setenv("RADIANCE_PREFILL_PIPELINE", v, 1);
RadBuilder b;
RadBuildCtx ctx = spec_ctx(0, 2, 7);
ctx.max_tok = 2048;
const int rc = stderr_of_rc([&] { return qwen35_fp8::declare(&b, mk.meta(), &ctx); });
unsetenv("RADIANCE_PREFILL_PIPELINE");
REQUIRE_EQ(rc, RAD_OK);
CHECK(!qwen35_fp8::g_model[0].pipe_on);
}
}
/* Under a span a Flash-Next prefill of two intervals runs a pass at a time. At every world its
* connection reads take a pass each and the indexer scores its pass-tall plane in windows, the MTP
+25
View File
@@ -900,6 +900,31 @@ TEST(libr4d_resolves_the_all_reduce_by_message_size) {
"8192:ar_oneshot_3rank_exact 524288:ar_oneshot_3rank_exact "
"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
* 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. */
auto lane = [&](int world, int exact) {
Geometry g;
g.set_i("world_size", world);
g.set_s("dtype", "bf16");
g.set_i("exact", exact);
g.set_i("min_bytes", 128 * 1024);
g.set_i("overlap", 1);
return r.build_bands("all_reduce", "numel", width, chunk * width, g);
};
CHECK_EQ(band_names(lane(3, 1)), "8192:ar_oneshot_3rank_exact 524288:ar_oneshot_3rank_exact "
"5242880:ar_twoshot_3rank_exact_lane ");
CHECK_EQ(band_names(lane(4, 1)), "8192:ar_oneshot_4rank_exact 524288:ar_oneshot_4rank_exact "
"5242880:ar_twoshot_4rank_exact_lane ");
CHECK_EQ(band_names(lane(8, 1)), "8192:ar_oneshot_8rank_exact 524288:ar_twoshot_8rank_exact "
"5242880:ar_twoshot_8rank_exact_lane ");
CHECK_EQ(band_names(lane(3, 0)), "8192:ar_twoshot_3rank_ti8_lane 524288:ar_twoshot_3rank_ti8_lane "
"5242880:ar_twoshot_3rank_ti8_lane ");
CHECK_EQ(band_names(lane(4, 0)), "8192:ar_twoshot_4rank_ti8_lane 524288:ar_twoshot_4rank_ti8_lane "
"5242880:ar_twoshot_4rank_ti8_lane ");
/* Above the two-shot's bound the one-shot takes the message back. */
CHECK_EQ(band_names(bands(4, 1, 131072)),
"8192:ar_oneshot_4rank_exact 524288:ar_oneshot_4rank_exact "