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.
This commit is contained in:
Niko1221 committed 2026-09-30 22:30:11 +02:00
1 parent 24bba1743b
commit dc24332249
2 files changed
+50 -1

No files matched your search

+15
View File
@@ -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 <tests/data/native_experts>\n");
+35 -1
View File
@@ -79,7 +79,41 @@ std::string error_of(const std::vector<std::string>& 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;