Skip to content

Commit 16d486d

Browse files
kmbandyclaude
andcommitted
test(wp): catalog is_expert classification (dense vs routed, shared expert)
Phase 1 Task 4. Locks the invariant WP_RESIDENT_DENSE depends on: routed _exps tensors are experts; attention/embeddings and the SHARED expert (ffn_*_shexp — matches an ffn_ role prefix but not _exps.) are dense. Verifies consolidated parent is uncounted, 256 sub-pages counted. 38/38 green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014ZRfPpL8XFzk1hep9MMg9P
1 parent 0b2ae03 commit 16d486d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/test-weight-pager.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,34 @@ static int test_wp_paged_batch_flag_default_off() {
16261626
// main
16271627
// ---------------------------------------------------------------------------
16281628

1629+
// WP_RESIDENT_DENSE relies on the catalog's expert classification agreeing
1630+
// with the loader's is_consolidated detection (llama-model.cpp) and the
1631+
// is_paged_weight predicate. Lock in the invariant: routed-expert (_exps)
1632+
// tensors are experts; dense tensors — attention, embeddings, and the SHARED
1633+
// expert (ffn_*_shexp, which matches an ffn_ role prefix but is NOT _exps) —
1634+
// are not. A mismatch here would let a dense tensor slip past one filter.
1635+
static int test_catalog_is_expert_classification() {
1636+
int fails = 0;
1637+
wp::PageCatalog cat;
1638+
// Dense tensors — must NOT be experts.
1639+
int p_attn = cat.add("blk.0.attn_q.weight", 0, 0, 4096);
1640+
int p_emb = cat.add("token_embd.weight", 0, 0, 100000);
1641+
int p_shex = cat.add("blk.0.ffn_down_shexp.weight", 0, 0, 8192);
1642+
// Consolidated routed experts — MUST be experts (parent + N sub-pages).
1643+
int first_sub = cat.add_consolidated_experts("blk.0.ffn_gate_exps.weight",
1644+
0, 0, 256 * 8192, 256);
1645+
EXPECT(!cat.at(p_attn).is_expert, "attn_q is dense");
1646+
EXPECT(!cat.at(p_emb).is_expert, "token_embd is dense");
1647+
EXPECT(!cat.at(p_shex).is_expert, "ffn_down_shexp is dense (shared expert)");
1648+
EXPECT(cat.at(first_sub).is_expert, "ffn_gate_exps sub-page is expert");
1649+
EXPECT(cat.at(first_sub).is_sub_expert, "ffn_gate_exps sub-page is a sub-expert");
1650+
EXPECT(cat.at(first_sub - 1).is_consolidated, "parent is consolidated");
1651+
EXPECT(!cat.at(first_sub - 1).is_expert, "consolidated parent is not itself an expert page");
1652+
EXPECT(cat.has_experts(), "catalog reports experts present");
1653+
EXPECT_EQ_INT(cat.n_expert_pages(), 256, "256 expert sub-pages counted (parent excluded)");
1654+
return fails;
1655+
}
1656+
16291657
int main() {
16301658
int total_fails = 0;
16311659

@@ -1664,6 +1692,7 @@ int main() {
16641692
{ "catalog_add_pinned_basic", test_catalog_add_pinned_basic },
16651693
{ "catalog_add_pinned_mixed_with_paged", test_catalog_add_pinned_mixed_with_paged },
16661694
{ "catalog_clear_resets_pinned", test_catalog_clear_resets_pinned_counters },
1695+
{ "catalog_is_expert_classification", test_catalog_is_expert_classification },
16671696
{ "pool_hit_count_basic", test_pool_hit_count_basic },
16681697
{ "pool_hot_threshold_protects", test_pool_hot_threshold_protects_in_eviction },
16691698
{ "pool_hot_fallback_when_all_hot", test_pool_hot_fallback_when_all_hot },

0 commit comments

Comments
 (0)