Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Model families: Qwen3.6-35B-A3B (qwen35moe) recognised, geometry and layout from the GGUF, no engine path yet
Niko122114ba7a627afd
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 0f6426a45..566349ce6 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -253,6 +253,10 @@ if(STRATA_BUILD_TESTS)add_executable(gguf_split_test tests/core/gguf_split_test.cpp)target_link_libraries(gguf_split_test PRIVATE strata_artifact)add_test(NAME gguf_split_test COMMAND gguf_split_test)+ # the model families (qwen4exp, qwen35moe): the guards, the geometry from metadata, the layout tables (synthetic)+ add_executable(model_family_test tests/core/model_family_test.cpp)+ target_link_libraries(model_family_test PRIVATE strata_artifact)+ add_test(NAME model_family_test COMMAND model_family_test)# how --batch cuts a prompt read into pieces (a layer split with no slot decoding must still reach a BYIELD)add_executable(batch_read_test tests/program/batch_read_test.cpp)target_include_directories(batch_read_test PRIVATE include)diff --git a/include/strata/artifact/gguf_reader.hpp b/include/strata/artifact/gguf_reader.hppindex 1be014326..3b960c1a3 100644--- a/include/strata/artifact/gguf_reader.hpp+++ b/include/strata/artifact/gguf_reader.hpp@@ -33,6 +33,7 @@#include <algorithm>#include "strata/artifact/gguf_split.hpp"+#include "strata/artifact/model_family.hpp"#ifdef _WIN32#define WIN32_LEAN_AND_MEAN@@ -210,6 +211,10 @@ inline bool block_geometry(uint32_t t, int& elems, int& bytes) {elems = 1;bytes = 1;return true;+ case 39: // MXFP4: one E8M0 scale + 16 bytes of 4-bit values (Qwen3.6's MXFP4_MOE experts)+ elems = 32;+ bytes = 17;+ return true;case 42:elems = 64;bytes = 18;@@ -577,18 +582,54 @@ private:std::map<std::string, std::pair<size_t, const TensorInfo*>> index_;};-// ---- architecture guard (P1.S2). The engine is specialised to ONE model; anything else must be-// refused with a precise error rather than silently mis-run.+// ---- architecture guard (P1.S2). The engine is specialised to known model families (model_family.hpp);+// anything else must be refused with a precise error rather than silently mis-run. `check_architecture` accepts+// every family Strata knows (qwen4exp, qwen35moe); `check_engine_architecture` below also wants one this engine+// runs.struct Qwen4ExpGuard {uint32_t block_count = 48, hidden = 2560, experts = 0, experts_used = 0, head_count = 24,head_count_kv = 2; // 0 = presence-only: pruned variants (GSQ-RCO Coder) legitimately ship// fewer experts than the canonical 512; the graph reads the true value};+/// The family of the model whose metadata shard is `g` (Unknown when it has no or another architecture).+inline ModelFamily model_family(const GgufFile& g) {+ const MetaValue* arch = g.get("general.architecture");+ return arch ? model_family_from_arch(arch->s) : ModelFamily::Unknown;+}++/// Qwen3.6-35B-A3B's guard: every key the geometry is read from must be present (core::geometry_from_gguf),+/// and the few that the layer pattern depends on must have the values the model has.+inline std::string check_architecture_qwen35moe(const GgufFile& g) {+ static const char* const keys[] = {+ "qwen35moe.block_count", "qwen35moe.embedding_length", "qwen35moe.attention.head_count",+ "qwen35moe.attention.head_count_kv", "qwen35moe.attention.key_length", "qwen35moe.attention.value_length",+ "qwen35moe.expert_count", "qwen35moe.expert_used_count", "qwen35moe.expert_feed_forward_length",+ "qwen35moe.expert_shared_feed_forward_length", "qwen35moe.ssm.conv_kernel", "qwen35moe.ssm.state_size",+ "qwen35moe.ssm.group_count", "qwen35moe.ssm.time_step_rank", "qwen35moe.ssm.inner_size",+ "qwen35moe.full_attention_interval", "qwen35moe.nextn_predict_layers",+ };+ for (const char* k : keys) {+ const MetaValue* v = g.get(k);+ if (!v) return std::string("missing ") + k;+ if (!v->is_num()) return std::string(k) + " is not a number";+ }+ const MetaValue* nl = g.get("qwen35moe.block_count");+ const MetaValue* mtp = g.get("qwen35moe.nextn_predict_layers");+ if (mtp->u >= nl->u) return "qwen35moe.nextn_predict_layers is not smaller than qwen35moe.block_count";+ if (g.get("qwen35moe.full_attention_interval")->u < 2)+ return "qwen35moe.full_attention_interval must be at least 2 (the GDN / attention pattern)";+ return {};+}+inline std::string check_architecture(const GgufFile& g, const Qwen4ExpGuard& want = {}) {const MetaValue* arch = g.get("general.architecture");if (!arch) return "missing general.architecture";- if (arch->s != "qwen4exp") return "architecture is '" + arch->s + "', this engine requires 'qwen4exp'";+ const ModelFamily family = model_family_from_arch(arch->s);+ if (family == ModelFamily::Qwen35Moe) return check_architecture_qwen35moe(g);+ if (family != ModelFamily::Qwen4Exp)+ return "architecture is '" + arch->s + "', Strata reads 'qwen4exp' (Qwen3.8-Flash-Next) and 'qwen35moe' "+ "(Qwen3.6-35B-A3B)";struct Req {const char* key;uint64_t want;@@ -610,4 +651,12 @@ inline std::string check_architecture(const GgufFile& g, const Qwen4ExpGuard& wareturn {}; // empty == ok}+/// The engine's guard: `check_architecture`, then a family this engine has a path for. A recognised family+/// it does not run yet (Qwen3.6) is refused with a message that says so.+inline std::string check_engine_architecture(const GgufFile& g, const Qwen4ExpGuard& want = {}) {+ std::string err = check_architecture(g, want);+ if (!err.empty()) return err;+ return model_family_not_supported(model_family(g));+}+} // namespace stratadiff --git a/include/strata/artifact/model_family.hpp b/include/strata/artifact/model_family.hppnew file mode 100644index 000000000..9507c9d06--- /dev/null+++ b/include/strata/artifact/model_family.hpp@@ -0,0 +1,64 @@+// include/strata/artifact/model_family.hpp - which model family a GGUF holds, from its general.architecture.+//+// Strata was written for one model (Qwen3.8-Flash-Next, `qwen4exp`). Qwen3.6-35B-A3B (`qwen35moe`) is a close+// cousin (same tokenizer, the same Gated-DeltaNet + gated-attention 3:1 layer pattern, the same head dims), so the+// reader, the geometry and the layout tables know both. The ENGINE runs only the families `model_family_runs`+// names; a recognised family it does not run yet is refused with `model_family_not_supported`, not mis-run.+//+// No dependencies: the GGUF reader (the architecture guard) and the core geometry both include this.+#pragma once++#include <string>++namespace strata {++enum class ModelFamily {+ Unknown = 0,+ Qwen4Exp, ///< Qwen3.8-Flash-Next and its fine-tunes / pruned variants (Swift 1.5, the Coder)+ Qwen35Moe, ///< Qwen3.6-35B-A3B (Unsloth's MTP GGUFs): plain pre-norm residual, dense attention, nextn MTP block+};++inline ModelFamily model_family_from_arch(const std::string& arch) {+ if (arch == "qwen4exp") return ModelFamily::Qwen4Exp;+ if (arch == "qwen35moe") return ModelFamily::Qwen35Moe;+ return ModelFamily::Unknown;+}++/// The GGUF architecture string (also the metadata key prefix: "<arch>.block_count").+inline const char* model_family_arch(ModelFamily f) {+ switch (f) {+ case ModelFamily::Qwen4Exp:+ return "qwen4exp";+ case ModelFamily::Qwen35Moe:+ return "qwen35moe";+ default:+ return "";+ }+}++/// The model's name for messages.+inline const char* model_family_title(ModelFamily f) {+ switch (f) {+ case ModelFamily::Qwen4Exp:+ return "Qwen3.8-Flash-Next";+ case ModelFamily::Qwen35Moe:+ return "Qwen3.6-35B-A3B";+ default:+ return "an unknown model";+ }+}++/// Whether this engine has a path for the family. Qwen3.6 is recognised (reader, geometry, layout, setup) but+/// has no engine path yet: phase T1 of NEW-MODELS-PLAN.md adds it.+inline bool model_family_runs(ModelFamily f) { return f == ModelFamily::Qwen4Exp; }++/// The refusal for a recognised family the engine does not run (empty when it runs it).+inline std::string model_family_not_supported(ModelFamily f) {+ if (model_family_runs(f)) return {};+ if (f == ModelFamily::Unknown) return "this is not a model family Strata knows";+ return std::string(model_family_title(f)) + " (architecture '" + model_family_arch(f) ++ "') is recognised, but this engine does not run it yet - support for it is in development. "+ "Use a Qwen3.8-Flash-Next model file (setup.py installs one)";+}++} // namespace stratadiff --git a/include/strata/core/family_layout.hpp b/include/strata/core/family_layout.hppnew file mode 100644index 000000000..726e006a9--- /dev/null+++ b/include/strata/core/family_layout.hpp@@ -0,0 +1,284 @@+// include/strata/core/family_layout.hpp - per model family: the geometry read from a GGUF's metadata, and the+// tensor layout table (every tensor of a layer, by name and GGUF shape) checked against a model file's directory.+//+// Header-only and GPU-free: the engine, the tools and the unit tests (tests/core/model_family_test.cpp) share it.+//+// * geometry_from_gguf: fills core::ModelGeometry from "<arch>.*" keys. For qwen4exp the keys a file does not+// carry keep Flash-Next's values (the struct defaults, which every published qwen4exp file matches); for+// qwen35moe every key is required (check_architecture_qwen35moe).+// * compiled_geometry_mismatch: the first field where a geometry differs from the shapes this engine's kernels+// are built for (the expert count and top-k are run-time values and are not compared).+// * layer_tensors / global_tensors: the layout tables. Names are GGUF names (blk.N.<suffix>), shapes are in+// GGUF order (dim 0 contiguous), as tools/gguf_reader.py prints them.+// * check_gguf_layout: every table entry present with its shape, inside its file, of a type with a known block+// size; and, for a family whose table is complete (qwen35moe), no blk.* tensor the table does not name.+#pragma once++#include "strata/artifact/gguf_reader.hpp"+#include "strata/artifact/model_family.hpp"+#include "strata/core/geometry.hpp"++#include <cstdint>+#include <cstdio>+#include <set>+#include <string>+#include <vector>++namespace strata::core {++/// Fills `g` (and `top_k`, the experts per token) from the metadata shard `meta`. False with `err` when the+/// architecture guard refuses the file or a key has an impossible value.+inline bool geometry_from_gguf(const strata::GgufFile& meta, ModelGeometry& g, int64_t& top_k, std::string& err) {+ err = strata::check_architecture(meta);+ if (!err.empty()) return false;+ const strata::ModelFamily family = strata::model_family(meta);+ const std::string p = std::string(strata::model_family_arch(family)) + ".";+ g = ModelGeometry{};+ g.family = family;+ // a key the file carries replaces the default; `required` keys were checked present by the guard+ auto num = [&](const char* key, int64_t& dst) {+ if (const strata::MetaValue* v = meta.get(p + key))+ if (v->is_num()) dst = (int64_t) v->u;+ };+ int64_t block_count = g.n_layers, key_length = g.head_dim, value_length = -1;+ num("block_count", block_count);+ num("embedding_length", g.n_embd);+ num("attention.head_count", g.n_head);+ num("attention.head_count_kv", g.n_head_kv);+ num("attention.key_length", key_length);+ num("attention.value_length", value_length);+ num("expert_count", g.n_expert);+ top_k = 10;+ num("expert_used_count", top_k);+ num("expert_feed_forward_length", g.n_ff);+ num("expert_shared_feed_forward_length", g.n_ff_shexp);+ num("ssm.conv_kernel", g.ssm_d_conv);+ num("ssm.state_size", g.ssm_state_size);+ num("ssm.group_count", g.ssm_k_heads);+ num("ssm.time_step_rank", g.ssm_v_heads);+ num("ssm.inner_size", g.ssm_value_dim);+ num("full_attention_interval", g.qsa_interval);+ g.head_dim = key_length;+ if (family == strata::ModelFamily::Qwen35Moe) {+ num("nextn_predict_layers", g.n_mtp_layers);+ g.hc = g.hc_lr = 0; // a plain pre-norm residual+ g.idx_q_heads = g.idx_key_dim = 0; // dense attention, no sparse indexer+ } else {+ num("hyper_connection.count", g.hc);+ num("hyper_connection.low_rank", g.hc_lr);+ num("attention.indexer.head_count", g.idx_q_heads);+ num("attention.indexer.key_length", g.idx_key_dim);+ }+ g.n_layers = block_count - g.n_mtp_layers;+ g.ssm_conv_channels = 2 * g.ssm_state_size * g.ssm_k_heads + g.ssm_value_dim;+ if (const strata::MetaValue* v = meta.get("tokenizer.ggml.tokens"))+ if (v->type == strata::MetaType::ARRAY && v->count > 0) g.n_vocab = (int64_t) v->count;++ char buf[256];+ auto bad = [&](const char* what) {+ std::snprintf(buf, sizeof buf, "%s: %s", meta.path().c_str(), what);+ err = buf;+ return false;+ };+ if (g.n_layers <= 0 || g.n_embd <= 0 || g.n_head <= 0 || g.n_head_kv <= 0 || g.head_dim <= 0 || g.n_expert <= 0 ||+ top_k <= 0 || top_k > g.n_expert || g.n_ff <= 0 || g.ssm_state_size <= 0 || g.ssm_k_heads <= 0 ||+ g.ssm_v_heads <= 0 || g.ssm_d_conv <= 0 || g.qsa_interval < 2)+ return bad("a geometry key is zero or out of range");+ if (value_length >= 0 && value_length != key_length) return bad("attention.key_length != attention.value_length");+ if (g.ssm_value_dim != g.ssm_state_size * g.ssm_v_heads) return bad("ssm.inner_size != ssm.state_size * ssm.time_step_rank");+ if (g.ssm_v_heads % g.ssm_k_heads) return bad("ssm.time_step_rank is not a multiple of ssm.group_count");+ if (g.n_head % g.n_head_kv) return bad("attention.head_count is not a multiple of attention.head_count_kv");+ if (g.n_layers % g.qsa_interval) return bad("the layer count is not a multiple of full_attention_interval");+ return true;+}++/// The first geometry field that differs from the shapes this engine's kernels are built for (ModelGeometry's+/// defaults, Flash-Next's), as "<what> is <got>, this engine's kernels are built for <want>"; empty when none.+/// n_expert and top-k are run-time sizes (the Coder ships 256 experts) and n_vocab is the embedding's business.+inline std::string compiled_geometry_mismatch(const ModelGeometry& g) {+ const ModelGeometry c;+ if (g.family != c.family)+ return std::string("the model is ") + strata::model_family_title(g.family) + ", this engine's kernels are built "+ "for " + strata::model_family_title(c.family);+ struct F {+ const char* what;+ int64_t got, want;+ };+ const F fields[] = {+ {"embedding_length", g.n_embd, c.n_embd},+ {"the layer count", g.n_layers, c.n_layers},+ {"full_attention_interval", g.qsa_interval, c.qsa_interval},+ {"ssm.state_size", g.ssm_state_size, c.ssm_state_size},+ {"ssm.group_count", g.ssm_k_heads, c.ssm_k_heads},+ {"ssm.time_step_rank", g.ssm_v_heads, c.ssm_v_heads},+ {"ssm.conv_kernel", g.ssm_d_conv, c.ssm_d_conv},+ {"the GDN conv channels", g.ssm_conv_channels, c.ssm_conv_channels},+ {"ssm.inner_size", g.ssm_value_dim, c.ssm_value_dim},+ {"attention.head_count", g.n_head, c.n_head},+ {"attention.head_count_kv", g.n_head_kv, c.n_head_kv},+ {"attention.key_length", g.head_dim, c.head_dim},+ {"attention.indexer.head_count", g.idx_q_heads, c.idx_q_heads},+ {"attention.indexer.key_length", g.idx_key_dim, c.idx_key_dim},+ {"hyper_connection.count", g.hc, c.hc},+ {"hyper_connection.low_rank", g.hc_lr, c.hc_lr},+ {"expert_feed_forward_length", g.n_ff, c.n_ff},+ {"expert_shared_feed_forward_length", g.n_ff_shexp, c.n_ff_shexp},+ {"the in-file MTP layers", g.n_mtp_layers, c.n_mtp_layers},+ };+ for (const F& f : fields)+ if (f.got != f.want) {+ char buf[256];+ std::snprintf(buf, sizeof buf, "%s is %lld, this engine's kernels are built for %lld", f.what,+ (long long) f.got, (long long) f.want);+ return buf;+ }+ return {};+}++enum class LayerKind { Gdn, Attention, Mtp };++inline LayerKind layer_kind(const ModelGeometry& g, int64_t layer) {+ if (layer >= g.n_layers) return LayerKind::Mtp;+ return is_qsa_layer(g, layer) ? LayerKind::Attention : LayerKind::Gdn;+}++/// One tensor of the layout table: its name (a blk.N. suffix for a layer's, the full name for a global one) and+/// its GGUF shape.+struct TensorWant {+ std::string name;+ std::vector<int64_t> shape;+};++/// Every tensor of layer `layer` (kind from `layer_kind`), by family.+inline std::vector<TensorWant> layer_tensors(const ModelGeometry& g, int64_t layer) {+ const LayerKind kind = layer_kind(g, layer);+ const int64_t N = g.n_embd, NE = g.n_expert, FF = g.n_ff, FS = g.n_ff_shexp;+ std::vector<TensorWant> t;+ auto add = [&](const char* s, std::vector<int64_t> shape) { t.push_back({s, std::move(shape)}); };+ // MoE, every layer (the MTP block's too)+ add("ffn_gate_inp.weight", {N, NE});+ add("ffn_gate_inp_shexp.weight", {N});+ add("ffn_gate_shexp.weight", {N, FS});+ add("ffn_up_shexp.weight", {N, FS});+ add("ffn_down_shexp.weight", {FS, N});+ add("ffn_gate_exps.weight", {N, FF, NE});+ add("ffn_up_exps.weight", {N, FF, NE});+ add("ffn_down_exps.weight", {FF, N, NE});+ if (g.has_hyper_connections()) {+ // gated residual (Flash-Next): `gr_read` transposes, so the file's orientation is [hc_dim, hc_lr] / [hc_lr, hc_dim]+ const int64_t H = g.hc_dim();+ add("hc_attn_down.weight", {H, g.hc_lr});+ add("hc_attn_up.weight", {g.hc_lr, H});+ add("hc_attn_inject.weight", {H, g.hc});+ add("hc_attn_norm.weight", {H});+ add("hc_ffn_down.weight", {H, g.hc_lr});+ add("hc_ffn_up.weight", {g.hc_lr, H});+ add("hc_ffn_inject.weight", {H, g.hc});+ add("hc_ffn_norm.weight", {H});+ } else {+ // plain pre-norm residual (qwen35moe): x += mixer(rms(x)); x += moe(rms(x))+ add("attn_norm.weight", {N});+ add("post_attention_norm.weight", {N});+ }+ if (kind == LayerKind::Gdn) {+ add("attn_qkv.weight", {N, g.ssm_conv_channels});+ add("attn_gate.weight", {N, g.ssm_value_dim});+ add("ssm_out.weight", {g.ssm_value_dim, N});+ add("ssm_conv1d.weight", {g.ssm_d_conv, g.ssm_conv_channels});+ add("ssm_alpha.weight", {N, g.ssm_v_heads});+ add("ssm_beta.weight", {N, g.ssm_v_heads});+ add("ssm_a", {g.ssm_v_heads});+ add("ssm_dt.bias", {g.ssm_v_heads});+ add("ssm_norm.weight", {g.ssm_state_size});+ } else {+ // attention (query + output gate in attn_q), also the MTP block's+ add("attn_q.weight", {N, 2 * g.n_head * g.head_dim});+ add("attn_k.weight", {N, g.n_head_kv * g.head_dim});+ add("attn_v.weight", {N, g.n_head_kv * g.head_dim});+ add("attn_output.weight", {g.n_head * g.head_dim, N});+ add("attn_q_norm.weight", {g.head_dim});+ add("attn_k_norm.weight", {g.head_dim});+ if (g.has_indexer() && kind == LayerKind::Attention) {+ // `q_proj` is the QUERY count, `k_proj` the KEY width (round 194: they are different numbers)+ add("indexer.q_proj.weight", {N, g.idx_q_heads * g.idx_key_dim});+ add("indexer.k_proj.weight", {N, g.idx_key_dim});+ add("indexer.q_norm.weight", {g.idx_key_dim});+ add("indexer.k_norm.weight", {g.idx_key_dim});+ }+ }+ if (kind == LayerKind::Mtp) {+ // the GGUF-native MTP block: eh_proj over concat(enorm(embedding), hnorm(hidden))+ add("nextn.eh_proj.weight", {2 * N, N});+ add("nextn.enorm.weight", {N});+ add("nextn.hnorm.weight", {N});+ add("nextn.shared_head_norm.weight", {N});+ }+ return t;+}++/// The tensors outside the layers, by family. (Flash-Next's output_norm, PLE and n-gram tables are not listed:+/// the published files place them differently, and their loaders check them.)+inline std::vector<TensorWant> global_tensors(const ModelGeometry& g) {+ std::vector<TensorWant> t;+ t.push_back({"token_embd.weight", {g.n_embd, g.n_vocab}});+ t.push_back({"output.weight", {g.n_embd, g.n_vocab}});+ if (g.has_hyper_connections()) {+ t.push_back({"output_hc_down.weight", {g.hc_dim(), g.hc_lr}});+ t.push_back({"output_hc_up.weight", {g.hc_lr, g.hc_dim()}});+ t.push_back({"output_hc_norm.weight", {g.hc_dim()}});+ } else {+ t.push_back({"output_norm.weight", {g.n_embd}});+ }+ return t;+}++/// Whether the family's table names every blk.* tensor its files carry (then an unnamed one is an error).+inline bool layout_table_complete(const ModelGeometry& g) { return g.family == strata::ModelFamily::Qwen35Moe; }++/// Checks the model `m` (all shards) against the layout table of `g`. `checked` counts the tensors found.+inline bool check_gguf_layout(const strata::GgufModel& m, const ModelGeometry& g, std::string& err,+ size_t* checked = nullptr) {+ std::set<std::string> named;+ size_t n = 0;+ auto check = [&](const std::string& name, const std::vector<int64_t>& shape) {+ named.insert(name);+ size_t s = 0;+ const strata::TensorInfo* t = m.find(name, &s);+ if (!t) {+ err = "missing " + name;+ return false;+ }+ bool same = t->shape.size() == shape.size();+ for (size_t i = 0; same && i < shape.size(); ++i) same = t->shape[i] == (uint64_t) shape[i];+ if (!same) {+ std::string got, want;+ for (uint64_t d : t->shape) got += (got.empty() ? "" : ", ") + std::to_string(d);+ for (int64_t d : shape) want += (want.empty() ? "" : ", ") + std::to_string(d);+ err = name + " is [" + got + "], the " + strata::model_family_title(g.family) + " layout wants [" + want + "]";+ return false;+ }+ if (!m.in_bounds(*t, s)) {+ err = name + " (" + t->type_name() + ") has no known size inside " + m.shard(s).path();+ return false;+ }+ ++n;+ return true;+ };+ for (const TensorWant& w : global_tensors(g))+ if (!check(w.name, w.shape)) return false;+ for (int64_t l = 0; l < g.n_layers + g.n_mtp_layers; ++l)+ for (const TensorWant& w : layer_tensors(g, l))+ if (!check("blk." + std::to_string(l) + "." + w.name, w.shape)) return false;+ if (layout_table_complete(g)) {+ for (size_t s = 0; s < m.size(); ++s)+ for (const strata::TensorInfo& t : m.shard(s).tensors())+ if (!named.count(t.name)) {+ err = t.name + " is not in the " + std::string(strata::model_family_title(g.family)) + " layout";+ return false;+ }+ }+ if (checked) *checked = n;+ return true;+}++} // namespace strata::corediff --git a/include/strata/core/geometry.hpp b/include/strata/core/geometry.hppnew file mode 100644index 000000000..5ffc3dd64--- /dev/null+++ b/include/strata/core/geometry.hpp@@ -0,0 +1,62 @@+// include/strata/core/geometry.hpp - the model's geometry (moved out of layout.hpp so that tools and tests can use+// it without the weight table). The defaults are Qwen3.8-Flash-Next's: they are the shapes this engine's kernels+// are built for. core::geometry_from_gguf (family_layout.hpp) fills one from a model file's metadata.+#pragma once++#include "strata/artifact/model_family.hpp"++#include <cstdint>++namespace strata::core {++/// The model's geometry, taken from `docs/semantics.md` and the artifact's own metadata. Every field here+/// is a number a kernel depends on, so a change is a change to a kernel contract and not a tuning knob.+struct ModelGeometry {+ int64_t n_embd = 2560;+ int64_t n_layers = 48; ///< the trunk's layers (an in-file MTP block is counted in n_mtp_layers)+ int64_t qsa_interval = 4; ///< every 4th layer is full attention: layers 3, 7, ... 47++ // GDN (36 layers)+ int64_t ssm_state_size = 128;+ int64_t ssm_k_heads = 16;+ int64_t ssm_v_heads = 48;+ int64_t ssm_d_conv = 4;+ int64_t ssm_conv_channels = 10240; ///< 2*128*16 + 128*48+ int64_t ssm_value_dim = 6144; ///< 128 * 48++ // QSA (12 layers)+ int64_t n_head = 24;+ int64_t n_head_kv = 2;+ int64_t head_dim = 256;+ int64_t idx_q_heads = 4; ///< 0: no sparse indexer (dense attention only: qwen35moe)+ int64_t idx_key_dim = 128;++ // gated residual, on every layer+ int64_t hc = 4; ///< 0: no hyper-connections (a plain pre-norm residual: qwen35moe)+ int64_t hc_lr = 320;++ // MoE, on every layer+ int64_t n_expert = 512;+ int64_t n_ff = 640;+ int64_t n_ff_shexp = 640; ///< the shared expert's FFN width++ // appended for the model families (NEW-MODELS-PLAN.md T0); the defaults keep Flash-Next's values+ ModelFamily family = ModelFamily::Qwen4Exp;+ int64_t n_mtp_layers = 0; ///< MTP blocks inside the model file, after the trunk (qwen35moe: blk.40)+ int64_t n_vocab = 248320;++ int64_t hc_dim() const { return hc * n_embd; }+ /// `layer % qsa_interval == qsa_interval - 1` is full attention. Derived, not a second list.+ int64_t n_qsa_layers() const { return n_layers / qsa_interval; }+ int64_t n_gdn_layers() const { return n_layers - n_qsa_layers(); }+ bool has_indexer() const { return idx_q_heads > 0; }+ bool has_hyper_connections() const { return hc > 0; }+};++/// True for the full-attention layers. `docs/semantics.md` gives this twice over - `full_attention_interval+/// = 4` and an explicit `attention.compress_ratios` array - and this is the first of the two.+inline bool is_qsa_layer(const ModelGeometry& g, int64_t layer) {+ return layer % g.qsa_interval == g.qsa_interval - 1;+}++} // namespace strata::corediff --git a/include/strata/core/layout.hpp b/include/strata/core/layout.hppindex 7b27fec95..f99af593c 100644--- a/include/strata/core/layout.hpp+++ b/include/strata/core/layout.hpp@@ -15,6 +15,7 @@// at LOAD time - not as a wrong number inside a GEMV at token 4000.#pragma once+#include "strata/core/geometry.hpp"#include "strata/core/weights.hpp"#include <cstdint>@@ -22,48 +23,6 @@namespace strata::core {-/// The model's geometry, taken from `docs/semantics.md` and the artifact's own metadata. Every field here-/// is a number a kernel depends on, so a change is a change to a kernel contract and not a tuning knob.-struct ModelGeometry {- int64_t n_embd = 2560;- int64_t n_layers = 48;- int64_t qsa_interval = 4; ///< every 4th layer is full attention: layers 3, 7, ... 47-- // GDN (36 layers)- int64_t ssm_state_size = 128;- int64_t ssm_k_heads = 16;- int64_t ssm_v_heads = 48;- int64_t ssm_d_conv = 4;- int64_t ssm_conv_channels = 10240; ///< 2*128*16 + 128*48- int64_t ssm_value_dim = 6144; ///< 128 * 48-- // QSA (12 layers)- int64_t n_head = 24;- int64_t n_head_kv = 2;- int64_t head_dim = 256;- int64_t idx_q_heads = 4;- int64_t idx_key_dim = 128;-- // gated residual, on every layer- int64_t hc = 4;- int64_t hc_lr = 320;-- // MoE, on every layer- int64_t n_expert = 512;- int64_t n_ff = 640;-- int64_t hc_dim() const { return hc * n_embd; }- /// `layer % qsa_interval == qsa_interval - 1` is full attention. Derived, not a second list.- int64_t n_qsa_layers() const { return n_layers / qsa_interval; }- int64_t n_gdn_layers() const { return n_layers - n_qsa_layers(); }-};--/// True for the full-attention layers. `docs/semantics.md` gives this twice over - `full_attention_interval-/// = 4` and an explicit `attention.compress_ratios` array - and this is the first of the two.-inline bool is_qsa_layer(const ModelGeometry& g, int64_t layer) {- return layer % g.qsa_interval == g.qsa_interval - 1;-}-/// One layer's tensors, resolved by NAME. `get("attn_qkv.weight")` looks up `blk.<layer>.attn_qkv.weight`/// and returns null if the pack does not have it - a null is information, because a GDN layer has no/// `attn_q` and a QSA layer has no `attn_qkv`.diff --git a/serve/server.py b/serve/server.pyindex ff1b935c3..fbf4ddcfa 100644--- a/serve/server.py+++ b/serve/server.py@@ -6298,6 +6298,15 @@ def check_request_sampling(req) -> None:raise ValueError(f"{key}: {'an integer' if integer else 'a number'}")+# the API's model name per model family (the GGUF architecture, "arch" in the config) when the config names none+FAMILY_MODEL_NAMES = {"qwen4exp": "qwen3.8-flash-next", "qwen35moe": "qwen3.6-35b-a3b"}+++def default_model_name(cfg: dict) -> str:+ """The config's "model_name", else its family's name ("arch": qwen4exp, qwen35moe), else Flash-Next's."""+ return cfg.get("model_name") or FAMILY_MODEL_NAMES.get(cfg.get("arch") or "qwen4exp", "qwen3.8-flash-next")++def main() -> int:ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)ap.add_argument("--engine", choices=["mock", "strata"], default="mock")@@ -6437,7 +6446,7 @@ def main() -> int:# the model's own chat template (exported with its tokenizer), else the original model'stpl = tpath / "chat_template.jinja"svc = Service(engine, tok, ChatTemplate(tpl if tpl.exists() else ROOT / "serve/chat_template.jinja"),- model_name=cfg.get("model_name", "qwen3.8-flash-next"), vision=vision,+ model_name=default_model_name(cfg), vision=vision,sampling_defaults=sampling_defaults,fit_max_tokens=a.fit_max_tokens or cfg.get("fit_max_tokens") is True)svc.reasoning_close_retry = cfg.get("reasoning_close_retry") is True # #1053: opt-in, off by defaultdiff --git a/serve/test_family_name.py b/serve/test_family_name.pynew file mode 100644index 000000000..cd4024ff3--- /dev/null+++ b/serve/test_family_name.py@@ -0,0 +1,30 @@+"""serve/test_family_name.py - the API's model name per model family (NEW-MODELS-PLAN.md T0): the config's+"model_name" wins; without one, the family's ("arch": qwen4exp -> qwen3.8-flash-next, qwen35moe -> qwen3.6-35b-a3b),+and Flash-Next's for a config that names neither (every config setup wrote before).++ python -m unittest serve.test_family_name+"""+from __future__ import annotations++import unittest++from serve.server import FAMILY_MODEL_NAMES, default_model_name+++class FamilyName(unittest.TestCase):+ def test_config_name_wins(self):+ self.assertEqual(default_model_name({"model_name": "qwen3.8-flash-next-q2_0", "arch": "qwen35moe"}),+ "qwen3.8-flash-next-q2_0")++ def test_per_family(self):+ self.assertEqual(default_model_name({"arch": "qwen35moe"}), "qwen3.6-35b-a3b")+ self.assertEqual(default_model_name({"arch": "qwen4exp"}), "qwen3.8-flash-next")++ def test_old_configs(self):+ self.assertEqual(default_model_name({}), "qwen3.8-flash-next")+ self.assertEqual(default_model_name({"arch": "something-else"}), "qwen3.8-flash-next")+ self.assertEqual(set(FAMILY_MODEL_NAMES), {"qwen4exp", "qwen35moe"})+++if __name__ == "__main__":+ unittest.main()diff --git a/setup.py b/setup.pyindex 7d291e1c6..e33e0df6d 100644--- a/setup.py+++ b/setup.py@@ -68,6 +68,7 @@ HF_REVISIONS = {"ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF": "b22d729eae29b5796f76fb70f91aef549b9fc52c", # 2026-09-24"ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF": "5348543e0147355ac9cbcb031184a3546350988e", # 2026-09-29"unsloth/Qwen3.8-Flash-Next-GGUF": "38bb39ee97821de2c9009abb7e93950eec396e66", # 2026-09-30+ "unsloth/Qwen3.6-35B-A3B-MTP-GGUF": "5bc3e238d916f48a861bac2f8a1990a0e9b7e98d", # 2026-10-12}@@ -299,6 +300,29 @@ FAMILIES = {"sha256": {**UNSLOTH_SHARDS, **UNSLOTH_IQ4_XS_SHARDS}},}MMPROJ = "mmproj-Qwen3.8-Flash-Next-BF16.gguf"+# NEW-MODELS-PLAN.md T0: Qwen3.6-35B-A3B (GGUF architecture qwen35moe), Unsloth's GGUFs with the MTP block. Setup knows+# the family and downloads its files (pinned revision, size and SHA-256 checked: the Hub's LFS pointers), but this+# engine has no path for it yet and refuses the file with "not supported yet". Not in FAMILIES (the menu, the+# installed configs, the packs): only --family qwen36 reaches it (preview_family).+QWEN36_FILES = {+ "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf": (22853663008, "55983c5a75a1ab969824077b3bb3de4146e82a9234072b48ad4e8f92ad3fe9f1"),+ "Qwen3.6-35B-A3B-UD-Q6_K_XL.gguf": (32611711264, "35fce994cd36104a7dc1bd8a4bdf13778145664c00fdef6773aebc9246e5019c"),+ "Qwen3.6-35B-A3B-Q8_0.gguf": (37801097504, "c1283d8b80c3e38b2735ddbc9766d3b3126f44d6c484be419d4e101d09a76131"),+ "mmproj-F16.gguf": (899283584, "71f3cbc1f7cc0f30d09d41cfa924c0060827ebc33bf15ace7e86661e856f0160"),+}+PREVIEW_FAMILIES = {+ "qwen36": {"title": "Qwen3.6-35B-A3B", "by": "Qwen; GGUFs with the MTP layer by Unsloth", "arch": "qwen35moe",+ "about": "35B mixture of experts with 3B active (256 experts, top-8): a smaller cousin of "+ "Qwen3.8-Flash-Next with the same tokenizer",+ "hf": hf("unsloth/Qwen3.6-35B-A3B-MTP-GGUF"), "file": "Qwen3.6-35B-A3B-{q}.gguf", "tag": "qwen36-",+ "mmproj_hf": hf("unsloth/Qwen3.6-35B-A3B-MTP-GGUF"), "mmproj": "mmproj-F16.gguf",+ "name": "qwen3.6-35b-a3b", "license": "Apache 2.0: https://huggingface.co/Qwen/Qwen3.6-35B-A3B",+ # RAM floors from the iGPU baselines (llama.cpp: 21 / 30 / 38 GB in use, plus the OS)+ "models": {"UD-Q4_K_XL": {"about": "4-bit (Unsloth Dynamic), the smallest", "ram_gb": 32},+ "UD-Q6_K_XL": {"about": "6-bit (Unsloth Dynamic)", "ram_gb": 48},+ "Q8_0": {"about": "8-bit, the closest to the full model", "ram_gb": 48}},+ "sha256": QWEN36_FILES},+}# EXPERIMENTAL, off by default (setup asks): a control vector shipped with the repository, see its READMEESP_VECTOR = ROOT / "data" / "experimental-speed-projection" / "Qwen3.8-Flash-Next-experimental-speed-projection.gguf"# the image encoder on the GPU (~1.2 GB at 1024 image tokens) warms up before the engine starts, so the engine@@ -4824,10 +4848,57 @@ def sycl_setup(argv) -> int:return subprocess.call([sys.executable, str(script), *rest])+def preview_family(a) -> int:+ """--family qwen36: a family setup knows but the engine does not run yet (PREVIEW_FAMILIES). Downloads the chosen+ size (pinned revision, size and SHA-256 checked) and, with --vision, the image encoder - and says plainly that+ Strata cannot start it yet. Nothing is configured: no engine, no pack, no start script."""+ fam = PREVIEW_FAMILIES[a.family]+ names = list(fam["models"])+ say()+ say(f" {fam['title']} - {fam['by']}: {fam['about']}")+ warn(f"this Strata version does not run {fam['title']} yet (support is in development): setup downloads its "+ "files, and the engine refuses them with a message until a version that runs it")+ if a.model and a.model not in names:+ fail(f"{fam['title']} has no {a.model} model file", "choose one of: " + ", ".join(names))+ ram = ram_gb()+ for i, m in enumerate(names, 1):+ d = fam["models"][m]+ size = fam["sha256"][fam["file"].format(q=m)][0]+ fit = "" if ram >= d["ram_gb"] else f" <- needs {d['ram_gb']} GB RAM, you have {ram:.0f}"+ say(f" {i}) {m:10s} {d['about']}; download {size / 1e9:.1f} GB{fit}")+ if a.check:+ return 0+ model = a.model or names[int(ask("Which size?", [str(i) for i in range(1, len(names) + 1)], "1", a.yes)) - 1]+ say(f" Its license: {fam['license']}")+ want = [fam["file"].format(q=model)]+ if a.vision in ("yes", "gpu", "cpu"):+ want.append(fam["mmproj"])+ folder = Path(a.models_dir) / (fam["tag"] + model)+ files = [folder / w for w in want]+ left = sum(fam["sha256"][f.name][0] - (f.with_name(f.name + ".part").stat().st_size+ if f.with_name(f.name + ".part").is_file() else 0)+ for f in files if not (f.exists() and done(f))) / 1e9+ if left and free_gb(folder) < left + 1:+ fail(f"not enough free disk space in {folder}: need ~{left + 1:.0f} GB", "use --models-dir on a bigger drive")+ step(5, f"downloading {fam['title']} {model}")+ for f in files:+ url = (fam["mmproj_hf"] if f.name == fam["mmproj"] else fam["hf"]) + f.name+ download(url, f, "vision encoder" if f.name == fam["mmproj"] else None)+ verify_sha256(f, *fam["sha256"][f.name])+ ok(f"{fam['title']} {model}: {folder}")+ say()+ say(f"{fam['title']} is downloaded, but this Strata version cannot run it yet (its engine path is in "+ "development); nothing was configured. Run setup again without --family qwen36 to install a model it runs.")+ return 0++def main() -> int:ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)- ap.add_argument("--family", choices=list(FAMILIES), help="qwen = Qwen3.8-Flash-Next, swift = Swift 1.5")- ap.add_argument("--model", choices=list(MODELS))+ ap.add_argument("--family", choices=list(FAMILIES) + list(PREVIEW_FAMILIES),+ help="qwen = Qwen3.8-Flash-Next, swift = Swift 1.5 (qwen36 = Qwen3.6-35B-A3B: download only, the "+ "engine does not run it yet)")+ ap.add_argument("--model", choices=list(dict.fromkeys([*MODELS, *(m for f in PREVIEW_FAMILIES.values()+ for m in f["models"])])))ap.add_argument("--context", type=int)ap.add_argument("--rope-scaling", choices=["none", "linear", "yarn"],help="the RoPE extension for a context past the model's trained 262144: linear (position "@@ -4929,6 +5000,9 @@ def main() -> int:"sycl = Intel Arc, EXPERIMENTAL: Linux, built from source (docs/INTEL_ARC.md)")ap.add_argument("--skip-build", action="store_true", help=argparse.SUPPRESS)a = ap.parse_args()+ if a.model and a.model not in MODELS and a.family not in PREVIEW_FAMILIES:+ ap.error(f"--model {a.model} is a size of " + ", ".join(f"--family {f}" for f, d in PREVIEW_FAMILIES.items()+ if a.model in d["models"]))if a.source:os.environ["STRATA_SOURCE"] = a.sourceif a.inspect: # headers only: nothing is installed@@ -4953,6 +5027,8 @@ def main() -> int:roots = [data, *elsewhere]if a.models_dir is None:a.models_dir = str(data / "models")+ if a.family in PREVIEW_FAMILIES: # a family the engine does not run yet: its files only+ return preview_family(a)if a.rollback_engine: # #670return rollback_engine(12 if a.cuda == "12" else 13)diff --git a/src/core/native_dense.cpp b/src/core/native_dense.cppindex f75b03b24..aba2882b8 100644--- a/src/core/native_dense.cpp+++ b/src/core/native_dense.cpp@@ -272,7 +272,7 @@ bool NativeDense::load(const std::vector<std::string>& shards, WeightTable& tablconst auto* tensors = gguf.get("split.tensors.count");if (gguf.get("general.architecture") && (!number || number->u == 0)) {// splitter may copy general.architecture into every shard (Huihui abliterated re-split)- err = strata::check_architecture(gguf);+ err = strata::check_engine_architecture(gguf);if (!err.empty()) return false;have_architecture = true;if (count && number && tensors && number->u == 0 && count->u > 1) {diff --git a/src/core/native_head.cpp b/src/core/native_head.cppindex 93ec0fd2f..10e280a90 100644--- a/src/core/native_head.cpp+++ b/src/core/native_head.cpp@@ -28,7 +28,7 @@ bool NativeHead::load(const std::vector<std::string>& shards, int64_t n_in, int6// The architecture is the metadata shard's; output.weight comes from whichever shard holds it (shard 2// of Unsloth's UD-Q4_K_XL, whose shard 1 holds no tensor). GgufModel refuses a duplicate across shards.const strata::GgufModel model(shards);- err = strata::check_architecture(model.meta());+ err = strata::check_engine_architecture(model.meta());if (!err.empty()) return false;size_t at = 0;const strata::TensorInfo* tensor = model.find("output.weight", &at);@@ -116,7 +116,7 @@ bool NativeEmbed::load(const std::vector<std::string>& shards, int64_t n_embd, iconst strata::GgufModel model(shards);// --embd-gguf's one-tensor file (tools/embd_bf16_pack.py) says "strata-embd": only its tensor is checkedconst strata::MetaValue* arch = model.meta().get("general.architecture");- err = arch != nullptr && arch->s == "strata-embd" ? std::string() : strata::check_architecture(model.meta());+ err = arch != nullptr && arch->s == "strata-embd" ? std::string() : strata::check_engine_architecture(model.meta());if (!err.empty()) { err = "native embedding: " + err; return false; }size_t at = 0;const strata::TensorInfo* t = model.find("token_embd.weight", &at);diff --git a/src/program/generate.cpp b/src/program/generate.cppindex 7a93c0a3e..11f0dc55e 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -84,6 +84,7 @@#define NOMINMAX // gguf_reader.hpp includes windows.h#endif#include "strata/artifact/gguf_reader.hpp"+#include "strata/core/family_layout.hpp"#if defined(_WIN32)#include <windows.h>#include <psapi.h>@@ -2532,6 +2533,16 @@ int main(int argc, char** argv) {// every shard of the model (<name>-0000N-of-0000M.gguf beside --native). A missing shard is an error// here: it used to be skipped, leaving a model with some tensors absent and a later error, or none.o.native_shards = strata::gguf_split_paths(o.native_preset);+ // a model family Strata recognises but has no engine path for yet (Qwen3.6-35B-A3B) is refused here,+ // with a message that says so, before anything else about the file is judged+ {+ const strata::GgufFile meta(o.native_shards.front());+ const std::string why = strata::model_family_not_supported(strata::model_family(meta));+ if (strata::model_family(meta) != strata::ModelFamily::Unknown && !why.empty()) {+ std::fprintf(stderr, "strata generate: --native %s: %s\n", o.native_preset.c_str(), why.c_str());+ return 2;+ }+ }// --ple-gguf defaults to the shard that holds the PLE table, found by name: shard 2 of the ISTA files// and of Unsloth's UD-Q4_K_XL, shard 1 of Swift'sif (o.ple_gguf.empty() && !o.no_ple) {@@ -2831,7 +2842,7 @@ 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+ strata::core::ModelGeometry g; // canonical defaults; with --native the model file's geometry belowint64_t K = 10;// 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@@ -2845,16 +2856,26 @@ 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 geometry is the model file's (core::geometry_from_gguf: every "<arch>.*" shape key), checked+ // against the shapes this engine's kernels are built for. The expert count and top-k are run-time+ // sizes: a pruned variant (GSQ-RCO Coder) ships fewer experts than the canonical 512x10.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;- 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"))+ std::string gerr;+ if (!strata::core::geometry_from_gguf(model_gguf, g, K, gerr)) {+ std::fprintf(stderr, "strata generate: %s\n", gerr.c_str());+ return 1;+ }+ const std::string mismatch = strata::core::compiled_geometry_mismatch(g);+ if (!mismatch.empty()) {+ std::fprintf(stderr, "strata generate: %s: %s\n", o.native_preset.c_str(), mismatch.c_str());+ return 1;+ }+ const std::string p = std::string(strata::model_family_arch(g.family)) + ".";+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.freq_base")) gguf_rope_base = v->num();+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.scaling.type")) gguf_rope_type = v->s;+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.scaling.factor")) gguf_rope_factor = v->num();+ if (const strata::MetaValue* v = model_gguf.get(p + "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",diff --git a/sycl/src/core/native_dense.cpp b/sycl/src/core/native_dense.cppindex ae3c892f2..9e1c79136 100644--- a/sycl/src/core/native_dense.cpp+++ b/sycl/src/core/native_dense.cpp@@ -170,7 +170,7 @@ bool NativeDense::load(const std::vector<std::string> &shards,const auto* number = gguf.get("split.no");const auto* tensors = gguf.get("split.tensors.count");if (gguf.get("general.architecture")) {- err = strata::check_architecture(gguf);+ err = strata::check_engine_architecture(gguf);if (!err.empty()) return false;have_architecture = true;if (count && number && tensors && number->u == 0 && count->u > 1) {diff --git a/sycl/src/core/native_head.cpp b/sycl/src/core/native_head.cppindex 9afd21995..fbfa3fe9d 100644--- a/sycl/src/core/native_head.cpp+++ b/sycl/src/core/native_head.cpp@@ -32,7 +32,7 @@ bool NativeHead::load(const std::vector<std::string> &shards, int64_t n_in,// The architecture is the metadata shard's; output.weight comes from whichever shard holds it (shard 2// of Unsloth's UD-Q4_K_XL, whose shard 1 holds no tensor). GgufModel refuses a duplicate across shards.const strata::GgufModel model(shards);- err = strata::check_architecture(model.meta());+ err = strata::check_engine_architecture(model.meta());if (!err.empty()) return false;size_t at = 0;const strata::TensorInfo* tensor = model.find("output.weight", &at);@@ -171,7 +171,7 @@ bool NativeEmbed::load(const std::vector<std::string> &shards, int64_t n_embd,const strata::GgufModel model(shards);// --embd-gguf's one-tensor file (tools/embd_bf16_pack.py) says "strata-embd": only its tensor is checkedconst strata::MetaValue* arch = model.meta().get("general.architecture");- err = arch != nullptr && arch->s == "strata-embd" ? std::string() : strata::check_architecture(model.meta());+ err = arch != nullptr && arch->s == "strata-embd" ? std::string() : strata::check_engine_architecture(model.meta());if (!err.empty()) { err = "native embedding: " + err; return false; }size_t at = 0;const strata::TensorInfo* t = model.find("token_embd.weight", &at);diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex 5d6f58669..04dfafbf3 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -85,6 +85,7 @@ namespace strata::prefill { void set_nonresident_share(double share); } // SYC#define NOMINMAX // gguf_reader.hpp includes windows.h#endif#include "strata/artifact/gguf_reader.hpp"+#include "strata/core/family_layout.hpp"#if defined(_WIN32)#include <windows.h>#include <psapi.h>@@ -2313,6 +2314,16 @@ int main(int argc, char **argv) try {// every shard of the model (<name>-0000N-of-0000M.gguf beside --native). A missing shard is an error// here: it used to be skipped, leaving a model with some tensors absent and a later error, or none.o.native_shards = strata::gguf_split_paths(o.native_preset);+ // a model family Strata recognises but has no engine path for yet (Qwen3.6-35B-A3B) is refused here,+ // with a message that says so, before anything else about the file is judged+ {+ const strata::GgufFile meta(o.native_shards.front());+ const std::string why = strata::model_family_not_supported(strata::model_family(meta));+ if (strata::model_family(meta) != strata::ModelFamily::Unknown && !why.empty()) {+ std::fprintf(stderr, "strata generate: --native %s: %s\n", o.native_preset.c_str(), why.c_str());+ return 2;+ }+ }// --ple-gguf defaults to the shard that holds the PLE table, found by name: shard 2 of the ISTA files// and of Unsloth's UD-Q4_K_XL, shard 1 of Swift'sif (o.ple_gguf.empty() && !o.no_ple) {@@ -2605,7 +2616,7 @@ int main(int argc, char **argv) try {"(multi-token for the i-quant gate/up rows)\n",!strata::kernels::cpu::cpu_avx2_ok() ? "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+ strata::core::ModelGeometry g; // canonical defaults; with --native the model file's geometry belowint64_t K = 10;// 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@@ -2619,16 +2630,26 @@ int main(int argc, char **argv) try {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 geometry is the model file's (core::geometry_from_gguf: every "<arch>.*" shape key), checked+ // against the shapes this engine's kernels are built for. The expert count and top-k are run-time+ // sizes: a pruned variant (GSQ-RCO Coder) ships fewer experts than the canonical 512x10.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;- 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"))+ std::string gerr;+ if (!strata::core::geometry_from_gguf(model_gguf, g, K, gerr)) {+ std::fprintf(stderr, "strata generate: %s\n", gerr.c_str());+ return 1;+ }+ const std::string mismatch = strata::core::compiled_geometry_mismatch(g);+ if (!mismatch.empty()) {+ std::fprintf(stderr, "strata generate: %s: %s\n", o.native_preset.c_str(), mismatch.c_str());+ return 1;+ }+ const std::string p = std::string(strata::model_family_arch(g.family)) + ".";+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.freq_base")) gguf_rope_base = v->num();+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.scaling.type")) gguf_rope_type = v->s;+ if (const strata::MetaValue* v = model_gguf.get(p + "rope.scaling.factor")) gguf_rope_factor = v->num();+ if (const strata::MetaValue* v = model_gguf.get(p + "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",diff --git a/tests/core/gguf_fixture.hpp b/tests/core/gguf_fixture.hppindex 677a5cd85..4fcfd94fa 100644--- a/tests/core/gguf_fixture.hpp+++ b/tests/core/gguf_fixture.hpp@@ -18,14 +18,16 @@ namespace fixture {struct Kv {std::string key;- uint32_t type = 8; ///< GGUF value type: 8 string, 2 u16, 4 u32, 5 i32+ uint32_t type = 8; ///< GGUF value type: 8 string, 2 u16, 4 u32, 5 i32, 9 array of stringsstd::string s;uint64_t u = 0;+ std::vector<std::string> items; ///< type 9};-inline Kv str(const std::string& k, const std::string& v) { return Kv{k, 8, v, 0}; }-inline Kv u16(const std::string& k, uint64_t v) { return Kv{k, 2, {}, v}; }-inline Kv i32(const std::string& k, uint64_t v) { return Kv{k, 5, {}, v}; }-inline Kv u32(const std::string& k, uint64_t v) { return Kv{k, 4, {}, v}; }+inline Kv str(const std::string& k, const std::string& v) { return Kv{k, 8, v, 0, {}}; }+inline Kv u16(const std::string& k, uint64_t v) { return Kv{k, 2, {}, v, {}}; }+inline Kv i32(const std::string& k, uint64_t v) { return Kv{k, 5, {}, v, {}}; }+inline Kv u32(const std::string& k, uint64_t v) { return Kv{k, 4, {}, v, {}}; }+inline Kv str_array(const std::string& k, std::vector<std::string> v) { return Kv{k, 9, {}, 0, std::move(v)}; }struct Tensor {std::string name;@@ -65,6 +67,7 @@ inline Written write(const std::filesystem::path& path, const std::vector<Kv>& kif (k.type == 8) puts(k.s);else if (k.type == 2) { const uint16_t v = (uint16_t) k.u; put(&v, 2); }else if (k.type == 4 || k.type == 5) { const uint32_t v = (uint32_t) k.u; put(&v, 4); }+ else if (k.type == 9) { put32(8); put64(k.items.size()); for (const auto& it : k.items) puts(it); }else throw std::runtime_error("fixture: unsupported metadata type");}Written w;diff --git a/tests/core/model_family_test.cpp b/tests/core/model_family_test.cppnew file mode 100644index 000000000..479340d63--- /dev/null+++ b/tests/core/model_family_test.cpp@@ -0,0 +1,292 @@+// tests/core/model_family_test.cpp - the model families (NEW-MODELS-PLAN.md T0) on synthetic GGUFs: no model, no GPU.+//+// * the architecture guard accepts qwen4exp and qwen35moe and refuses anything else; the engine's guard refuses+// qwen35moe with "not ... yet" (no engine path for Qwen3.6 before T1);+// * geometry_from_gguf reads Qwen3.6-35B-A3B's real metadata values (hidden 2048, 40 + 1 MTP layers, 32 GDN V+// heads, conv 8192, no hyper-connections, no indexer) and Flash-Next's as exactly the compiled defaults;+// * the layout tables, on tiny files of either family: a complete file passes, a wrong shape, a missing tensor+// and (qwen35moe) a tensor the table does not name are refused, naming the tensor.+//+// `model_family_test --real SHARD`: the same view of a real model (headers only): family, geometry, the kernels'+// verdict and the layout check over every shard.+#include "gguf_fixture.hpp"++#include "strata/core/family_layout.hpp"++#include <chrono>+#include <cstdio>+#include <filesystem>+#include <string>+#include <vector>++namespace fs = std::filesystem;++namespace {+int g_fail = 0;+void check(bool ok, const std::string& what) {+ std::printf(" %-90s %s\n", what.c_str(), ok ? "ok" : "FAIL");+ if (!ok) ++g_fail;+}++struct TempDir {+ fs::path path;+ TempDir() {+ path = fs::temp_directory_path() /+ ("strata-model-family-test-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));+ fs::create_directories(path);+ }+ ~TempDir() {+ std::error_code ignored;+ fs::remove_all(path, ignored);+ }+};++using fixture::Kv;+using fixture::Tensor;+const uint32_t F32 = 0;++struct Dims {+ uint64_t block_count, embd, heads, heads_kv, key_len, experts, used, ff, ff_sh, conv, state, groups, v_heads,+ inner, interval, nextn, hc, hc_lr, idx_heads, idx_key;+};+// Qwen3.6-35B-A3B (unsloth/Qwen3.6-35B-A3B-MTP-GGUF, every quant) and Qwen3.8-Flash-Next, as their files say+const Dims kQwen36 = {41, 2048, 16, 2, 256, 256, 8, 512, 512, 4, 128, 16, 32, 4096, 4, 1, 0, 0, 0, 0};+const Dims kFlashNext = {48, 2560, 24, 2, 256, 512, 10, 640, 640, 4, 128, 16, 48, 6144, 4, 0, 4, 320, 4, 128};+// tiny models of each family for the layout checks (every tensor F32, a few KB)+const Dims kTiny36 = {5, 64, 2, 1, 16, 4, 2, 32, 32, 4, 8, 2, 4, 32, 4, 1, 0, 0, 0, 0};+const Dims kTinyFlash = {8, 64, 2, 1, 16, 4, 2, 32, 32, 4, 8, 2, 4, 32, 4, 0, 2, 8, 2, 8};++std::vector<Kv> metadata(const char* arch, const Dims& d, uint64_t vocab) {+ const std::string p = std::string(arch) + ".";+ std::vector<Kv> kv = {fixture::str("general.architecture", arch),+ fixture::u32(p + "block_count", d.block_count),+ fixture::u32(p + "embedding_length", d.embd),+ fixture::u32(p + "attention.head_count", d.heads),+ fixture::u32(p + "attention.head_count_kv", d.heads_kv),+ fixture::u32(p + "attention.key_length", d.key_len),+ fixture::u32(p + "attention.value_length", d.key_len),+ fixture::u32(p + "expert_count", d.experts),+ fixture::u32(p + "expert_used_count", d.used),+ fixture::u32(p + "expert_feed_forward_length", d.ff),+ fixture::u32(p + "expert_shared_feed_forward_length", d.ff_sh),+ fixture::u32(p + "ssm.conv_kernel", d.conv),+ fixture::u32(p + "ssm.state_size", d.state),+ fixture::u32(p + "ssm.group_count", d.groups),+ fixture::u32(p + "ssm.time_step_rank", d.v_heads),+ fixture::u32(p + "ssm.inner_size", d.inner),+ fixture::u32(p + "full_attention_interval", d.interval)};+ if (std::string(arch) == "qwen35moe") {+ kv.push_back(fixture::u32(p + "nextn_predict_layers", d.nextn));+ } else {+ kv.push_back(fixture::u32(p + "hyper_connection.count", d.hc));+ kv.push_back(fixture::u32(p + "hyper_connection.low_rank", d.hc_lr));+ kv.push_back(fixture::u32(p + "attention.indexer.head_count", d.idx_heads));+ kv.push_back(fixture::u32(p + "attention.indexer.key_length", d.idx_key));+ }+ std::vector<std::string> tokens;+ for (uint64_t i = 0; i < vocab; ++i) tokens.push_back("t" + std::to_string(i));+ kv.push_back(fixture::str_array("tokenizer.ggml.tokens", tokens));+ return kv;+}++/// The tensors the layout table of `g` names, as F32 fixtures.+std::vector<Tensor> tensors_of(const strata::core::ModelGeometry& g) {+ std::vector<Tensor> ts;+ uint8_t seed = 1;+ auto add = [&](const std::string& name, const std::vector<int64_t>& shape) {+ std::vector<uint64_t> s(shape.begin(), shape.end());+ ts.push_back({name, s, F32, seed++});+ };+ for (const auto& w : strata::core::global_tensors(g)) add(w.name, w.shape);+ for (int64_t l = 0; l < g.n_layers + g.n_mtp_layers; ++l)+ for (const auto& w : strata::core::layer_tensors(g, l)) add("blk." + std::to_string(l) + "." + w.name, w.shape);+ return ts;+}++bool geometry_of(const fs::path& p, strata::core::ModelGeometry& g, int64_t& k, std::string& err) {+ const strata::GgufFile f(p.string());+ return strata::core::geometry_from_gguf(f, g, k, err);+}++std::string layout_error(const fs::path& dir, const char* arch, const Dims& d, uint64_t vocab,+ void (*mutate)(std::vector<Tensor>&)) {+ const fs::path meta = dir / "meta.gguf";+ fixture::write(meta, metadata(arch, d, vocab), {});+ strata::core::ModelGeometry g;+ int64_t k = 0;+ std::string err;+ if (std::string(arch) == "qwen35moe") {+ if (!geometry_of(meta, g, k, err)) return "geometry: " + err;+ } else {+ // the qwen4exp guard pins Flash-Next's own block count and widths, so the tiny model's geometry is set here+ g.n_layers = (int64_t) d.block_count;+ g.n_embd = (int64_t) d.embd;+ g.n_head = (int64_t) d.heads;+ g.n_head_kv = (int64_t) d.heads_kv;+ g.head_dim = (int64_t) d.key_len;+ g.n_expert = (int64_t) d.experts;+ g.n_ff = (int64_t) d.ff;+ g.n_ff_shexp = (int64_t) d.ff_sh;+ g.ssm_d_conv = (int64_t) d.conv;+ g.ssm_state_size = (int64_t) d.state;+ g.ssm_k_heads = (int64_t) d.groups;+ g.ssm_v_heads = (int64_t) d.v_heads;+ g.ssm_value_dim = (int64_t) d.inner;+ g.ssm_conv_channels = 2 * g.ssm_state_size * g.ssm_k_heads + g.ssm_value_dim;+ g.hc = (int64_t) d.hc;+ g.hc_lr = (int64_t) d.hc_lr;+ g.idx_q_heads = (int64_t) d.idx_heads;+ g.idx_key_dim = (int64_t) d.idx_key;+ g.n_vocab = (int64_t) vocab;+ }+ std::vector<Tensor> ts = tensors_of(g);+ if (mutate) mutate(ts);+ const fs::path model = dir / (std::string(arch) + "-tiny.gguf");+ fixture::write(model, metadata(arch, d, vocab), ts);+ const strata::GgufModel m({model.string()});+ size_t n = 0;+ if (!strata::core::check_gguf_layout(m, g, err, &n)) return err;+ return {};+}++int real_model(const std::string& any) {+ try {+ const strata::GgufModel m = strata::GgufModel::open(any);+ const std::string arch = strata::check_architecture(m.meta());+ std::printf(" %zu shard(s); architecture guard: %s; engine guard: %s\n", m.size(),+ arch.empty() ? "ok" : arch.c_str(),+ strata::check_engine_architecture(m.meta()).empty() ? "runs"+ : strata::check_engine_architecture(m.meta()).c_str());+ if (!arch.empty()) return 1;+ strata::core::ModelGeometry g;+ int64_t k = 0;+ std::string err;+ if (!strata::core::geometry_from_gguf(m.meta(), g, k, err)) {+ std::printf(" geometry: %s\n", err.c_str());+ return 1;+ }+ std::printf(" family %s: layers %lld (+%lld MTP), hidden %lld, attention %lld/%lld x %lld every %lld, GDN K %lld"+ " V %lld x %lld conv %lld (%lld), MoE %lld experts top-%lld FF %lld shared %lld, hc %lld, indexer"+ " %lld, vocab %lld\n",+ strata::model_family_title(g.family), (long long) g.n_layers, (long long) g.n_mtp_layers,+ (long long) g.n_embd, (long long) g.n_head, (long long) g.n_head_kv, (long long) g.head_dim,+ (long long) g.qsa_interval, (long long) g.ssm_k_heads, (long long) g.ssm_v_heads,+ (long long) g.ssm_state_size, (long long) g.ssm_conv_channels, (long long) g.ssm_d_conv,+ (long long) g.n_expert, (long long) k, (long long) g.n_ff, (long long) g.n_ff_shexp,+ (long long) g.hc, (long long) g.idx_q_heads, (long long) g.n_vocab);+ const std::string mm = strata::core::compiled_geometry_mismatch(g);+ std::printf(" compiled kernels: %s\n", mm.empty() ? "match" : mm.c_str());+ size_t n = 0;+ const bool ok = strata::core::check_gguf_layout(m, g, err, &n);+ std::printf(" layout: %s (%zu tensors checked)\n", ok ? "ok" : err.c_str(), n);+ return ok ? 0 : 1;+ } catch (const std::exception& e) {+ std::printf(" refused: %s\n", e.what());+ return 1;+ }+}+} // namespace++int main(int argc, char** argv) {+ if (argc == 3 && std::string(argv[1]) == "--real") return real_model(argv[2]);+ std::printf("model_family_test\n");+ TempDir d;+ {+ // the guards+ const fs::path q36 = d.path / "q36.gguf", fn = d.path / "fn.gguf", other = d.path / "other.gguf";+ fixture::write(q36, metadata("qwen35moe", kQwen36, 8), {});+ fixture::write(fn, metadata("qwen4exp", kFlashNext, 8), {});+ fixture::write(other, {fixture::str("general.architecture", "llama")}, {});+ const strata::GgufFile a(q36.string()), b(fn.string()), c(other.string());+ check(strata::model_family(a) == strata::ModelFamily::Qwen35Moe &&+ strata::model_family(b) == strata::ModelFamily::Qwen4Exp &&+ strata::model_family(c) == strata::ModelFamily::Unknown,+ "model_family: qwen35moe, qwen4exp, unknown");+ check(strata::check_architecture(a).empty(), "the architecture guard accepts qwen35moe");+ check(strata::check_architecture(b).empty(), "the architecture guard accepts qwen4exp");+ check(strata::check_architecture(c).find("'llama'") != std::string::npos, "and refuses llama, naming it");+ const std::string e = strata::check_engine_architecture(a);+ check(e.find("Qwen3.6-35B-A3B") != std::string::npos && e.find("does not run it yet") != std::string::npos,+ "the engine guard refuses Qwen3.6: recognised, not supported yet");+ check(strata::check_engine_architecture(b).empty(), "the engine guard runs qwen4exp");+ std::vector<Kv> kv = metadata("qwen35moe", kQwen36, 8);+ for (auto it = kv.begin(); it != kv.end(); ++it)+ if (it->key == "qwen35moe.ssm.time_step_rank") { kv.erase(it); break; }+ const fs::path miss = d.path / "miss.gguf";+ fixture::write(miss, kv, {});+ check(strata::check_architecture(strata::GgufFile(miss.string())).find("ssm.time_step_rank") != std::string::npos,+ "a qwen35moe file without ssm.time_step_rank is refused, naming the key");+ }+ {+ // the geometry of the real models, from their metadata values+ const fs::path q36 = d.path / "q36g.gguf", fn = d.path / "fng.gguf";+ fixture::write(q36, metadata("qwen35moe", kQwen36, 248320), {});+ fixture::write(fn, metadata("qwen4exp", kFlashNext, 248320), {});+ strata::core::ModelGeometry g;+ int64_t k = 0;+ std::string err;+ const bool ok = geometry_of(q36, g, k, err);+ check(ok, "Qwen3.6 geometry reads" + (ok ? std::string() : ": " + err));+ check(g.family == strata::ModelFamily::Qwen35Moe && g.n_layers == 40 && g.n_mtp_layers == 1 && g.n_embd == 2048,+ "Qwen3.6: 40 trunk layers + 1 MTP block, hidden 2048");+ check(g.n_qsa_layers() == 10 && g.n_gdn_layers() == 30 && strata::core::layer_kind(g, 3) ==+ strata::core::LayerKind::Attention && strata::core::layer_kind(g, 40) == strata::core::LayerKind::Mtp,+ "Qwen3.6: 10 attention / 30 GDN layers, layer 40 is the MTP block");+ check(g.ssm_k_heads == 16 && g.ssm_v_heads == 32 && g.ssm_conv_channels == 8192 && g.ssm_value_dim == 4096,+ "Qwen3.6 GDN: 16 K groups, 32 V heads, conv 8192, inner 4096");+ check(g.n_head == 16 && g.n_head_kv == 2 && g.head_dim == 256 && !g.has_indexer() && !g.has_hyper_connections(),+ "Qwen3.6 attention: 16 Q / 2 KV x 256, no indexer, no hyper-connections");+ check(g.n_expert == 256 && k == 8 && g.n_ff == 512 && g.n_ff_shexp == 512 && g.n_vocab == 248320,+ "Qwen3.6 MoE: 256 experts top-8, FF 512, shared 512; vocab 248320");+ check(!strata::core::compiled_geometry_mismatch(g).empty(), "Qwen3.6 does not match the compiled kernels");+ strata::core::ModelGeometry f;+ const bool okf = geometry_of(fn, f, k, err);+ const strata::core::ModelGeometry c;+ check(okf && strata::core::compiled_geometry_mismatch(f).empty() && k == 10 && f.n_expert == c.n_expert &&+ f.ssm_conv_channels == c.ssm_conv_channels && f.n_vocab == c.n_vocab && f.hc_dim() == c.hc_dim(),+ "Flash-Next's metadata gives exactly the compiled geometry");+ Dims coder = kFlashNext;+ coder.experts = 256;+ const fs::path cp = d.path / "coder.gguf";+ fixture::write(cp, metadata("qwen4exp", coder, 8), {});+ check(geometry_of(cp, f, k, err) && f.n_expert == 256 && strata::core::compiled_geometry_mismatch(f).empty(),+ "the Coder's 256 experts are a run-time size, not a kernel mismatch");+ Dims wrong = kQwen36;+ wrong.inner = 4000;+ const fs::path wp = d.path / "wrong.gguf";+ fixture::write(wp, metadata("qwen35moe", wrong, 8), {});+ check(!geometry_of(wp, f, k, err) && err.find("ssm.inner_size") != std::string::npos,+ "an inconsistent ssm.inner_size is refused");+ }+ {+ // the layout tables+ check(layout_error(d.path, "qwen35moe", kTiny36, 16, nullptr).empty(),+ "a complete qwen35moe file passes its layout (incl. the nextn MTP block)");+ const std::string ef = layout_error(d.path, "qwen4exp", kTinyFlash, 16, nullptr);+ check(ef.empty(), "a complete qwen4exp file passes its layout (hyper-connections, indexer)" ++ (ef.empty() ? std::string() : ": " + ef));+ std::string e = layout_error(d.path, "qwen35moe", kTiny36, 16, [](std::vector<Tensor>& ts) {+ for (auto& t : ts)+ if (t.name == "blk.1.ssm_conv1d.weight") t.shape[1] += 1;+ });+ check(e.find("blk.1.ssm_conv1d.weight") != std::string::npos && e.find("wants") != std::string::npos,+ "a wrong shape is refused, naming the tensor and both shapes");+ e = layout_error(d.path, "qwen35moe", kTiny36, 16, [](std::vector<Tensor>& ts) {+ for (auto it = ts.begin(); it != ts.end(); ++it)+ if (it->name == "blk.4.nextn.eh_proj.weight") { ts.erase(it); break; }+ });+ check(e == "missing blk.4.nextn.eh_proj.weight", "a missing MTP tensor is refused");+ e = layout_error(d.path, "qwen35moe", kTiny36, 16, [](std::vector<Tensor>& ts) {+ ts.push_back({"blk.0.hc_attn_norm.weight", {64}, F32, 99});+ });+ check(e.find("blk.0.hc_attn_norm.weight") != std::string::npos && e.find("not in the") != std::string::npos,+ "a tensor the qwen35moe table does not name is refused");+ e = layout_error(d.path, "qwen4exp", kTinyFlash, 16, [](std::vector<Tensor>& ts) {+ for (auto it = ts.begin(); it != ts.end(); ++it)+ if (it->name == "blk.3.indexer.k_proj.weight") { ts.erase(it); break; }+ });+ check(e == "missing blk.3.indexer.k_proj.weight", "Flash-Next: a missing indexer tensor is refused (" + e + ")");+ }+ std::printf(g_fail ? "FAILED (%d)\n" : "ALL PASSED\n", g_fail);+ return g_fail ? 1 : 0;+}diff --git a/tools/strata_inspect.py b/tools/strata_inspect.pyindex 66cb727c7..d4af5e9f6 100644--- a/tools/strata_inspect.py+++ b/tools/strata_inspect.py@@ -29,6 +29,7 @@ import quantscope as qs # noqa: E402FINGERPRINTS = ROOT / "data" / "gguf_fingerprints.json"ARCH = "qwen4exp" # Qwen3.8-Flash-Next's general.architecture+PREVIEW_ARCHS = {"qwen35moe": "Qwen3.6-35B-A3B"} # model families Strata knows but does not run yet (T0)# the files setup installs: (family, model, ModelScope repository, file name prefix) - for --fingerprintsKNOWN = [@@ -92,6 +93,9 @@ def verdict(fp: dict, table: dict) -> tuple[str, str]:layout as one: a fine-tune made with the same recipe, untested), "no" (Strata cannot run it) or "untested"(naming the tensors whose quantization no file Strata runs has for them)."""known = {k: v for k, v in table.items() if not k.startswith("_")}+ if fp["arch"] in PREVIEW_ARCHS:+ return "no", (f"{PREVIEW_ARCHS[fp['arch']]} (architecture {fp['arch']!r}): Strata recognises it, but this "+ "version does not run it yet (support is in development)")if fp["arch"] != ARCH:return "no", f"not Qwen3.8-Flash-Next (architecture {fp['arch']!r}): Strata runs only that model"exact = [k for k, v in known.items() if v["expert_bytes"] == fp["expert_bytes"] and v["bytes"] == fp["bytes"]diff --git a/tools/test_setup_qwen36.py b/tools/test_setup_qwen36.pynew file mode 100644index 000000000..adb67f82d--- /dev/null+++ b/tools/test_setup_qwen36.py@@ -0,0 +1,124 @@+"""Tests for setup.py's Qwen3.6-35B-A3B entries (NEW-MODELS-PLAN.md T0): a family setup knows and downloads (pinned+revision, size and SHA-256), which the engine does not run yet. Mocked downloads - nothing is fetched.++ python -m unittest tools.test_setup_qwen36+"""+from __future__ import annotations++import argparse+import contextlib+import io+import re+import sys+import tempfile+import unittest+from pathlib import Path+from unittest import mock++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT))+sys.path.insert(0, str(ROOT / "tools"))+import setup # noqa: E402++SHA = re.compile(r"/resolve/[0-9a-f]{40}/")+REPO = "unsloth/Qwen3.6-35B-A3B-MTP-GGUF"+++def args(**kw):+ base = dict(family="qwen36", model=None, check=False, yes=True, vision=None, models_dir=None)+ base.update(kw)+ return argparse.Namespace(**base)+++def run(fn, *a, **kw):+ out = io.StringIO()+ with contextlib.redirect_stdout(out):+ try:+ return fn(*a, **kw), out.getvalue()+ except SystemExit as e:+ return e.code, out.getvalue()+++class Qwen36Entries(unittest.TestCase):+ def test_pinned_and_hashed(self):+ fam = setup.PREVIEW_FAMILIES["qwen36"]+ self.assertEqual(setup.HF_REVISIONS[REPO], "5bc3e238d916f48a861bac2f8a1990a0e9b7e98d")+ for key in ("hf", "mmproj_hf"):+ self.assertRegex(fam[key], SHA)+ self.assertIn(REPO, fam[key])+ self.assertEqual(fam["arch"], "qwen35moe")+ self.assertEqual(list(fam["models"]), ["UD-Q4_K_XL", "UD-Q6_K_XL", "Q8_0"])+ for m in fam["models"]:+ size, sha = fam["sha256"][fam["file"].format(q=m)]+ self.assertGreater(size, 20e9)+ self.assertRegex(sha, r"^[0-9a-f]{64}$")+ self.assertEqual(fam["sha256"]["Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf"][0], 22853663008)+ self.assertIn(fam["mmproj"], fam["sha256"])++ def test_not_a_regular_family(self):+ # the menu, the installed configs and the packs never see it: it is not in FAMILIES+ self.assertNotIn("qwen36", setup.FAMILIES)+ for m, d in setup.MODELS.items():+ self.assertNotIn("qwen36", d.get("families", ()))+++class PreviewFamily(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.calls = []+ patches = [mock.patch.object(setup, "download", lambda url, dst, what=None: self.calls.append(("get", url, dst))),+ mock.patch.object(setup, "verify_sha256", lambda s, size, sha: self.calls.append(("sha", s.name, size, sha))),+ mock.patch.object(setup, "ram_gb", lambda: 64.0),+ mock.patch.object(setup, "free_gb", lambda p: 500.0)]+ for p in patches:+ p.start()+ self.addCleanup(p.stop)++ def test_downloads_the_pinned_file_and_checks_it(self):+ rc, out = run(setup.preview_family, args(model="UD-Q4_K_XL", models_dir=self.tmp.name))+ self.assertEqual(rc, 0)+ get = [c for c in self.calls if c[0] == "get"]+ self.assertEqual(len(get), 1)+ self.assertEqual(get[0][1], setup.hf(REPO) + "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf")+ self.assertEqual(get[0][2], Path(self.tmp.name) / "qwen36-UD-Q4_K_XL" / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf")+ self.assertIn(("sha", "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", 22853663008,+ "55983c5a75a1ab969824077b3bb3de4146e82a9234072b48ad4e8f92ad3fe9f1"), self.calls)+ self.assertIn("cannot run it yet", out)+ self.assertIn("does not run Qwen3.6-35B-A3B yet", out)++ def test_vision_adds_the_encoder(self):+ rc, _ = run(setup.preview_family, args(model="Q8_0", vision="yes", models_dir=self.tmp.name))+ self.assertEqual(rc, 0)+ names = [c[2].name for c in self.calls if c[0] == "get"]+ self.assertEqual(names, ["Qwen3.6-35B-A3B-Q8_0.gguf", "mmproj-F16.gguf"])++ def test_check_lists_without_downloading(self):+ rc, out = run(setup.preview_family, args(check=True, models_dir=self.tmp.name))+ self.assertEqual(rc, 0)+ self.assertEqual(self.calls, [])+ self.assertIn("UD-Q6_K_XL", out)+ self.assertIn("32.6 GB", out)++ def test_a_flash_next_size_is_refused(self):+ rc, out = run(setup.preview_family, args(model="IQ3_XXS", models_dir=self.tmp.name))+ self.assertEqual(rc, 1)+ self.assertIn("has no IQ3_XXS", out)+ self.assertEqual(self.calls, [])++ def test_too_little_disk(self):+ with mock.patch.object(setup, "free_gb", lambda p: 10.0):+ rc, out = run(setup.preview_family, args(model="Q8_0", models_dir=self.tmp.name))+ self.assertEqual(rc, 1)+ self.assertIn("not enough free disk space", out)++ def test_a_qwen36_size_without_the_family(self):+ err = io.StringIO()+ with mock.patch.object(sys, "argv", ["setup.py", "--model", "Q8_0"]), contextlib.redirect_stderr(err):+ rc, _ = run(setup.main)+ self.assertEqual(rc, 2)+ self.assertIn("--family qwen36", err.getvalue())+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/test_strata_inspect.py b/tools/test_strata_inspect.pyindex db375497e..39b76947a 100644--- a/tools/test_strata_inspect.py+++ b/tools/test_strata_inspect.py@@ -42,6 +42,14 @@ class Verdict(unittest.TestCase):fp["arch"] = "qwen3moe"self.assertEqual(SI.verdict(fp, self.table)[0], "no")+ def test_qwen36_is_recognised_not_run_yet(self):+ fp = self.fp("qwen/Q2_0")+ fp["arch"] = "qwen35moe"+ kind, sentence = SI.verdict(fp, self.table)+ self.assertEqual(kind, "no")+ self.assertIn("Qwen3.6-35B-A3B", sentence)+ self.assertIn("does not run it yet", sentence)+def test_expert_type_without_kernel(self):fp = self.fp("qwen/IQ3_S")fp["expert_bytes"] = {"IQ1_S": 30_000_000_000}