Archived
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:
1 parent
0f4c1afc38
commit
d39e0511e7
6 files changed
+459
-5
No files matched your search
@@ -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. */
|
||||
|
||||
Reference in new issue
Block a user