core: the model's geometry is read from its GGUF metadata and checked against the shape the kernels are compiled for

read_geometry (gguf_reader.hpp) fills ModelGeometry from the qwen4exp.* keys, under llama.cpp's names: layers, widths,
GDN, attention, indexer (heads, key width, pooling block from compress_ratios, top-k), rope width, hyper-connections,
experts, RMS epsilon, and the vocabulary from tokenizer.ggml.tokens. The six keys the guard always required stay
required; any other absent key keeps the compiled value. Keys that state one thing twice must agree (the interval and
compress_ratios, key and value head widths, routed and shared expert widths, ssm.inner_size and state x v heads).

check_architecture no longer hard-codes 48 / 2560 / 24 / 2: it reads the geometry and refuses a file the kernels are not
compiled for, naming the key ("qwen4exp.block_count = 40, the kernels are compiled for 48"). Only the expert count,
the experts per token (1..64) and the vocabulary may differ. ModelGeometry moves to core/geometry.hpp (no
dependencies), with kCompiledGeometry; the kernels that fix a dimension at compile time static_assert it there, in the
CUDA/HIP tree and the SYCL copies (plus qsa_prompt_attn_xmx).

generate.cpp takes the geometry and K from read_geometry, and the native embedding takes n_embd / n_vocab from it
instead of a literal 248320. The QSA kernel shapes come from one qsa_shapes(g) (layout.hpp) in layer, mtp, session,
verify and prefill, so n_rot, idx_block and idx_top_k follow the geometry too. Mirrored in sycl/.

Tested: tests/core/gguf_geometry_test.cpp (new, synthetic GGUFs) 28/28, gguf_split_test and gguf_reader_test pass,
built with MSVC /W4 /WX on Windows. `gguf_geometry_test --real` on Unsloth's Qwen3.8-Flash-Next UD-IQ4_XS shard 1
reads exactly the compiled shape and the guard accepts it. Not built here: the engine (no CUDA, HIP or oneAPI compiler
on this PC), so generate/layer/mtp/session/verify/prefill and the kernel asserts are reviewed, not compiled.
This commit is contained in:
Shawn Jackson authored and Niko1221 committed 2026-10-13 00:49:57 +02:00
1 parent 20b501743d
commit f812e9a162
42 files changed
+644 -169

No files matched your search

+16 -10
View File
@@ -2831,8 +2831,10 @@ int main(int argc, char** argv) {
? "AVX1 128-bit (iq_avx1, the older-CPU build)"
: "ggml-cpu vec_dot (no AVX2: the older-CPU build)")
: std::getenv("STRATA_NO_IQ256") == nullptr ? "AVX-2" : "ggml-cpu vec_dot (STRATA_NO_IQ256 set)");
strata::core::ModelGeometry g; // canonical defaults; the model file overrides the MoE shape below
int64_t K = 10;
// the compiled shape; a native model's file replaces it below with its own metadata (read_geometry), which a
// pruned variant (GSQ-RCO Coder, fewer than 512 experts) differs from
strata::core::ModelGeometry g;
int64_t K = g.n_expert_used;
// THE ROPE CONFIG RESOLVES HERE, BEFORE ANY WEIGHT MOVES - the CLI and the model file have both spoken,
// and `session_init` below builds the rope table from it and captures the kernels reading its constants
// (rope_scaling.hpp); the only hard constraint is "set before that", and dying on a bad rope key beats
@@ -2845,19 +2847,24 @@ int main(int argc, char** argv) {
std::string gguf_rope_type;
double gguf_rope_base = 0, gguf_rope_factor = 0, gguf_rope_orig_ctx = 0;
if (!o.native_preset.empty()) {
// a pruned variant (GSQ-RCO Coder) ships fewer experts than the canonical 512x10; the model file
// is the authority on its own MoE shape - everything else in the geometry is unchanged
// the model file is the authority on its own geometry; the kernels' compiled shape is checked against
// it before any weight moves, naming the key that differs
try {
strata::GgufFile model_gguf(o.native_shards.front()); // the metadata shard
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.expert_count")) g.n_expert = (int64_t) v->u;
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.expert_used_count")) K = (int64_t) v->u;
std::string gerr = strata::read_geometry(model_gguf, g);
if (gerr.empty()) gerr = strata::geometry_unsupported(g);
if (!gerr.empty()) {
std::fprintf(stderr, "strata generate: %s: %s\n", o.native_shards.front().c_str(), gerr.c_str());
return 1;
}
K = g.n_expert_used;
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.rope.freq_base")) gguf_rope_base = v->num();
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.rope.scaling.type")) gguf_rope_type = v->s;
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.rope.scaling.factor")) gguf_rope_factor = v->num();
if (const strata::MetaValue* v = model_gguf.get("qwen4exp.rope.scaling.original_context_length"))
gguf_rope_orig_ctx = v->num();
} catch (const std::exception& e) {
std::fprintf(stderr, "strata generate: reading the model's expert shape from %s: %s\n",
std::fprintf(stderr, "strata generate: reading the model's geometry from %s: %s\n",
o.native_preset.c_str(), e.what());
return 1;
}
@@ -2942,10 +2949,9 @@ int main(int argc, char** argv) {
"and --prefill CHUNK\n", o.pack.c_str());
return 2;
}
const strata::core::ModelGeometry g0;
const auto embed_t0 = std::chrono::steady_clock::now();
if (!native_embed.load(o.embd_gguf.empty() ? o.native_shards : std::vector<std::string>{o.embd_gguf}, g0.n_embd,
248320, err)) {
if (!native_embed.load(o.embd_gguf.empty() ? o.native_shards : std::vector<std::string>{o.embd_gguf}, g.n_embd,
g.n_vocab, err)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;
}