Archived
glm indexer: a step that takes all its blocks does not split
A prefill chunk past the row threshold split the indexer over the ranks even when every row's history fit the selection, so it scored rows whose selection was already decided and gathered the result. Such a step now takes the unsplit take-all path on every rank: zeros into a plane of its own, [max_tok, topk + 1] (the score plane holds only a run of rows where a step may split), and a selection over the whole step, with no query side, scorer or gathers. Temp-0 replies byte-identical to the scoring path; 114/114 tests.
This commit is contained in:
1 parent
c9e34d534c
commit
be623ba1dc
3 files changed
+105
-36
No files matched your search
@@ -27,6 +27,9 @@ struct DsaCache {
|
||||
rad_buf query = 0, codes = 0, scales = 0, gate = 0, kg = 0;
|
||||
rad_buf stage = 0, page = 0, bpos = 0, nc = 0, pooled = 0, pool_scale = 0;
|
||||
rad_buf score = 0, selected = 0, nsel = 0, length = 0;
|
||||
/* A taking-all step's zero scores, [max_tok, topk + 1]: such a step does not split, and
|
||||
* the score plane holds only a run of rows when the step may. */
|
||||
rad_buf unscored = 0;
|
||||
/* TP only: a rank's rebased bounds, page tables and lengths before the gathers. */
|
||||
rad_buf cu_part = 0, sel_part = 0, len_part = 0;
|
||||
};
|
||||
@@ -44,7 +47,7 @@ struct DsaCache {
|
||||
rad_kvgroup index = 0, tail = 0, attention = 0;
|
||||
rad_weight ape = 0;
|
||||
rad_op op_query = 0, op_work = 0, op_pool = 0, op_tail = 0, op_score = 0, op_select = 0;
|
||||
rad_op op_unscored = 0;
|
||||
rad_op op_unscored = 0, op_select_all = 0;
|
||||
rad_op op_score_part = 0, op_select_part = 0, op_gather_sel = 0, op_gather_len = 0;
|
||||
|
||||
int declare(RadBuilder* b, Names& nm, const Geom& geom, int l, const Config& cfg,
|
||||
@@ -121,7 +124,7 @@ struct DsaCache {
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok),
|
||||
RAD_INT("n", unscored_cols()), RAD_STR("dtype", "f32")),
|
||||
RAD_NOWEIGHTS),
|
||||
{}, { w.score });
|
||||
{}, { w.unscored });
|
||||
op_score = rw(b,
|
||||
RAD_OP(b, "dsa_score",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", 128),
|
||||
@@ -149,6 +152,14 @@ struct DsaCache {
|
||||
RAD_INT("seqs", g.max_seqs), RAD_INT("signed", 1)),
|
||||
RAD_NOWEIGHTS),
|
||||
{ w.score, w.nc }, { w.selected, w.nsel, w.length });
|
||||
op_select_all = rw(b,
|
||||
RAD_OP(b, "qsa_select",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok),
|
||||
RAD_INT("blocks", unscored_cols()),
|
||||
RAD_INT("topk", 512), RAD_INT("ratio", 4),
|
||||
RAD_INT("seqs", g.max_seqs), RAD_INT("signed", 1)),
|
||||
RAD_NOWEIGHTS),
|
||||
{ w.unscored, w.nc }, { w.selected, w.nsel, w.length });
|
||||
if (split) {
|
||||
op_select_part = rw(
|
||||
b,
|
||||
@@ -175,7 +186,9 @@ struct DsaCache {
|
||||
if (!op_score_part || !op_select_part || !op_gather_sel || !op_gather_len)
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
return op_query && op_work && op_tail && op_unscored && op_score && op_select ? RAD_OK
|
||||
return op_query && op_work && op_tail && op_unscored && op_score && op_select &&
|
||||
op_select_all
|
||||
? RAD_OK
|
||||
: RAD_E_INVAL;
|
||||
}
|
||||
int64_t unscored_cols() const { return c.topk + 1 < c.blocks ? c.topk + 1 : c.blocks; }
|
||||
@@ -191,20 +204,19 @@ struct DsaCache {
|
||||
}
|
||||
/* The decision reads the same host bound as the score plane's width (max_ctx_len, rounded by
|
||||
* the core), so every rank takes the same path and a recorded decode pass changes it only when
|
||||
* that bound moves. */
|
||||
* that bound moves. A step that takes all its blocks never splits: with nothing to score, every
|
||||
* rank selects the whole step itself, and the gathers have nothing to save. */
|
||||
bool splits(const RadBatch* batch) const {
|
||||
const int64_t T = batch->n_tok;
|
||||
return op_score_part && (GlmTp::splits(T, g.world) ||
|
||||
(T >= GlmTp::kSplitWorkRows &&
|
||||
T * live_blocks(batch) >= GlmTp::kSplitWork));
|
||||
return op_score_part && live_blocks(batch) > c.topk &&
|
||||
(GlmTp::splits(T, g.world) ||
|
||||
(T >= GlmTp::kSplitWorkRows && T * live_blocks(batch) >= GlmTp::kSplitWork));
|
||||
}
|
||||
/* Every row's history fits the selection, so the query side (projection, head gates,
|
||||
* quantiser, scorer) has nothing to decide: the selected table is every live block in order,
|
||||
* bit for bit what scoring would select. Read from the same host bound as splits(), so every
|
||||
* rank agrees. A split step keeps scoring: its selection's rebased bounds come off the scorer. */
|
||||
bool takes_all(const RadBatch* batch) const {
|
||||
return !splits(batch) && live_blocks(batch) <= c.topk;
|
||||
}
|
||||
* rank agrees. */
|
||||
bool takes_all(const RadBatch* batch) const { return live_blocks(batch) <= c.topk; }
|
||||
/* The query rows this rank runs: the whole step, or its run of a split step (GlmTp::run_of).
|
||||
* A rank whose run lies wholly past a small step runs the step's first R rows instead: no
|
||||
* sequence holds its run, so its scores are -inf, and its answers land past T. The caller's
|
||||
@@ -253,15 +265,22 @@ struct DsaCache {
|
||||
step_split(ctx, batch, live);
|
||||
return;
|
||||
}
|
||||
if (all)
|
||||
RAD_ISSUE_N(ctx, op_unscored, T, bcol_at(w.score, 0, c.blocks, 0, unscored_cols(), T));
|
||||
else
|
||||
// dsa_score declares ten operands, cu_part the optional tenth; the engine counts them.
|
||||
RAD_ISSUE_N(ctx, op_score, T, brows(w.codes, T * 32), brows(w.scales, T * 32),
|
||||
brows(w.gate, T), kv_cache(index, layer), RAD_NONE,
|
||||
praw2(ib->block_table, RAD_I32, S, ib->block_table_pitch),
|
||||
praw(batch->cu_seqlens, RAD_I32, S + 1), brows(w.nc, S),
|
||||
bcol_at(w.score, 0, c.blocks, 0, live, T), RAD_NONE);
|
||||
if (all) {
|
||||
const int64_t U = unscored_cols();
|
||||
RAD_ISSUE_N(ctx, op_unscored, T, brows(w.unscored, T));
|
||||
RAD_ISSUE_N(ctx, op_select_all, T, bcol_at(w.unscored, 0, U, 0, live, T),
|
||||
praw2(ab->block_table, RAD_I32, S, ab->block_table_pitch),
|
||||
brows(w.nc, S), praw(batch->positions, RAD_I32, T),
|
||||
praw(batch->cu_seqlens, RAD_I32, S + 1), brows(w.selected, T),
|
||||
brows(w.nsel, T), brows(w.length, T));
|
||||
return;
|
||||
}
|
||||
// dsa_score declares ten operands, cu_part the optional tenth; the engine counts them.
|
||||
RAD_ISSUE_N(ctx, op_score, T, brows(w.codes, T * 32), brows(w.scales, T * 32),
|
||||
brows(w.gate, T), kv_cache(index, layer), RAD_NONE,
|
||||
praw2(ib->block_table, RAD_I32, S, ib->block_table_pitch),
|
||||
praw(batch->cu_seqlens, RAD_I32, S + 1), brows(w.nc, S),
|
||||
bcol_at(w.score, 0, c.blocks, 0, live, T), RAD_NONE);
|
||||
RAD_ISSUE_N(ctx, op_select, T, bcol_at(w.score, 0, c.blocks, 0, live, T),
|
||||
praw2(ab->block_table, RAD_I32, S, ab->block_table_pitch), brows(w.nc, S),
|
||||
praw(batch->positions, RAD_I32, T), praw(batch->cu_seqlens, RAD_I32, S + 1),
|
||||
|
||||
Reference in new issue
Block a user