diff --git a/core/build/rad_builder.cpp b/core/build/rad_builder.cpp index 6879208a..fad27544 100644 --- a/core/build/rad_builder.cpp +++ b/core/build/rad_builder.cpp @@ -1780,6 +1780,13 @@ int Builder::declare_drafter(const RadDrafterDecl* d) { (long long)d->proposal_pitch); return RAD_E_INVAL; } + if (d->kind == RAD_DRAFT_BLOCK && d->proposal_pitch > 0 && d->proposal_pitch < d->depth) { + err(RAD_E_INVAL, "declare_drafter '%s': proposal_pitch %lld under depth %d. A block pass " + "writes each sequence's %d proposals into one row of the proposal buffer, " + "so a row must hold them.", nm, (long long)d->proposal_pitch, d->depth, + d->depth); + return RAD_E_INVAL; + } /* A block pass embeds the mask id at every unfilled position, so it needs one. */ if (d->kind == RAD_DRAFT_BLOCK && d->mask_token < 0) { err(RAD_E_INVAL, "declare_drafter '%s': RAD_DRAFT_BLOCK with no mask_token. Every " @@ -1823,7 +1830,11 @@ int Builder::declare_drafter(const RadDrafterDecl* d) { prog_.drafter_name = nm; prog_.drafter.name = nullptr; prog_.drafter.block = block; - if (prog_.drafter.proposal_pitch == 0) prog_.drafter.proposal_pitch = 1; + /* A block drafter's proposal row holds its whole block's tokens, and the engine reads row s + * at s * pitch (a short block fills only its front), so its pitch defaults to depth; a serial + * one writes a token a pass, at pitch 1 by default. */ + if (prog_.drafter.proposal_pitch == 0) + prog_.drafter.proposal_pitch = prog_.drafter.kind == RAD_DRAFT_BLOCK ? prog_.drafter.depth : 1; return RAD_OK; } diff --git a/core/engine.h b/core/engine.h index 42eca7c1..46524c87 100644 --- a/core/engine.h +++ b/core/engine.h @@ -341,6 +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) */ /* Serial driver (spec ยง10): `depth` dependent passes after the step commits, each embedding * the previous proposal. MTP, EAGLE and Medusa-serial have this shape. */ diff --git a/core/engine_bringup.cpp b/core/engine_bringup.cpp index 83853df0..02b8105d 100644 --- a/core/engine_bringup.cpp +++ b/core/engine_bringup.cpp @@ -1306,9 +1306,10 @@ int Engine::declare() { drafter_short_ = drafter_.kind == RAD_DRAFT_BLOCK && cfg_.draft_short_from > 0 ? p0.drafter_short_block : 0; if (cfg_.draft_short_from > 0 && drafter_.kind != RAD_DRAFT_NONE && !drafter_short_) - RAD_WARN("--draft-short-from %lld: '%s' declares no shorter block, so its block stays %lld", - (long long)cfg_.draft_short_from, drafter_name_.c_str(), - (long long)drafter_.block); + RAD_WARN("--draft-short-from %lld: '%s' %s", (long long)cfg_.draft_short_from, + drafter_name_.c_str(), + drafter_.kind == RAD_DRAFT_BLOCK ? "declares no shorter block, so its block stays" + : "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, diff --git a/core/sched/scheduler.cpp b/core/sched/scheduler.cpp index f2f41e53..44410ed5 100644 --- a/core/sched/scheduler.cpp +++ b/core/sched/scheduler.cpp @@ -2374,8 +2374,12 @@ void Scheduler::serial_end(int rounds_done) { * also propose. Called while plan() still describes that step, because the context pass mirrors * it exactly, rejected suffix included: the drafter reads hidden states positionally from its * own buffer, so batch row i must be buffer row i. The rejected positions lie in [n_computed, - * n_computed + block), which the query pass overwrites before anything reads them, and the - * ensure() below covers them since n_computed + block reaches the trunk step's own end. + * n_computed + the trunk step's block), which a query pass overwrites before anything reads them. + * The ensure() below covers n_computed + `block`; with the block the trunk step verified that + * reaches its end. A short block (rad_drafter_short_block) after a long one does not: rejected + * rows past it fall on pages the commit's rollback freed, whose slot is -1, and every kv_store + * drops a negative slot. That rule is what keeps such a step from writing into another + * sequence's pages. * * On the card the step has not committed yet. The step began at n_computed (a row issued ahead * was staged at its furthest reach; it really continued from the committed end, as commit() diff --git a/tests/arch_fakes.h b/tests/arch_fakes.h index c8449ac0..4c0c50f0 100644 --- a/tests/arch_fakes.h +++ b/tests/arch_fakes.h @@ -365,9 +365,8 @@ struct ChainOn { 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; + if (!b || b->drafter.kind != RAD_DRAFT_BLOCK) return RAD_E_STATE; + if (block >= full || block - (full - b->drafter.depth) < 1) return RAD_E_INVAL; b->drafter_short = block; return RAD_OK; } diff --git a/tests/build_test.cpp b/tests/build_test.cpp index 6b76b8cb..03a9cc84 100644 --- a/tests/build_test.cpp +++ b/tests/build_test.cpp @@ -1105,6 +1105,36 @@ TEST(a_block_drafters_short_block_is_shorter_and_still_proposes) { } } +/* A block drafter's proposal pitch is its row pitch, which the engine reads row s at: left at 0 it + * defaults to depth, and under depth it is refused, since a row could not hold the proposals. */ +TEST(a_block_drafters_proposal_pitch_holds_its_proposals) { + Registry reg; + RadBufDecl bd{}; + bd.dtype = RAD_I32; bd.rank = 2; bd.shape[0] = 256; bd.shape[1] = 4; + { + Builder b(reg, make_meta(), make_ctx()); + RadDrafterDecl d{}; + d.kind = RAD_DRAFT_BLOCK; d.name = "df"; d.depth = 4; d.mask_token = 5; + d.proposal = rad_decl_buffer(&b, "prop", &bd); + CHECK_OK(rad_declare_drafter(&b, &d)); + CHECK_EQ(b.program().drafter.proposal_pitch, 4); + } + { + Builder b(reg, make_meta(), make_ctx()); + RadDrafterDecl d{}; + d.kind = RAD_DRAFT_BLOCK; d.name = "df"; d.depth = 4; d.mask_token = 5; + d.proposal = rad_decl_buffer(&b, "prop", &bd); d.proposal_pitch = 3; + CHECK_EQ(rad_declare_drafter(&b, &d), RAD_E_INVAL); + } + { + 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(b.program().drafter.proposal_pitch, 1); + } +} + /* 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. */