From dc24332249f46654fe90a1ea5ccd0bd4b36e87bf Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 30 Sep 2026 20:56:15 +0200 Subject: [PATCH] tests: --real modes for gguf_split_test and expert_layout_test (a real model's shards / a real pack's spans, headers only) `gguf_split_test --real SHARD` opens a real model's shards (GgufModel), checks the architecture on the metadata shard and prints where output / token_embd / the PLE table and key / layer 11's experts are. `expert_layout_test --real PACK NATIVE_SHARD` checks a real pack's native_experts.txt against its model (check_experts_gguf; no expert byte is read). Both pass on the Q2_0, IQ3_XXS (v2), IQ3_S, Coder IQ1_M and Swift IQ2_XS packs and models on the reference PC. --- tests/core/expert_layout_test.cpp | 15 +++++++++++++ tests/core/gguf_split_test.cpp | 36 ++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/core/expert_layout_test.cpp b/tests/core/expert_layout_test.cpp index d532d746..f69e5c55 100644 --- a/tests/core/expert_layout_test.cpp +++ b/tests/core/expert_layout_test.cpp @@ -256,6 +256,21 @@ void arena() { } // namespace int main(int argc, char** argv) { + // `expert_layout_test --real PACK_DIR NATIVE_SHARD`: a real pack's native_experts.txt against its model's files + // (headers only - check_experts_gguf reads no expert byte) + if (argc == 4 && std::string(argv[1]) == "--real") { + std::string err; + if (!load(argv[2], 48, 512, err)) { std::printf("layout refused: %s\n", err.c_str()); return 1; } + const ExpertLayout& L = strata::kernels::cpu::expert_layout(); + const bool ok = strata::core::check_experts_gguf(argv[3], L, err); + size_t split = 0; + for (int64_t l = 0; l < L.n_layers && !L.gguf_file.empty(); ++l) + split += L.gguf_file[(size_t) (3 * l)] != L.gguf_file[(size_t) (3 * l + 2)]; + std::printf("%s: v%d, %lld layers x %lld experts, %.2f GiB, %zu layer(s) split per role: %s%s\n", argv[2], + L.version, (long long) L.n_layers, (long long) L.n_expert, (double) L.total / (1u << 30), split, + ok ? "every span is its tensor" : "REFUSED: ", ok ? "" : err.c_str()); + return ok ? 0 : 1; + } std::printf("expert_layout_test\n"); if (argc < 2) { std::printf("usage: expert_layout_test \n"); diff --git a/tests/core/gguf_split_test.cpp b/tests/core/gguf_split_test.cpp index 22b668b6..3f137ccb 100644 --- a/tests/core/gguf_split_test.cpp +++ b/tests/core/gguf_split_test.cpp @@ -79,7 +79,41 @@ std::string error_of(const std::vector& paths) { } } // namespace -int main() { +// `gguf_split_test --real SHARD`: the same view of a real model (headers only): its shards, the architecture +// check on the metadata shard, and where the tensors the engine reads by name live. +int real_model(const std::string& any) { + try { + const strata::GgufModel m = strata::GgufModel::open(any); + size_t tensors = 0; + for (size_t i = 0; i < m.size(); ++i) { + std::printf(" shard %zu: %s, %zu tensors, data at %llu\n", i + 1, m.shard(i).path().c_str(), + m.shard(i).tensors().size(), (unsigned long long) m.shard(i).data_start()); + tensors += m.shard(i).tensors().size(); + } + const std::string arch = strata::check_architecture(m.meta()); + std::printf(" %zu tensors; architecture check on the metadata shard: %s\n", tensors, + arch.empty() ? "ok" : arch.c_str()); + int bad = arch.empty() ? 0 : 1; + for (const char* name : {"output.weight", "token_embd.weight", "per_layer_token_embd.weight", + "blk.1.ple_key.weight", "blk.11.ffn_gate_exps.weight", "blk.11.ffn_up_exps.weight", + "blk.11.ffn_down_exps.weight"}) { + size_t s = 0; + const strata::TensorInfo* t = m.find(name, &s); + if (!t) { std::printf(" %-30s absent\n", name); continue; } + const bool ok = m.in_bounds(*t, s); + bad += !ok; + std::printf(" %-30s shard %zu, %s, %llu B, %s\n", name, s + 1, t->type_name(), + (unsigned long long) strata::tensor_payload_bytes(*t), ok ? "in bounds" : "OUT OF BOUNDS"); + } + return bad ? 1 : 0; + } catch (const std::exception& e) { + std::printf(" refused: %s\n", e.what()); + return 1; + } +} + +int main(int argc, char** argv) { + if (argc == 3 && std::string(argv[1]) == "--real") return real_model(argv[2]); std::printf("gguf_split_test\n"); { TempDir d;