Archived
block drafter: a short block chosen per step by load (--draft-short-from N)
A block drafter proposes its block whole, so the block's length is paid for every drafting sequence whatever each verifies. At one sequence a long block pays: Qwen3.8-27B + DFlash2 (block 8, --draft-window adaptive) decodes one stream 135 -> 155-165 t/s against block 4. At sixteen it does not: block 8 750-790 t/s, block 4 900, its drafter rows and weaker first positions costing more than the extra drafts bring. --draft-window adaptive alone cannot help, since it only shortens what each sequence verifies. - rad_drafter_short_block(b, block): additive export (RAD_ABI_VERSION unchanged); the plugin declares that its query pass also runs at `block` rows a sequence. Builder validates it (block drafter, shorter than its own, still proposes). - --draft-short-from N (default 0 = never): the engine stages the short block once N sequences decoded in the step just run (Scheduler::decoded_seqs). - The engine reads the proposals at the drafter's declared row pitch, not at the step's count: dflash_select writes row s at s * pitch, and a short block fills only a row's front (with the pitch read as the count, every sequence but the first got the wrong tokens). - Dflash2: a short block of 4 rows (depth 3) wherever its own is longer: its own convolution and selector ops at that block (every other op is per row); the query pass picks by T / n_seq and fails the step on a block it has no ops for. qwen35_fp8 and gemma3 declare it. - Tests: build_test (the declaration's checks), arch_test (the qwen35 family's short query pass runs the short ops, a block without ops fails the step; the DFlash2 pin moves), config_test. Measured (Qwen, speculation 7 adaptive, short block from 4 sequences, against production's speculation 3 fixed): one stream +15-20 % (kratky) / +9 % (syslog), 4 streams +3 %, 16 streams equal (915 / 906 t/s). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9eaf10da6e
commit
90e14c5015
16 files changed
+211
-6
No files matched your search
@@ -117,6 +117,7 @@ struct RadBuilder {
|
||||
std::string drafter_name;
|
||||
bool drafter_shared = false;
|
||||
int drafter_pos = -1;
|
||||
int64_t drafter_short = 0; /* rad_drafter_short_block */
|
||||
|
||||
/* The buffers named to rad_buf_concurrent: the ones a second lane touches. */
|
||||
std::vector<rad_buf> concurrent;
|
||||
@@ -361,6 +362,15 @@ struct ChainOn {
|
||||
explicit ChainOn(int on) { g_chain_on = on; }
|
||||
~ChainOn() { g_chain_on = 0; }
|
||||
};
|
||||
|
||||
extern "C" int rad_drafter_short_block(RadBuilder* b, int64_t block) {
|
||||
const int64_t full = b ? (b->drafter.block > 0 ? b->drafter.block : b->drafter.depth + 1) : 0;
|
||||
if (!b || b->drafter.kind != RAD_DRAFT_BLOCK || block >= full ||
|
||||
block - (full - b->drafter.depth) < 1)
|
||||
return RAD_E_STATE;
|
||||
b->drafter_short = block;
|
||||
return RAD_OK;
|
||||
}
|
||||
extern "C" int rad_declare_encoder(RadBuilder* b, const RadEncoderDecl* d) {
|
||||
if (!b || !d || !d->name || !d->modalities) return RAD_E_INVAL;
|
||||
if (d->modalities == RAD_MM_AUDIO) {
|
||||
|
||||
@@ -6149,6 +6149,26 @@ void lint_qwen35_fp8_family(Fn declare, StepFn step, const RadModelMeta* meta, i
|
||||
const auto v = run_passes(b, step, all, rank, world);
|
||||
CHECK_PASSES(b, v);
|
||||
for (size_t i = 1; i < v.size(); ++i) CHECK(each_gemm_nt_once(b, *v[i]));
|
||||
if (!block_drafter || block <= 4) continue;
|
||||
/* The short block (rad_drafter_short_block): a query pass staged at 4 rows a sequence
|
||||
* runs the short ops, its selector proposing 3; a block with no ops fails the step. */
|
||||
CHECK_EQ(b.drafter_short, 4);
|
||||
const auto ctx2 = context_pass(b, *ver);
|
||||
const auto qs = query_pass(b, 4, b.drafter_short, b.drafter_short - 1);
|
||||
const auto vs = run_passes(b, step, { ver.get(), ctx2.get(), qs.get() }, rank, world);
|
||||
CHECK_PASSES(b, vs);
|
||||
CHECK(vs[2]->step_fail.empty());
|
||||
int64_t sel_steps = -1, sel_stride = -1;
|
||||
for (const RecIssue& i : vs[2]->issues)
|
||||
if (const RecOp* o = b.op_of(i.op); o && o->op == "dflash_select") {
|
||||
sel_steps = pint(o, "steps");
|
||||
sel_stride = pint(o, "anchor_stride");
|
||||
}
|
||||
CHECK_EQ(sel_steps, 3);
|
||||
CHECK_EQ(sel_stride, 4);
|
||||
const auto qbad = query_pass(b, 4, 6, 5);
|
||||
const auto vb = run_passes(b, step, { qbad.get() }, rank, world);
|
||||
CHECK(!vb[0]->step_fail.empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1072,6 +1072,39 @@ TEST(the_drafter_name_survives_the_program_leaving_the_builder) {
|
||||
CHECK_EQ(p.drafter.depth, 3);
|
||||
}
|
||||
|
||||
/* rad_drafter_short_block applies only to a declared block drafter, and only to a block shorter
|
||||
* than its own that still proposes a token; anything else is refused at declare, since the core
|
||||
* would stage a block the plugin has no ops for. */
|
||||
TEST(a_block_drafters_short_block_is_shorter_and_still_proposes) {
|
||||
Registry reg;
|
||||
{
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
CHECK_EQ(rad_drafter_short_block(&b, 4), RAD_E_STATE); /* nothing declared */
|
||||
}
|
||||
{
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
RadDrafterDecl d{};
|
||||
d.kind = RAD_DRAFT_SERIAL; d.name = "mtp"; d.depth = 4;
|
||||
CHECK_OK(rad_declare_drafter(&b, &d));
|
||||
CHECK_EQ(rad_drafter_short_block(&b, 3), RAD_E_STATE); /* a serial head */
|
||||
}
|
||||
{
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
RadBufDecl bd{};
|
||||
bd.dtype = RAD_I32; bd.rank = 2; bd.shape[0] = 256; bd.shape[1] = 4;
|
||||
const rad_buf prop = rad_decl_buffer(&b, "prop", &bd);
|
||||
RadDrafterDecl d{};
|
||||
d.kind = RAD_DRAFT_BLOCK; d.name = "df"; d.depth = 4; d.mask_token = 5;
|
||||
d.proposal = prop; d.proposal_pitch = 4; /* block 5: the anchor + 4 */
|
||||
CHECK_OK(rad_declare_drafter(&b, &d));
|
||||
CHECK_EQ(rad_drafter_short_block(&b, 5), RAD_E_INVAL); /* not shorter */
|
||||
CHECK_EQ(rad_drafter_short_block(&b, 1), RAD_E_INVAL); /* proposes nothing */
|
||||
CHECK_EQ(b.program().drafter_short_block, 0);
|
||||
CHECK_OK(rad_drafter_short_block(&b, 3));
|
||||
CHECK_EQ(b.program().drafter_short_block, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* rad_drafter_shared_kv applies only to a declared serial drafter. With none declared, a block
|
||||
* drafter, or a position no head occupies, it is refused at declare; a head staged the wrong way
|
||||
* silently costs acceptance. */
|
||||
|
||||
@@ -435,7 +435,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--placement", { "all_vram" } }, { "--checkpoint-interval", { "256" } },
|
||||
{ "--prefill-span", { "2" } },
|
||||
{ "--checkpoint-slots", { "4" } }, { "--checkpoint-policy", { "tip-only" } },
|
||||
{ "--num-speculative-tokens", { "2" } }, { "--draft-window", { "fixed" } },
|
||||
{ "--num-speculative-tokens", { "2" } }, { "--draft-window", { "fixed" } }, { "--draft-short-from", { "4" } },
|
||||
{ "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } },
|
||||
{ "--served-model-name", { "m" } }, { "--mm-max-patches", { "1024" } },
|
||||
{ "--control-vector", { "off" } },
|
||||
|
||||
Reference in new issue
Block a user