qwen35_fp8: a prefill step of one sequence in two pieces, block boundaries on the second lane

At two ranks a prefill step of at least 1024 rows is cut into two pieces of about half
(pipe_rows: rounded up to 64, both in the whole step's band). Every block runs a piece at a
time on lane 0; the work between two blocks runs a piece at a time on lane 1: the block's
all-reduce at `overlap` 1 (the narrow lane rows), then the next block's plain norm, and after
a feed-forward that keeps its add, the add, the DFlash2 taps and the final norm. The fused
all-reduce + norm is not used there: it holds its blocks while waiting on the link and slowed
the GEMM beside it by a third (measured: no gain at all with it).

- GdnFP8, AttnGatedFP8: takes_pieces(); the dense attention gets a two-piece path (each piece
  its own rows, positions, slots and query bounds, seeing the cache up to its own end), and
  the delta net's piece path takes the caller's normed input (ArPieces::in_ready) and passes
  each piece its own context length (positions + r0), so a prompt's first chunk works.
- MlpFP8: slice() split into body() and tail(), and an overlap all-reduce (issue_ar).
- NormQuantFP8::step_plain().
- M-RoPE batches (the vision tower loaded) take it when no token's components differ: plane 0
  of rope_pos is then every token's position.
- RADIANCE_QWEN35_PIPE=0 turns it off; a wide prefill step that runs serially says why, once.

Bit for bit the serial step: Qwen3.8-27B KL recordings (k6_v4, wht6) compare equal with the
pipeline on and off, and greedy answers to three long requests (680-41k tokens, speculation 3
with the DFlash2 taps) are identical. 41k-token prefill on two R9700s: 9.00 -> 8.41 s with the
TN crossover of the next commit (-6.6 %). arch_test: the two-rank pin moves; new tests pin the
serial build under RADIANCE_QWEN35_PIPE=0 and the pieces, lanes and overlap of a wide step.

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 0f4c1afc38
commit d39e0511e7
6 files changed
+459 -5

No files matched your search

+60
View File
@@ -157,6 +157,21 @@ struct AttnGatedFP8 {
/* Set before declare: the `overlap` issue_ar's collective is declared at, 0 for none. */
int ar_overlap = 0;
rad_op op_ar_ov = 0;
/* Whether step() with `own_ar` false runs the dense path a piece at a time over a caller's
* normed pieces (ArPieces::in_ready): one prefill sequence in two pieces, each the chunk a
* span of 1 makes, on the unfused prologue with one rotary component per token (every token's
* components agree, so plane 0 of an M-RoPE batch's positions is each token's position) and
* the gate quantised by gate_quant_fp8. */
bool takes_pieces(const RadBatch* batch, const ArPieces* pieces) const {
const int64_t T = batch->n_tok;
const RadKVGroupBatch* kvb = kv_batch(batch, kv);
return pieces && pieces->in_ready && pieces->cu && pieces->cuts(T) &&
T <= 2 * pieces->rows && !op_add && !op_fill && op_gq && !op_sig && !qsa_sel &&
batch->n_seq == 1 && batch->phase == RAD_PHASE_PREFILL &&
!(T <= fused_rows) && batch->positions && !rope_mixed(batch) &&
kvb && kvb->slot_mapping && kvb->block_table && kvb->seqused;
}
};
inline int AttnGatedFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
@@ -477,6 +492,51 @@ inline void AttnGatedFP8::step(RadCtx* c, const RadBatch* batch, bool own_ar,
const int64_t T = batch->n_tok;
/* One prefill sequence in two pieces over the caller's normed input (takes_pieces): the
* projections, prologue, cache store, attention, gate and out projection of the first piece,
* then the second's, so the first piece's reduction runs beside all of the second piece's
* work. Each piece is the chunk a span of 1 makes: its rows, its positions, its slots, and an
* attention over its own query bounds (ArPieces::cu) that sees the cache up to its own end --
* the first piece's position after its last row, the step's seqused for the second, which
* reads the first piece's keys from the cache as a later chunk would. */
if (!own_ar && takes_pieces(batch, pieces)) {
const int64_t R = pieces->rows, hd = g.head_dim, qw = g.q_dim();
const int64_t qgw = g.n_head * 2 * hd, kvw = g.n_head_kv * hd;
const int64_t tpitch = kvb->block_table_pitch;
for (int64_t p = 0; p < 2; ++p) {
const int64_t r0 = p == 0 ? 0 : R;
const int64_t n = p == 0 ? R : T - R;
const int32_t* pos = (batch->rope_pos ? batch->rope_pos : batch->positions) + r0;
qg.step(c, w.h, w.qg, T, r0, n);
kp.step(c, w.h, w.k, T, r0, n);
vp.step(c, w.h, w.v, T, r0, n);
RAD_ISSUE_N(c, op_q_norm, n * g.n_head,
bcol_at(w.qg, r0, qgw, 0, hd, n), RAD_W(w_q_norm),
brow_slice(w.q, r0, n, qw));
RAD_ISSUE_N(c, op_k_norm, n * g.n_head_kv,
brow_slice(w.k, r0, n, kvw), RAD_W(w_k_norm),
brow_slice(w.k, r0, n, kvw));
RAD_ISSUE_N(c, op_rope_q, n, brow_slice(w.q, r0, n, qw), praw(pos, RAD_I32, n));
RAD_ISSUE_N(c, op_rope_k, n, brow_slice(w.k, r0, n, kvw), praw(pos, RAD_I32, n));
RAD_ISSUE_N(c, op_kv_store, n,
brow_slice(w.k, r0, n, kvw), brow_slice(w.v, r0, n, kvw),
praw(slot + r0, RAD_I32, n), kv_cache(kv, layer));
RAD_ISSUE_N(c, op_attn, n,
brows(w.q, T), kv_cache(kv, layer), praw2(table, RAD_I32, 1, tpitch),
praw(p == 0 ? batch->positions + R : used, RAD_I32, 1),
RAD_NONE, RAD_NONE, praw(pieces->cu + p, RAD_I32, 2),
brows(w.attn.x, T));
RAD_ISSUE_N(c, op_gq, n * g.n_head,
bcol_at(w.qg, r0, qgw, hd, hd, n), brow_slice(w.attn.x, r0, n, qw),
brow_slice(w.attn.cq(), r0, n, qw),
brow_slice(w.attn.cs(), r0, n, fp8_blocks(qw)),
brow_slice(w.attn.x, r0, n, qw));
o.step(c, w.attn, w.h.x, T, r0, n);
if (p == 0) pieces->hand(r0, n);
}
return;
}
if (!ext_in) nq_h.step(c, T);
if (op_fill) {
/* Attention-zero rank: zero output, then the reduce and the residual. */
+12 -5
View File
@@ -139,6 +139,13 @@ struct GdnFP8 {
* trailing add, which would read the delta before the reduction. */
void step(RadCtx* c, const RadBatch* batch, bool own_ar = true,
ArPieces* pieces = nullptr) const;
/* Whether step() with `own_ar` false runs the whole block a piece at a time over `pieces`
* (its piece path), asked by a caller that must know before it commits to a schedule. */
bool takes_pieces(const RadBatch* batch, const ArPieces* pieces) const {
return pieces && pieces->cu && pieces->cuts(batch->n_tok) &&
batch->n_tok <= 2 * pieces->rows && (ext_in || pieces->in_ready) && !op_add &&
batch->n_seq == 1 && batch->phase == RAD_PHASE_PREFILL;
}
/* Whether a step of T rows issues the all-reduce itself, asked by a caller before taking it
* over; and that all-reduce over rows [r0, r0 + rows) of the output. */
bool issues_ar(int64_t T) const { return op_ar && !ar_taken(g, T, ar_out, ar_out_take); }
@@ -389,10 +396,10 @@ inline void GdnFP8::step(RadCtx* c, const RadBatch* batch, bool own_ar,
* piece the chunk a span of 1 makes (the projection over its rows; the convolution, solve and
* scan over its bounds, with the state handed on through the cache; the gated norm, quantiser
* and out projection), so the first piece's reduction runs beside all of the second piece's
* work. The second piece reads the history the first left in the convolution slot: a spanned
* step is past the prompt's first interval, so its context length is never zero. */
if (!own_ar && pieces && pieces->cu && pieces->cuts(T) && T <= 2 * pieces->rows && ext_in &&
!op_add && S == 1 && batch->phase == RAD_PHASE_PREFILL) {
* work. The second piece reads the history the first left in the convolution slot, so each
* piece passes its own context length, its first row's position: the step's would tell the
* second piece of a prompt's first chunk that it has none. */
if (!own_ar && takes_pieces(batch, pieces)) {
const int64_t in_w = conv_dim + v_dim;
for (int64_t p = 0; p < 2; ++p) {
const int64_t r0 = p * pieces->rows;
@@ -405,7 +412,7 @@ inline void GdnFP8::step(RadCtx* c, const RadBatch* batch, bool own_ar,
bcol(w.in.x, 0, conv_dim, T), RAD_W(w_conv), RAD_NONE, RAD_W(w_a_log),
RAD_W(w_dt_bias), kv_cache(kv_conv, layer), praw(cu, RAD_I32, 2),
bcol(w.ab, 0, H, T), bcol(w.ab, H, H, T),
praw(cv_idx, RAD_I32, 1), praw(batch->ctx_lens, RAD_I32, 1),
praw(cv_idx, RAD_I32, 1), praw(batch->positions + r0, RAD_I32, 1),
brows(w.q, T), brows(w.k, T), brows(w.v, T),
brows(w.gdec, T), brows(w.beta, T));
RAD_ISSUE_N(c, op_kkt, n,
+33
View File
@@ -75,6 +75,20 @@ struct MlpFP8 {
void step_rows(RadCtx* c, int64_t T) const { slice(c, T, 0, T); }
/* One row slice of the whole block; `rows <= 0` means the rest of the step. */
void slice(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const;
/* The slice in its parts, for a caller that runs the norm and the tail elsewhere (qwen35_fp8's
* pipelined prefill puts both on the second lane): the projections from the normed input to
* the delta in `w.h.x`, then the all-reduce and add this block issues itself. */
void body(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const;
void tail(RadCtx* c, int64_t r0, int64_t rows) const;
/* The block's all-reduce over rows [r0, r0 + rows) of the output, at `overlap` where declared
* (a caller that runs it beside other work). */
void issue_ar(RadCtx* c, int64_t r0, int64_t rows) const {
RAD_ISSUE_N(c, op_ar_ov ? op_ar_ov : op_ar, rows * g.n_embd,
brow_slice(w.h.x, r0, rows, g.n_embd), RAD_NONE);
}
/* Set before declare: the `overlap` issue_ar's collective is declared at, 0 for none. */
int ar_overlap = 0;
rad_op op_ar_ov = 0;
};
inline int MlpFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, const Wire& wire,
@@ -129,6 +143,17 @@ inline int MlpFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, co
RAD_INT("min_bytes", g.wire_min_bytes)),
RAD_NOWEIGHTS),
{w.h.x}, {w.h.x});
/* The same collective for a caller that runs it beside other work (issue_ar): at `overlap` 1
* it gets the rows that hold fewer CUs while waiting on the link. */
if (g.world > 1 && ar_overlap > 0)
op_ar_ov = rw(b, RAD_OP(b, "all_reduce",
RAD_PARAMS(RAD_INT("world_size", g.world),
RAD_RANGE("numel", g.n_embd, g.max_tok * g.n_embd),
RAD_STR("dtype", g.dtype), RAD_INT("exact", g.wire_exact),
RAD_INT("min_bytes", g.wire_min_bytes),
RAD_INT("overlap", ar_overlap)),
RAD_NOWEIGHTS),
{w.h.x}, {w.h.x});
/* Only when the next block's norm will not add (rad_fp8.h: NormQuantFP8). */
if (add_out)
@@ -149,6 +174,11 @@ inline int MlpFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l, co
inline void MlpFP8::slice(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const {
if (rows <= 0) rows = T - r0;
nq_h.step(c, T, r0, rows);
body(c, T, r0, rows);
tail(c, r0, rows);
}
inline void MlpFP8::body(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const {
if (op_gated && rows <= gated_rows) {
RAD_ISSUE_N(c, op_gated, rows, brow_slice(w.h.q, r0, rows, g.n_embd),
brow_slice(w.h.s, r0, rows, g.n_embd / RAD_FP8_BLOCK), RAD_W(gate_up.w),
@@ -160,6 +190,9 @@ inline void MlpFP8::slice(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const
gq_ffn.step(c, w.gate_up, T, r0, rows);
}
down.step(c, w.ffn, w.h.x, T, r0, rows);
}
inline void MlpFP8::tail(RadCtx* c, int64_t r0, int64_t rows) const {
if (op_ar && !(ar_out && ar_fused_ok(g, rows)))
RAD_ISSUE_N(c, op_ar, rows * g.n_embd, brow_slice(w.h.x, r0, rows, g.n_embd), RAD_NONE);
if (op_add)
+16
View File
@@ -290,6 +290,10 @@ struct ArPieces {
* chunk a span of 1 makes, the state carried through the cache) and hand off the first
* piece's reduction before the second piece's projection. Null for any other step. */
const int32_t* cu = nullptr;
/* The caller normed each piece's input itself (qwen35_fp8's pipelined prefill, on the second
* lane behind the previous block's piece), so a block with its own norm takes the piece path
* as one with an external input does and skips that norm. */
bool in_ready = false;
bool cuts(int64_t T) const { return done && rows > 0 && T > rows; }
void hand(int64_t r0, int64_t n) { done(u, r0, n); ++handed; }
};
@@ -389,6 +393,9 @@ struct NormQuantFP8 {
}
/* Asked by the preceding block before issuing its own collective. */
bool takes_ar(int64_t T) const { return pick(T) != op; }
/* The plain op whatever the wire, for a caller that issued the preceding all-reduce itself
* (qwen35_fp8's pipelined prefill, which runs it narrow beside compute). */
void step_plain(RadCtx* c, int64_t T, int64_t r0 = 0, int64_t rows = 0) const;
};
inline int NormQuantFP8::declare(RadBuilder* b, const Geom& g, rad_weight gain, rad_buf x,
@@ -470,6 +477,15 @@ inline int NormQuantFP8::declare(RadBuilder* b, const Geom& g, rad_weight gain,
* `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_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),
res ? brow_slice(res, r0, rows, n) : RAD_NONE, RAD_W(w),
brow_slice(a.q, r0, rows, n),
brow_slice(a.s, r0, rows, n / RAD_FP8_BLOCK),
brow_slice(a.x, r0, rows, n));
}
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),