Archived
speculation: an MTP head's first draft reads its cache only up to where it sits
The history pass has a row for every position a verify could commit; rows past the last committed one repeat it, and the run's last row is draft round 1's input. The card gave that pass the run's whole length as its context. Attention places row j of a q_len-row run at seqused - q_len + j and reads keys up to there, so after a verify that accepted acc < n_spec drafts, round 1 also read the n_spec - acc positions after its own: slots the head's layer had not written for this sequence (last step's speculative rounds, or whatever the block held before it was handed out). Its proposal then followed those bytes. Positions 2 and on were right: each round is one row whose context ends at its own position. This fits #221 (Qwen3.8-Flash-Next, position-1 acceptance 0.01-0.16 after a few short conversations sit in the prefix cache, healthy with --no-prefix-cache, after a restart and on long conversations): with the default lending cache the pool hands out blocks it lent the expert slab once cached blocks pass the live mark, and their unwritten slots hold expert bytes; above 2051 tokens the head's QSA path bounds each query by its own position. On the reporter's model (TP2, their flags, 32 distinct short chats on a fresh engine) 1.12.0 falls to p1 0.352 from request 9; with this change p1 is 0.953, as with --no-prefix-cache (0.955), replies identical. The context now ends at the last committed position. Earlier rows of the pass count lower than their positions, but nothing reads their output (the head goes on with draft_out_ids only), and every row's K and V still store at its own position's slot. Tests: advance_test (no row of a history pass or a round counts past its own position, and the run's last row sits exactly at it, for every acceptance and lead; fails before: the last row at 204 for a head at 201; and right after a 1-2 token prompt, where the rows nothing reads count before the sequence's start, every row still stores at its own position and the last sits at the committed one); ref_test (rows of a paged-attention run that sit before the context's start return zeros, not NaN, and the rows after them stay exact). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bf6c019571
commit
64c652f01e
3 files changed
+111
-8
No files matched your search
@@ -3064,6 +3064,32 @@ TEST(op_attn_paged_ragged) {
|
||||
CHECK_NEAR(out.at(5), 1.0f / sum, 1e-6);
|
||||
}
|
||||
|
||||
/* A run longer than its context: four query rows over two keys, as an MTP head's history pass
|
||||
* right after a one-token prompt is (core/sched/advance_impl.h ADV_HIST ends the context at the
|
||||
* last committed position). Rows sit at seqused - q_len + j = -2, -1, 0, 1: the first two see no
|
||||
* key and are zero, not NaN, and the last two are as if the run were two rows. */
|
||||
TEST(op_attn_paged_rows_before_the_context) {
|
||||
const float sc = 1.0f / 1.41421356f;
|
||||
T q(RAD_F32, {4, 1, 2});
|
||||
q.f({ 1, 0, 0, 1, 1, 0, 0, 1 });
|
||||
T kv(RAD_F32, {1, 1, 2, 4});
|
||||
kv.f({ 1, 0, 1, 0,
|
||||
0, 1, 0, 1 });
|
||||
T bt(RAD_I32, {1, 1}); bt.n({0});
|
||||
T su(RAD_I32, {1}); su.n({2});
|
||||
T out(RAD_F32, {4, 1, 2});
|
||||
A a; a.t(q).t(kv).t(bt).t(su).tnull().tnull().tnull().t(out)
|
||||
.i("q_len", 4).i("head_dim", 2).i("gqa", 1).i("block_size", 2)
|
||||
.i("causal", 1).i("window", 0).s("q_dtype", "f32").s("kv_dtype", "f32");
|
||||
CHECK_OK(run("attn_paged", a));
|
||||
for (int e = 0; e < 4; ++e) CHECK_EQ(out.at(e), 0.0f);
|
||||
/* Row 2 at position 0 sees key 0; row 3 at position 1 sees both, q = [0,1]. */
|
||||
CHECK_NEAR(out.at(4), 1.0f, 1e-6); CHECK_NEAR(out.at(5), 0.0f, 1e-6);
|
||||
const float w0 = std::exp(-sc), sum = w0 + 1.0f;
|
||||
CHECK_NEAR(out.at(6), w0 / sum, 1e-6);
|
||||
CHECK_NEAR(out.at(7), 1.0f / sum, 1e-6);
|
||||
}
|
||||
|
||||
TEST(op_attn_dense) {
|
||||
const float sc = 1.0f / 1.41421356f;
|
||||
T q(RAD_F32, {2, 1, 2}); q.f({1, 0, 0, 1});
|
||||
|
||||
Reference in new issue
Block a user