block drafter: the short block on the card's driver

1.11.0 runs a block drafter on the card only (issue_block_drafter). Engine::block_shape chooses the block
and the proposal count a step runs: the drafter's own, or its short block from --draft-short-from
decoding sequences on, off again two below. The card's query pass runs that block, ADV_BTAKE takes that
many proposals from the front of each row at the drafter's pitch, and the step issued ahead verifies
that many (expect_draft and finish_block_drafter read block_steps_). sched_test runs the card driver's
sequence at DFlash2's short block (4 rows, 3 proposals) against the host's reference.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 committed 2026-10-23 11:26:39 +00:00
1 parent 7e2d6a205d
commit 877e8e44e4
5 files changed
+82 -16

No files matched your search

+1 -1
View File
@@ -354,7 +354,7 @@ int Engine::issue_ahead(const RadBatch** out) {
for (int i = 0; i < serial_rows_ && serial_done_ > 0; ++i)
sched_.expect_draft(serial_row_[(size_t)i].seq, serial_done_);
for (int i = 0; i < block_rows_; ++i)
sched_.expect_draft(block_row_[(size_t)i].seq, drafter_.depth);
sched_.expect_draft(block_row_[(size_t)i].seq, block_steps_);
const RadBatch* nb = sched_.step_next();
if (!nb) return RAD_OK;
/* Its rows' tokens, positions and slots, advanced on the card behind this step's acceptance
+7 -1
View File
@@ -341,7 +341,7 @@ private:
/* The block drafter's shorter block (rad_drafter_short_block), 0 when it has none or
* --draft-short-from is 0. */
int64_t drafter_short_ = 0;
bool short_on_ = false; /* the short block runs now (run_block_drafter) */
bool short_on_ = false; /* the short block runs now (block_shape) */
/* Serial driver (spec §10): `depth` dependent passes after the step commits, each embedding
* the previous proposal. MTP, EAGLE and Medusa-serial have this shape. */
@@ -417,10 +417,16 @@ private:
int block_pass(const RadBatch* db, const char* what, int step);
int issue_block_drafter(int step, StepOut& so);
int finish_block_drafter(const StepOut& so);
/* The block and proposal count this step's query pass runs at: the drafter's own, or its short
* block once --draft-short-from sequences decode, back to its own only two below. */
void block_shape(int* block, int* steps);
/* Handed from issue_block_drafter to finish_block_drafter and issue_ahead: the drafting rows,
* in the query pass's order, and how many there are (0 when no query pass ran). */
std::vector<Scheduler::BlockRow> block_row_;
int block_rows_ = 0;
/* The proposals a row of the query pass took (block_shape), for finish_block_drafter and
* issue_ahead's expect_draft. */
int block_steps_ = 0;
/* Encoder driver (spec §11, core/engine_mm.cpp): encodes every media item the scheduler waits
* on, in passes of whole segments, and reads it back into the item. Runs between steps, never
* inside one. */
+1 -1
View File
@@ -1312,7 +1312,7 @@ int Engine::declare() {
: "is a serial head, which proposes no block");
if (drafter_short_)
RAD_INFO("speculation: from %lld decoding sequences on, '%s' runs its short block of %lld "
"row(s), %lld token(s), on the host's block driver", (long long)cfg_.draft_short_from,
"row(s), %lld token(s)", (long long)cfg_.draft_short_from,
drafter_name_.c_str(),
(long long)drafter_short_,
(long long)(drafter_short_ - ((drafter_.block > 0 ? drafter_.block
+26 -3
View File
@@ -313,6 +313,25 @@ bool Engine::block_drafting() const {
* and its proposals go into the slots behind the anchor (ADV_BTAKE): exactly the token row the
* next verify reads (ADV_TRUNK), so the step issued ahead verifies them with no host round trip.
* collect_step's wait covers both passes and the slots' readback. */
void Engine::block_shape(int* block, int* steps) {
*steps = drafter_.depth;
/* The row count is the drafter's (defaulted and checked by declare_drafter). */
*block = drafter_.block > 0 ? (int)drafter_.block : drafter_.depth + 1;
/* Its short block under load (rad_drafter_short_block): the same anchor convention, so as many
* fewer proposals as rows. The load is the step just run's, which the next step, the one these
* proposals are for, mostly repeats. On from --draft-short-from decoding sequences, off again
* only two below it, so a load wavering at the threshold does not switch the block (a new pass
* shape) every step. */
if (drafter_short_ <= 0) return;
const int64_t n = sched_.decoded_seqs();
if (n >= cfg_.draft_short_from) short_on_ = true;
else if (n + 2 <= cfg_.draft_short_from) short_on_ = false;
if (short_on_) {
*steps -= *block - (int)drafter_short_;
*block = (int)drafter_short_;
}
}
int Engine::issue_block_drafter(int step, StepOut& so) {
block_rows_ = 0;
if (!block_drafting()) return RAD_OK;
@@ -321,8 +340,12 @@ int Engine::issue_block_drafter(int step, StepOut& so) {
/* The sampled ids before either pass, as the serial driver reads them. */
RAD_TRY(collect_issue(so));
const int steps = drafter_.depth;
const int block = drafter_.block > 0 ? (int)drafter_.block : drafter_.depth + 1;
/* The short block too (block_shape): its query pass is a shorter batch the card positions
* the same way, its proposals the front of each row at the drafter's pitch (ADV_BTAKE), and
* the step issued ahead verifies that many (issue_ahead). */
int block = 0, steps = 0;
block_shape(&block, &steps);
block_steps_ = steps;
block_row_.resize((size_t)cfg_.max_seqs);
const int n = sched_.block_begin(block, steps, (int)drafter_.window, drafter_.mask_token,
block_row_.data(), (int)block_row_.size(), /*on_card=*/true);
@@ -368,7 +391,7 @@ int Engine::finish_block_drafter(const StepOut& so) {
if (block_rows_ <= 0) return RAD_OK;
Rank& r0 = *ranks_[0];
const int steps = drafter_.depth;
const int steps = block_steps_;
draft_out_.assign((size_t)block_rows_ * (size_t)steps, 0);
for (int i = 0; i < block_rows_; ++i) {
const StepSlot& S = slots_host_[block_row_[(size_t)i].card];