review fixes of the pipelined prefill (independent review)

- pipe_ready: past the batch's and the build's own conditions (the same on every rank), a
  rank-local failure -- no pinned host memory for the bounds table, or its copy failing -- now
  fails the step instead of running it serially. A serial step on one rank beside a pipelined
  one on the other issues different collectives on the shared all-reduce instance: a hang or a
  wrong sum.
- declare frees the previous build's pinned bounds table before resetting the model.
- NormQuantFP8: the slicing comment back above step(); step_plain() gets its own.
- r4d_rows: the TN axis's help text says the new crossover (M >= 1024).

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 d39e0511e7
commit 57d2cb4043
3 files changed
+27 -13

No files matched your search

+5 -4
View File
@@ -473,10 +473,7 @@ inline int NormQuantFP8::declare(RadBuilder* b, const Geom& g, rad_weight gain,
return RAD_OK;
}
/* `r0`/`rows` select a row slice, defaulting to the whole step (`brow_slice` at offset 0 equals
* `brows`). Slicing lets a block run in passes (the routed feed-forward). Each slice must land in
* the same bucket-table band as the whole (core/runtime/ctx.h), or a different kernel with a
* different summation order would run. */
/* step() below with the plain op, whatever the wire. */
inline void NormQuantFP8::step_plain(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const {
if (rows <= 0) rows = T - r0;
RAD_ISSUE_N(c, op, rows, brow_slice(src, r0, rows, n),
@@ -486,6 +483,10 @@ inline void NormQuantFP8::step_plain(RadCtx* c, int64_t T, int64_t r0, int64_t r
brow_slice(a.x, r0, rows, n));
}
/* `r0`/`rows` select a row slice, defaulting to the whole step (`brow_slice` at offset 0 equals
* `brows`). Slicing lets a block run in passes (the routed feed-forward). Each slice must land in
* the same bucket-table band as the whole (core/runtime/ctx.h), or a different kernel with a
* different summation order would run. */
inline void NormQuantFP8::step(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const {
if (rows <= 0) rows = T - r0;
RAD_ISSUE_N(c, pick(rows), rows, brow_slice(src, r0, rows, n),
+20 -7
View File
@@ -449,6 +449,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
if (ctx->rank < 0 || ctx->rank >= MAX_RANKS) return RAD_E_INVAL;
Model& m = g_model[ctx->rank];
if (m.pipe_tbl) rad_dev_free(m.pipe_tbl, RAD_MEM_HOST_PINNED);
m = Model{};
m.nm = Names(ctx->scope);
RAD_ARCH_TRY(check_format(meta));
@@ -1274,9 +1275,10 @@ static void pipe_hand(void* u, int64_t r0, int64_t n) {
}
/* The bounds of this step's pieces on the card, {0, pipe_rows(T), T}, if the step is pipelined;
* null for a serial step. Copied on the step's stream ahead of every layer from the pinned table,
* whose rows never change, so a captured step replays the same copy. */
static const int32_t* pipe_ready(RadCtx* c, const RadBatch* batch, Model& m) {
* null for a serial step, and null with `failed` set when the step has been failed. Copied on the
* step's stream ahead of every layer from the pinned table, whose rows never change, so a captured
* step replays the same copy. */
static const int32_t* pipe_ready(RadCtx* c, const RadBatch* batch, Model& m, bool* failed) {
const int64_t T = batch->n_tok;
if (!m.pipe_on || !m.b_pipe_cu || T < kPipeMinRows || T > m.g.max_tok ||
batch->phase != RAD_PHASE_PREFILL)
@@ -1319,10 +1321,19 @@ static const int32_t* pipe_ready(RadCtx* c, const RadBatch* batch, Model& m) {
}
}
}
if (!m.pipe_tbl) return serial("no pinned host memory for the piece bounds");
if (rad_memcpy_async(d, m.pipe_tbl + 3 * T, 3 * (int64_t)sizeof(int32_t), rad_stream(c)) !=
RAD_OK)
/* Everything above depends only on the batch and the build, the same on every rank; what
* follows is this rank's own, and falling back to the serial step here would leave the other
* rank pipelining, the two issuing different collectives on the shared all-reduce instance
* (a hang or a wrong sum). So it fails the step. */
if (!m.pipe_tbl ||
rad_memcpy_async(d, m.pipe_tbl + 3 * T, 3 * (int64_t)sizeof(int32_t), rad_stream(c)) !=
RAD_OK) {
rad_step_fail(c, "qwen35: the pipelined prefill's piece bounds could not be put on the card "
"(no pinned host memory, or the copy failed); RADIANCE_QWEN35_PIPE=0 runs "
"prefill serially");
*failed = true;
return nullptr;
}
return d;
}
@@ -1424,10 +1435,12 @@ static void step(RadCtx* c, const RadBatch* batch) {
}
#if !QWEN35_MOE
if (const int32_t* pcu = pipe_ready(c, batch, m)) {
bool pipe_failed = false;
if (const int32_t* pcu = pipe_ready(c, batch, m, &pipe_failed)) {
step_pipelined(c, batch, m, pcu);
return;
}
if (pipe_failed) return;
#endif
RAD_ISSUE(c, m.op_embed,
+2 -2
View File
@@ -4930,11 +4930,11 @@ static const RadTunable tGemmPrefill[] = {
};
/* The MXFP4 tiled GEMM's one axis: compiled arms of one template. 0 is the M crossover (TN=4 from
* M >= 2048), which needs M. */
* M >= 1024), which needs M. */
static const int64_t kMxTn[] = { 0, 2, 4 };
static const RadTunable tGemmMxfp4Tiled[] = {
{ "tn", kMxTn, NELEM(kMxTn), 0,
"16-column fragments per wave: 2 = 256x64 block, 4 = 256x128. 0 = TN 4 from M >= 2048" },
"16-column fragments per wave: 2 = 256x64 block, 4 = 256x128. 0 = TN 4 from M >= 1024" },
};
/* The MXFP4 decode GEMM's axes. 0 on each is the kernel's own rule (r4d_gemm_mxfp4a8_decode.hip);