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

+46
View File
@@ -1272,6 +1272,32 @@ int Builder::declare_drafter(const RadDrafterDecl* d) {
return RAD_OK;
}
/* A SERIAL HEAD THAT READS THE TRUNK'S CACHE AND KEEPS NONE (rad_builder.h). Checked here for the
* reason declare_drafter checks everything: the driver only reaches the head once a request
* speculates, and a head staged the wrong way round costs acceptance and says nothing. */
int Builder::drafter_shared_kv(int pos_offset) {
if (finished_) {
err(RAD_E_STATE, "drafter_shared_kv after declare finished");
return RAD_E_STATE;
}
if (prog_.drafter.kind != RAD_DRAFT_SERIAL) {
err(RAD_E_STATE, "drafter_shared_kv: %s. Only a SERIAL head runs round after round at one "
"position; declare it with rad_declare_drafter first.",
prog_.drafter.kind == RAD_DRAFT_NONE ? "no drafter is declared"
: "the declared drafter is a BLOCK drafter");
return RAD_E_STATE;
}
if (pos_offset != 0 && pos_offset != 1) {
err(RAD_E_INVAL, "drafter_shared_kv '%s': pos_offset %d. The rows sit at the committed "
"position (0) or one past it (1); nothing else names a position the head "
"was trained at.", prog_.drafter_name.c_str(), pos_offset);
return RAD_E_INVAL;
}
prog_.drafter_shared_kv = true;
prog_.drafter_pos_offset = pos_offset;
return RAD_OK;
}
void Builder::note_v(const char* f, va_list ap) {
char msg[1024];
vsnprintf(msg, sizeof msg, f ? f : "", ap);
@@ -1522,6 +1548,8 @@ void Builder::finish_kv_groups() {
default: break;
}
std::sort(gi.layers.begin(), gi.layers.end());
gi.drafter = prog_.meta.n_layers > 0 && !gi.layers.empty() &&
gi.layers.front() >= prog_.meta.n_layers;
/* A group nothing is bound to is a group the block manager cannot size: how many state
* instances a sequence owns is the layer count, and assuming one would make the page size
@@ -1628,6 +1656,19 @@ int Builder::finish() {
finish_weight_uses();
finish_layouts();
finish_kv_groups();
/* A HEAD DECLARED TO KEEP NO CACHE OF ITS OWN (rad_drafter_shared_kv) is given no history pass:
* the scheduler owes it none. A KV group bound at one of its layers -- meta.n_layers and above
* are the drafter's -- would then be read without anything ever having written it. */
if (prog_.drafter_shared_kv)
for (size_t g = 1; g < prog_.kv_groups.size(); ++g)
for (int l : prog_.kv_groups[g].layers)
if (l >= prog_.meta.n_layers) {
err(RAD_E_STATE, "drafter '%s' keeps no cache of its own (rad_drafter_shared_kv) "
"and its layer %d is bound to KV group '%s', which no pass "
"would ever write", prog_.drafter_name.c_str(), l,
prog_.kv_groups[g].name.c_str());
break;
}
finish_buffer_liveness();
int s = plan_buffers(prog_, &bufrep_);
@@ -1762,6 +1803,11 @@ int rad_declare_drafter(RadBuilder* b, const RadDrafterDecl* d) {
return B(b)->declare_drafter(d);
}
int rad_drafter_shared_kv(RadBuilder* b, int pos_offset) {
if (!b) return RAD_E_INVAL;
return B(b)->drafter_shared_kv(pos_offset);
}
int rad_declare_encoder(RadBuilder* b, const RadEncoderDecl* d) {
if (!b) return RAD_E_INVAL;
return B(b)->declare_encoder(d);