Merge Gemma 4 31B: PRs #74, #75, #81 and #86 (sfjes, keptn42), with fixes

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:
Deadcode committed 2026-10-12 20:46:37 +02:00
84 files changed
+10292 -230

No files matched your search

+75
View File
@@ -706,6 +706,38 @@ TEST(tune_requests_are_one_per_kernel_and_shape) {
}
/* ================================================================== KV groups */
/* A HEAD THAT KEEPS NO CACHE OF ITS OWN BINDS NONE: it is given no history pass, so a group bound at
* one of its layers (meta.n_layers and above) would be read and never written. The same head
* borrowing only the trunk's layers finishes. */
TEST(a_head_with_no_cache_of_its_own_binds_no_group_of_its_own) {
NEED_PLUGIN(reg)
for (bool own : { false, true }) {
Builder b(reg, make_meta(), make_ctx());
RadKVGroupDecl kd{};
kd.kind = RAD_KV_FULL; kd.dtype = RAD_BF16; kd.n_head_kv = 8; kd.head_dim = 128;
const rad_kvgroup g = b.decl_kv_group("kv_full", &kd);
const RadParam p[] = { RAD_RANGE("q_len", 1, 16), RAD_INT("head_dim", 128),
RAD_INT("window", 0), RAD_INT("block_size", 16),
RAD_INT("causal", 1), RAD_INT("n_head", 8),
RAD_STR("kv_dtype", "bf16") };
b.decl_op("t_attn", p, 7, nullptr, 0);
CHECK_OK(b.bind_layer_kv(0, g));
CHECK_OK(b.bind_layer_kv(1, g));
if (own) CHECK_OK(b.bind_layer_kv(2, g)); /* make_meta: two trunk layers, so 2 is the head's */
RadDrafterDecl d{};
d.kind = RAD_DRAFT_SERIAL; d.name = "mtp"; d.depth = 3;
CHECK_OK(rad_declare_drafter(&b, &d));
CHECK_OK(rad_drafter_shared_kv(&b, 0));
b.finish();
if (own) {
CHECK_EQ(b.status(), RAD_E_STATE);
CHECK(has(b.errors().back(), "keeps no cache of its own"));
} else {
CHECK_OK(b.status());
}
}
}
TEST(kv_block_size_comes_off_the_kernel) {
NEED_PLUGIN(reg)
Builder b(reg, make_meta(), make_ctx());
@@ -1005,6 +1037,49 @@ TEST(the_drafter_name_survives_the_program_leaving_the_builder) {
CHECK_EQ(p.drafter.depth, 3);
}
/* A HEAD THAT KEEPS NO CACHE OF ITS OWN (rad_drafter_shared_kv) is a property of a declared SERIAL
* drafter. With none declared, with a block drafter, or at a position no head sits at, the call is
* refused at declare -- a head staged the wrong way round costs acceptance and says nothing. */
TEST(a_head_that_keeps_no_cache_of_its_own_is_a_serial_one) {
Registry reg;
{
Builder b(reg, make_meta(), make_ctx());
CHECK_EQ(rad_drafter_shared_kv(&b, 0), RAD_E_STATE); /* nothing declared */
}
{
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;
CHECK_OK(rad_declare_drafter(&b, &d));
CHECK_EQ(rad_drafter_shared_kv(&b, 0), RAD_E_STATE); /* a block drafter */
CHECK(!b.program().drafter_shared_kv);
}
{
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_shared_kv(&b, 2), RAD_E_INVAL); /* no position a head sits at */
CHECK(!b.program().drafter_shared_kv);
CHECK_OK(rad_drafter_shared_kv(&b, 1));
CHECK(b.program().drafter_shared_kv);
CHECK_EQ(b.program().drafter_pos_offset, 1);
}
{
/* Every drafter that does not ask keeps the old shape. */
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(!b.program().drafter_shared_kv);
CHECK_EQ(b.program().drafter_pos_offset, 0);
}
}
/* ================================================================== the enum name tables
*