Support pruned expert variants (GSQ-RCO Coder: 256 of 512 experts)

- iq_pack.py: derive n_expert from the router tensor shape (was hardcoded 512)
- expert_layout.cpp: parse the pack header's recorded n_expert instead of the
  caller's compile-time canonical geometry; use it for the contiguity stride
- gguf_reader.hpp: Qwen4ExpGuard expert-count checks become presence-only
- generate.cpp: read qwen4exp.expert_count/expert_used_count from the model
  file into the runtime geometry; MTP drafter keeps canonical geometry (the
  draft is the original 512-expert head); serve gate allows profile-less
  caches; K from metadata
- layer.cpp: native fused router stays 512x10-only, generic top-k fallback
- prefill: expert count taken from the geometry everywhere; route_kernel
  templatized (512->16, 256->8 registers/lane, else generic router_top10)
This commit is contained in:
pete committed 2026-09-28 12:29:32 +01:00
1 parent 898d6a4c3e
commit 8bef4161cf
8 files changed
+77 -43

No files matched your search

+11 -2
View File
@@ -93,7 +93,16 @@ bool expert_layout_load(const std::string& pack_dir, int64_t n_layers, int64_t n
L.max_blob = 0;
std::string line;
while (std::getline(in, line)) {
if (line.empty() || line[0] == '#') continue;
if (line.empty() || line[0] == '#') {
if (!line.empty() && line[0] == '#') {
// v3 packs record their expert count in the header; a pruned model (GSQ-RCO Coder) ships
// fewer experts than the canonical geometry the caller passes, which is a compile-time
// default, so the header wins.
const size_t at = line.find("(n_expert ");
if (at != std::string::npos) L.n_expert = std::atoll(line.c_str() + at + 10);
}
continue;
}
std::istringstream ss(line);
long long l = -1, gt = -1, dt = -1;
unsigned long long off = 0, blob = 0, go = 0, uo = 0, dox = 0;
@@ -130,7 +139,7 @@ bool expert_layout_load(const std::string& pack_dir, int64_t n_layers, int64_t n
err = "native_experts.txt: layer " + std::to_string(l) + " is missing or not contiguous";
return false;
}
at += L.bytes[(size_t) l] * (uint64_t) n_expert;
at += L.bytes[(size_t) l] * (uint64_t) L.n_expert;
}
L.total = at;
g_layout = L;