Archived
The gemma4_bf16 architecture (sliding and global attention, the proportional RoPE ladder, the assistant head as a drafter that reads the trunk's cache, the vision tower), its w4a8 decode junctions, the h512/gqa8 and h256/gqa2 attention kernels, compressed-tensors int4 import, multi-EOS from generation_config, the call/reasoning reply format, a window group that keeps the keys a prefill chunk still reads, and window snapshots in checkpoint slots so a prefix hit on a sliding-window trunk resumes. Fixes on top: the investigation switches and diagnostic blocks out of the served paths; int4 import through the checkpoint import framework; attention_k_eq_v from the config; the fused junctions only where every reader takes their pair; a shared-KV head binds no group of its own; the compose file without HSA_ENABLE_IPC_MODE_LEGACY (TP2 fails with it on ROCm 10.1); a checkpoint carries a window only where a hit resumes from it; the README says the linked container is keptn42's calibrated GPTQ build and what the in-tree recipe gives.
This commit is contained in:
commit
7c7f755931
84 files changed
+10292
-230
No files matched your search
+146
-5
@@ -943,6 +943,106 @@ TEST(kv_preemption_by_recompute_and_the_undeadlockable_request) {
|
||||
CHECK_OK(f.kv.ensure(newcomer, per));
|
||||
}
|
||||
|
||||
/* THE WINDOW BEHIND A PREFIX HIT: a checkpoint slot carries window_blocks pages a WINDOW group,
|
||||
* window_rows() names the pages a query at P reads from the table that wrote them, seed_window()
|
||||
* gives a resumed sequence fresh pages at the same floor -- and a table whose floor moved past it
|
||||
* answers false, which is the fallback (no snapshot, a full re-prefill). */
|
||||
TEST(kv_window_snapshot_rows_and_seed) {
|
||||
std::vector<KVGroupInfo> g;
|
||||
g.push_back(null_group());
|
||||
KVGroupInfo k;
|
||||
k.name = "swa";
|
||||
k.decl.kind = RAD_KV_WINDOW;
|
||||
k.decl.dtype = RAD_BF16;
|
||||
k.decl.n_head_kv = 2;
|
||||
k.decl.head_dim = 8;
|
||||
k.decl.window = 64;
|
||||
k.block_size = 16;
|
||||
k.layers = { 0 };
|
||||
g.push_back(k);
|
||||
Config cfg = small_config();
|
||||
Pools p;
|
||||
CHECK_OK(p.configure(cfg, 0, &rad_malloc_allocator(), &rad_malloc_allocator()));
|
||||
KVManager kv;
|
||||
CHECK_OK(kv.configure(g, cfg, p.kv()));
|
||||
CHECK(kv.has_window_snapshot());
|
||||
CHECK_EQ(kv.checkpoint_bytes(), 5 * kv.plan(G_FULL)->bytes_per_block);
|
||||
|
||||
CHECK_OK(kv.add_sequence(1));
|
||||
CHECK_OK(kv.ensure(1, 400)); /* a prompt of 400 in one chunk */
|
||||
std::vector<int32_t> rows;
|
||||
CHECK(kv.window_rows(1, 400, &rows));
|
||||
CHECK_EQ((long long)rows.size(), 5ll); /* padded to window_blocks */
|
||||
/* A query at 400 reads back to 337: blocks 21..24, the floor recycle_window keeps. */
|
||||
for (int j = 0; j < 4; ++j) CHECK_EQ(rows[(size_t)j], kv.block_table(1, G_FULL)[(size_t)(21 + j)]);
|
||||
CHECK_EQ(rows[4], -1);
|
||||
/* A short prefix: the window starts at zero and the rest is padding. */
|
||||
CHECK(kv.window_rows(1, 32, &rows));
|
||||
CHECK_EQ(rows[0], kv.block_table(1, G_FULL)[0]);
|
||||
CHECK_EQ(rows[2], -1);
|
||||
/* Not on a block: no rows. */
|
||||
CHECK(!kv.window_rows(1, 40, &rows));
|
||||
/* The floor moved past it (a decode step slid the window): the fallback. */
|
||||
CHECK_OK(kv.ensure(1, 401));
|
||||
CHECK(!kv.window_rows(1, 64, &rows));
|
||||
CHECK(kv.window_rows(1, 400, &rows));
|
||||
|
||||
/* A resumed sequence: seeded at the floor, extended from there, and its rows are its own. */
|
||||
CHECK_OK(kv.add_sequence(2));
|
||||
CHECK_OK(kv.seed_window(2, 400));
|
||||
CHECK_EQ(kv.first_block_pos(2, G_FULL), 336ll);
|
||||
CHECK_EQ((long long)kv.block_table(2, G_FULL).size(), 4ll);
|
||||
CHECK_EQ(kv.seq_tokens(2), 400ll);
|
||||
CHECK_OK(kv.ensure(2, 432, 400));
|
||||
CHECK_EQ(kv.first_block_pos(2, G_FULL), 336ll);
|
||||
CHECK_EQ((long long)kv.block_table(2, G_FULL).size(), 6ll);
|
||||
std::vector<int32_t> rows2;
|
||||
CHECK(kv.window_rows(2, 400, &rows2));
|
||||
for (int j = 0; j < 4; ++j) CHECK_EQ(rows2[(size_t)j], kv.block_table(2, G_FULL)[(size_t)j]);
|
||||
/* A table already holding window pages is not seeded twice. */
|
||||
CHECK_EQ(kv.seed_window(2, 400), RAD_E_STATE);
|
||||
kv.free_sequence(1);
|
||||
kv.free_sequence(2);
|
||||
}
|
||||
|
||||
/* A SNAPSHOT ONLY WHERE A HIT RESUMES FROM IT: the trunk's window in a model with no linear state.
|
||||
* A model with linear state re-prefills a hit on a windowed trunk, and a drafter's window is
|
||||
* recomputed by draft refill, so a window section in either slot would be copied at every
|
||||
* checkpoint and never read. */
|
||||
TEST(kv_window_snapshot_only_where_a_hit_resumes_from_it) {
|
||||
KVGroupInfo w;
|
||||
w.name = "swa";
|
||||
w.decl.kind = RAD_KV_WINDOW;
|
||||
w.decl.dtype = RAD_BF16;
|
||||
w.decl.n_head_kv = 2;
|
||||
w.decl.head_dim = 8;
|
||||
w.decl.window = 64;
|
||||
w.block_size = 16;
|
||||
w.layers = { 6 };
|
||||
const Config cfg = small_config();
|
||||
{ /* beside linear state: the slot holds the state and nothing more */
|
||||
std::vector<KVGroupInfo> g = hybrid_groups();
|
||||
g.push_back(w);
|
||||
Pools p;
|
||||
CHECK_OK(p.configure(cfg, 0, &rad_malloc_allocator(), &rad_malloc_allocator()));
|
||||
KVManager kv;
|
||||
CHECK_OK(kv.configure(g, cfg, p.kv()));
|
||||
CHECK(!kv.has_window_snapshot());
|
||||
CHECK_EQ(kv.checkpoint_bytes(), 16384ll);
|
||||
}
|
||||
{ /* a drafter's own window over a full-attention trunk */
|
||||
std::vector<KVGroupInfo> g = hybrid_groups(/*with_linear=*/false);
|
||||
w.drafter = true;
|
||||
g.push_back(w);
|
||||
Pools p;
|
||||
CHECK_OK(p.configure(cfg, 0, &rad_malloc_allocator(), &rad_malloc_allocator()));
|
||||
KVManager kv;
|
||||
CHECK_OK(kv.configure(g, cfg, p.kv()));
|
||||
CHECK(!kv.has_window_snapshot());
|
||||
CHECK_EQ(kv.checkpoint_bytes(), 0ll);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(kv_window_group_recycles_below_the_window) {
|
||||
std::vector<KVGroupInfo> g;
|
||||
g.push_back(null_group());
|
||||
@@ -965,19 +1065,60 @@ TEST(kv_window_group_recycles_below_the_window) {
|
||||
CHECK_OK(kv.configure(g, cfg, p.kv()));
|
||||
/* window 64 at block 16 is 4 blocks plus one for the straddle. */
|
||||
CHECK_EQ(kv.plan(G_FULL)->window_blocks, 5ll);
|
||||
/* Sized against the cap, not against the whole budget: blocks past the window are memory
|
||||
* nobody will ever address. */
|
||||
CHECK_EQ(kv.total_blocks(G_FULL), cfg.max_seqs * 5);
|
||||
/* Sized against the cap, not against the whole budget: a window a sequence plus one step's
|
||||
* worth of tokens (max_tok) and a straddle block a sequence -- a chunk's own blocks are held
|
||||
* beside the window behind its first query. Past that is memory nobody will ever address. */
|
||||
CHECK_EQ(kv.total_blocks(G_FULL), cfg.max_seqs * 5 + (cfg.max_tok + 15) / 16 + cfg.max_seqs);
|
||||
|
||||
const int64_t n0 = kv.free_blocks(G_FULL);
|
||||
CHECK_OK(kv.add_sequence(1));
|
||||
CHECK_OK(kv.ensure(1, 80));
|
||||
CHECK_OK(kv.ensure(1, 80)); /* a chunk from 0: all of it held */
|
||||
CHECK_EQ(kv.first_block_pos(1, G_FULL), 0ll);
|
||||
CHECK_EQ((long long)kv.block_table(1, G_FULL).size(), 5ll);
|
||||
/* A chunk from 80 to 400: its first query (80) reads back to 17, so block 1 stays and only
|
||||
* block 0 goes -- NOT the window behind 400, which left rows 80..335 with no keys. */
|
||||
CHECK_OK(kv.ensure(1, 400));
|
||||
CHECK_EQ((long long)kv.block_table(1, G_FULL).size(), 5ll); /* recycled, not grown */
|
||||
CHECK_EQ(kv.first_block_pos(1, G_FULL), 16ll);
|
||||
CHECK_EQ((long long)kv.block_table(1, G_FULL).size(), 24ll);
|
||||
/* A decode step from 400: back to the window, recycled rather than grown. */
|
||||
CHECK_OK(kv.ensure(1, 401));
|
||||
CHECK_EQ(kv.first_block_pos(1, G_FULL), 336ll);
|
||||
CHECK_EQ((long long)kv.block_table(1, G_FULL).size(), 5ll);
|
||||
CHECK_EQ(kv.free_blocks(G_FULL), n0 - 5);
|
||||
kv.free_sequence(1);
|
||||
CHECK_EQ(kv.free_blocks(G_FULL), n0);
|
||||
|
||||
/* THE PROMPT LONGER THAN THE WINDOW, in one chunk from 0: every position keeps its slot. The
|
||||
* old rule rebased this table at ceil(400/16) - 5 = 20 blocks, and a sliding layer read no
|
||||
* keys at all for positions 0..319. */
|
||||
CHECK_OK(kv.add_sequence(2));
|
||||
CHECK_OK(kv.ensure(2, 400));
|
||||
CHECK_EQ(kv.first_block_pos(2, G_FULL), 0ll);
|
||||
CHECK_EQ((long long)kv.block_table(2, G_FULL).size(), 25ll);
|
||||
/* And the scheduler's form names the step's first query itself: a chunk grown in the same
|
||||
* step (ensure called twice) keeps what the first call's first query reads. */
|
||||
CHECK_OK(kv.ensure(2, 432, 400));
|
||||
CHECK_EQ(kv.first_block_pos(2, G_FULL), 336ll);
|
||||
CHECK_OK(kv.ensure(2, 464, 400));
|
||||
CHECK_EQ(kv.first_block_pos(2, G_FULL), 336ll);
|
||||
CHECK_EQ((long long)kv.block_table(2, G_FULL).size(), 8ll);
|
||||
kv.free_sequence(2);
|
||||
CHECK_EQ(kv.free_blocks(G_FULL), n0);
|
||||
|
||||
/* A COMMITTED CHUNK GIVES ITS BLOCKS BACK at once: trim_window to the new end keeps the window
|
||||
* behind it and nothing else, so a prefill that waits a step for its next chunk holds a window
|
||||
* and not a chunk. */
|
||||
CHECK_OK(kv.add_sequence(3));
|
||||
CHECK_OK(kv.ensure(3, 400));
|
||||
CHECK_EQ((long long)kv.block_table(3, G_FULL).size(), 25ll);
|
||||
kv.trim_window(3, 400);
|
||||
CHECK_EQ(kv.first_block_pos(3, G_FULL), 336ll);
|
||||
CHECK_EQ((long long)kv.block_table(3, G_FULL).size(), 4ll);
|
||||
CHECK_EQ(kv.free_blocks(G_FULL), n0 - 4);
|
||||
CHECK_OK(kv.ensure(3, 401));
|
||||
CHECK_EQ((long long)kv.block_table(3, G_FULL).size(), 5ll);
|
||||
kv.free_sequence(3);
|
||||
CHECK_EQ(kv.free_blocks(G_FULL), n0);
|
||||
}
|
||||
|
||||
TEST(kv_conv_slot_is_a_rolling_window) {
|
||||
|
||||
Reference in new issue
Block a user