|
28 | 28 | from mobius._registry import _REGISTRATIONS |
29 | 29 | from mobius.integrations.gguf._arch_registry import ( |
30 | 30 | MMPROJ_ARCHITECTURE, |
| 31 | + _validate_census_closure, |
31 | 32 | get_arch_spec, |
32 | 33 | iter_arch_specs, |
33 | 34 | supported_architectures, |
|
56 | 57 | #: Number of importable architectures. Pinned so that adding support is a |
57 | 58 | #: deliberate act that also updates the documented support matrix, and so that |
58 | 59 | #: accidentally losing an architecture is a failure rather than a silence. |
59 | | -_EXPECTED_SUPPORTED_COUNT = 41 |
| 60 | +_EXPECTED_SUPPORTED_COUNT = 51 |
| 61 | +_FINAL_CENSUS_CLOSURE = frozenset( |
| 62 | + { |
| 63 | + "afmoe", |
| 64 | + "bailingmoe", |
| 65 | + "bailingmoe2", |
| 66 | + "bitnet", |
| 67 | + "codeshell", |
| 68 | + "cohere2moe", |
| 69 | + "command-r", |
| 70 | + "deepseek", |
| 71 | + "deepseek2", |
| 72 | + "deepseek32", |
| 73 | + "dots1", |
| 74 | + "dots3note", |
| 75 | + "ernie4_5", |
| 76 | + "ernie4_5-moe", |
| 77 | + "exaone-moe", |
| 78 | + "exaone4", |
| 79 | + "gemma-embedding", |
| 80 | + "gemma4-assistant", |
| 81 | + "glm4", |
| 82 | + "glm4moe", |
| 83 | + "gptj", |
| 84 | + "gptneox", |
| 85 | + "granite", |
| 86 | + "granite_swa", |
| 87 | + "graniteswitch", |
| 88 | + "hunyuan-moe", |
| 89 | + "hy_v3", |
| 90 | + "jais", |
| 91 | + "jais2", |
| 92 | + "laguna", |
| 93 | + "llama-embed", |
| 94 | + "maincoder", |
| 95 | + "mellum", |
| 96 | + "mimo2", |
| 97 | + "minicpm", |
| 98 | + "minimax-m2", |
| 99 | + "minimax-m3", |
| 100 | + "mistral4", |
| 101 | + "nanbeige", |
| 102 | + "orion", |
| 103 | + "pangu-embedded", |
| 104 | + "plamo", |
| 105 | + "plamo3", |
| 106 | + "plm", |
| 107 | + "qwen", |
| 108 | + "refact", |
| 109 | + "starcoder", |
| 110 | + "step35", |
| 111 | + "xverse", |
| 112 | + } |
| 113 | +) |
| 114 | +_QKV_HELPER_TENSOR_NAMES = frozenset( |
| 115 | + { |
| 116 | + "blk.{bid}.attn_qkv.weight", |
| 117 | + "blk.{bid}.attn_qkv.bias", |
| 118 | + "blk.{bid}.attn_q.weight", |
| 119 | + "blk.{bid}.attn_q.bias", |
| 120 | + "blk.{bid}.attn_k.weight", |
| 121 | + "blk.{bid}.attn_k.bias", |
| 122 | + "blk.{bid}.attn_v.weight", |
| 123 | + "blk.{bid}.attn_v.bias", |
| 124 | + } |
| 125 | +) |
| 126 | +_GATE_UP_EXPS_HELPER_TENSOR_NAMES = frozenset( |
| 127 | + { |
| 128 | + "blk.{bid}.ffn_gate_up_exps.weight", |
| 129 | + "blk.{bid}.ffn_gate_exps.weight", |
| 130 | + "blk.{bid}.ffn_up_exps.weight", |
| 131 | + } |
| 132 | +) |
| 133 | +_FINAL_CENSUS_SUFFIXLESS_TENSORS = frozenset( |
| 134 | + { |
| 135 | + ("gemma4-assistant", "masked_embd_ordering"), |
| 136 | + ("hy_v3", "blk.{bid}.exp_probs_b"), |
| 137 | + ("plamo3", "blk.{bid}.post_attention_norm"), |
| 138 | + ("plamo3", "blk.{bid}.post_ffw_norm"), |
| 139 | + } |
| 140 | +) |
60 | 141 |
|
61 | 142 | # Quantized reachability is separately pinned from float importability. A new |
62 | 143 | # architecture must explicitly prove that its graph exposes packed projection |
@@ -155,7 +236,7 @@ def test_a_buildable_architecture_resolves_in_the_mobius_registry(self, spec) -> |
155 | 236 |
|
156 | 237 | def test_the_supported_set_is_pinned(self) -> None: |
157 | 238 | """Gaining or losing support is a deliberate, reviewable change.""" |
158 | | - assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT + 10 |
| 239 | + assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT |
159 | 240 |
|
160 | 241 | def test_falcon_h1_is_not_a_generic_falcon_alias(self) -> None: |
161 | 242 | """Falcon-H1 must fail before constructing the incompatible Falcon graph.""" |
@@ -273,6 +354,35 @@ def test_aliases_do_not_collide(self) -> None: |
273 | 354 | ) |
274 | 355 | seen[name] = spec.gguf_arch |
275 | 356 |
|
| 357 | + def test_registry_exactly_closes_the_pinned_census(self) -> None: |
| 358 | + specs = iter_arch_specs() |
| 359 | + _validate_census_closure(specs, frozenset(upstream_architectures())) |
| 360 | + assert len(specs) == 147 |
| 361 | + assert {spec.gguf_arch for spec in specs} == set(upstream_architectures()) |
| 362 | + |
| 363 | + @pytest.mark.parametrize( |
| 364 | + ("mutation", "match"), |
| 365 | + [ |
| 366 | + ("missing", "missing="), |
| 367 | + ("extra", "extra="), |
| 368 | + ("duplicate", "duplicates="), |
| 369 | + ("alias-drift", "aliases_that_became_canonical="), |
| 370 | + ], |
| 371 | + ) |
| 372 | + def test_census_mutation_is_detected(self, mutation: str, match: str) -> None: |
| 373 | + specs = iter_arch_specs() |
| 374 | + upstream = set(upstream_architectures()) |
| 375 | + if mutation == "missing": |
| 376 | + specs = specs[:-1] |
| 377 | + elif mutation == "extra": |
| 378 | + upstream.remove(specs[0].gguf_arch) |
| 379 | + elif mutation == "duplicate": |
| 380 | + specs = (*specs, specs[0]) |
| 381 | + else: |
| 382 | + upstream.add("mistral") |
| 383 | + with pytest.raises(ValueError, match=match): |
| 384 | + _validate_census_closure(tuple(specs), frozenset(upstream)) |
| 385 | + |
276 | 386 | @pytest.mark.parametrize("spec", iter_arch_specs(), ids=lambda s: s.gguf_arch) |
277 | 387 | def test_alias_resolution_is_total(self, spec) -> None: |
278 | 388 | for name in spec.names: |
@@ -542,6 +652,152 @@ def test_deleting_recurrent_mapping_breaks_closure( |
542 | 652 | _build_mapping.cache_clear() |
543 | 653 |
|
544 | 654 |
|
| 655 | +class TestFinalCensusClosure: |
| 656 | + @pytest.mark.parametrize("architecture", sorted(_FINAL_CENSUS_CLOSURE)) |
| 657 | + def test_every_newly_closed_id_has_one_nonimportable_spec(self, architecture: str) -> None: |
| 658 | + spec = try_get_arch_spec(architecture) |
| 659 | + assert spec is not None |
| 660 | + assert spec.gguf_arch == architecture |
| 661 | + assert spec.model_type is None |
| 662 | + assert spec.aliases == frozenset() |
| 663 | + assert all(verdict is not Support.SUPPORTED for verdict in spec.verdicts.values()) |
| 664 | + assert spec.reason |
| 665 | + |
| 666 | + @pytest.mark.parametrize( |
| 667 | + "architecture", |
| 668 | + sorted(_FINAL_CENSUS_CLOSURE - {"gptj"}), |
| 669 | + ) |
| 670 | + def test_loader_and_converter_audits_are_pinned(self, architecture: str) -> None: |
| 671 | + upstream = upstream_architectures()[architecture] |
| 672 | + assert upstream.cpp_loader |
| 673 | + assert upstream.loader_source.startswith("src/models/") |
| 674 | + assert upstream.tensor_names |
| 675 | + assert upstream.tensor_families |
| 676 | + assert upstream.required_metadata |
| 677 | + assert upstream.tensor_closure_status == "audited-direct-loader-conditional-union" |
| 678 | + assert ( |
| 679 | + upstream.converter_inventory_status |
| 680 | + == "exact-pinned-MODEL_TENSORS-family-inventory" |
| 681 | + ) |
| 682 | + assert all( |
| 683 | + name.endswith((".weight", ".bias", ".scale", ".input_scale", ".lora_a", ".lora_b")) |
| 684 | + or (architecture, name) in _FINAL_CENSUS_SUFFIXLESS_TENSORS |
| 685 | + for name in upstream.tensor_names |
| 686 | + ) |
| 687 | + |
| 688 | + def test_shared_loader_helpers_are_fully_expanded(self) -> None: |
| 689 | + expected = { |
| 690 | + "create_tensor_qkv": _QKV_HELPER_TENSOR_NAMES, |
| 691 | + "create_tensor_gate_up_exps": _GATE_UP_EXPS_HELPER_TENSOR_NAMES, |
| 692 | + } |
| 693 | + for architecture in sorted(_FINAL_CENSUS_CLOSURE): |
| 694 | + upstream = upstream_architectures()[architecture] |
| 695 | + for helper in upstream.loader_helpers: |
| 696 | + assert helper in expected |
| 697 | + assert expected[helper] <= set(upstream.tensor_names), ( |
| 698 | + f"{architecture} does not contain the full {helper} conditional union" |
| 699 | + ) |
| 700 | + |
| 701 | + def test_suffixless_loader_tensors_are_exact(self) -> None: |
| 702 | + suffixless = { |
| 703 | + (architecture, name) |
| 704 | + for architecture in _FINAL_CENSUS_CLOSURE |
| 705 | + for name in upstream_architectures()[architecture].tensor_names |
| 706 | + if not name.endswith( |
| 707 | + (".weight", ".bias", ".scale", ".input_scale", ".lora_a", ".lora_b") |
| 708 | + ) |
| 709 | + } |
| 710 | + assert suffixless == _FINAL_CENSUS_SUFFIXLESS_TENSORS |
| 711 | + |
| 712 | + def test_step35_metadata_reads_are_exact(self) -> None: |
| 713 | + upstream = upstream_architectures()["step35"] |
| 714 | + assert set(upstream.required_metadata) == { |
| 715 | + "attention.layer_norm_rms_epsilon", |
| 716 | + "attention.sliding_window", |
| 717 | + "attention.sliding_window_pattern", |
| 718 | + "expert_feed_forward_length", |
| 719 | + } |
| 720 | + assert set(upstream.optional_metadata) == { |
| 721 | + "expert_gating_func", |
| 722 | + "expert_shared_feed_forward_length", |
| 723 | + "expert_weights_norm", |
| 724 | + "expert_weights_scale", |
| 725 | + "nextn_predict_layers", |
| 726 | + "rope.freq_base_swa", |
| 727 | + "swiglu_clamp_exp", |
| 728 | + "swiglu_clamp_shexp", |
| 729 | + } |
| 730 | + |
| 731 | + @pytest.mark.parametrize( |
| 732 | + ("architecture", "optional_keys"), |
| 733 | + [ |
| 734 | + ("granite", {"expert_shared_feed_forward_length"}), |
| 735 | + ("granite_swa", {"expert_shared_feed_forward_length"}), |
| 736 | + ( |
| 737 | + "graniteswitch", |
| 738 | + {"adapters.router_gain", "expert_shared_feed_forward_length"}, |
| 739 | + ), |
| 740 | + ("minicpm", {"embedding_scale", "logit_scale", "residual_scale"}), |
| 741 | + ], |
| 742 | + ) |
| 743 | + def test_defaulted_metadata_is_not_classified_as_required( |
| 744 | + self, architecture: str, optional_keys: set[str] |
| 745 | + ) -> None: |
| 746 | + upstream = upstream_architectures()[architecture] |
| 747 | + assert optional_keys <= set(upstream.optional_metadata) |
| 748 | + assert optional_keys.isdisjoint(upstream.required_metadata) |
| 749 | + |
| 750 | + def test_array_metadata_reads_are_complete_and_classified(self) -> None: |
| 751 | + expected = { |
| 752 | + "dots3note": ( |
| 753 | + {"attention.indexer.types", "attention.sliding_window_pattern"}, |
| 754 | + set(), |
| 755 | + ), |
| 756 | + "granite": (set(), {"deepstack_mapping"}), |
| 757 | + "granite_swa": ( |
| 758 | + {"attention.sliding_window_pattern"}, |
| 759 | + {"attention.rope_pattern", "deepstack_mapping"}, |
| 760 | + ), |
| 761 | + "graniteswitch": ( |
| 762 | + {"adapters.token_ids_activate", "adapters.token_ids_substitute"}, |
| 763 | + set(), |
| 764 | + ), |
| 765 | + } |
| 766 | + actual = { |
| 767 | + architecture: set(upstream_architectures()[architecture].array_metadata) |
| 768 | + for architecture in expected |
| 769 | + } |
| 770 | + assert actual == { |
| 771 | + architecture: required | optional |
| 772 | + for architecture, (required, optional) in expected.items() |
| 773 | + } |
| 774 | + for architecture, (required, optional) in expected.items(): |
| 775 | + upstream = upstream_architectures()[architecture] |
| 776 | + assert required <= set(upstream.required_metadata) |
| 777 | + assert required.isdisjoint(upstream.optional_metadata) |
| 778 | + assert optional <= set(upstream.optional_metadata) |
| 779 | + assert optional.isdisjoint(upstream.required_metadata) |
| 780 | + |
| 781 | + def test_dead_gptj_id_is_explicitly_rejected(self) -> None: |
| 782 | + upstream = upstream_architectures()["gptj"] |
| 783 | + assert not upstream.cpp_loader |
| 784 | + assert upstream.tensor_closure_status == "no-loader" |
| 785 | + assert upstream.converter_inventory_status == "no-converter" |
| 786 | + with pytest.raises(DisabledGGUFArchitectureError, match="no model loader"): |
| 787 | + get_arch_spec("gptj") |
| 788 | + |
| 789 | + @pytest.mark.parametrize("architecture", ["arwkv7", "rwkv6", "rwkv6qwen2", "rwkv7"]) |
| 790 | + def test_rwkv_variants_have_distinct_state_abi_reasons(self, architecture: str) -> None: |
| 791 | + spec = try_get_arch_spec(architecture) |
| 792 | + assert spec is not None and spec.reason is not None |
| 793 | + assert "state" in spec.reason.lower() |
| 794 | + assert "Mamba" in spec.reason |
| 795 | + upstream = upstream_architectures()[architecture] |
| 796 | + assert upstream.tensor_names |
| 797 | + assert upstream.tensor_families |
| 798 | + assert upstream.required_metadata |
| 799 | + |
| 800 | + |
545 | 801 | class TestPinnedAudioCohort: |
546 | 802 | """Pin the audited C09 inventories without implying graph support.""" |
547 | 803 |
|
@@ -1236,12 +1492,12 @@ def test_deliberately_disabled_architectures_raise_the_disabled_error( |
1236 | 1492 | def test_a_dead_upstream_architecture_says_so(self) -> None: |
1237 | 1493 | """``gptj`` is registered upstream but has no loader, so nothing can read it.""" |
1238 | 1494 | with pytest.raises( |
1239 | | - UnsupportedGGUFArchitectureError, match=re.escape("no llama.cpp model loader") |
| 1495 | + DisabledGGUFArchitectureError, match=re.escape("llama.cpp has no model loader") |
1240 | 1496 | ): |
1241 | 1497 | get_arch_spec("gptj") |
1242 | 1498 |
|
1243 | 1499 | def test_an_unimported_upstream_architecture_names_its_cohort(self) -> None: |
1244 | | - with pytest.raises(UnsupportedGGUFArchitectureError, match="distinct RWKV"): |
| 1500 | + with pytest.raises(UnsupportedGGUFArchitectureError, match="RWKV6 carries"): |
1245 | 1501 | get_arch_spec("rwkv6") |
1246 | 1502 |
|
1247 | 1503 | def test_an_unknown_architecture_is_distinguished_from_an_upstream_one(self) -> None: |
@@ -1288,9 +1544,9 @@ def _expected_rows() -> list[str]: |
1288 | 1544 | if verdict is not Support.SUPPORTED |
1289 | 1545 | ) |
1290 | 1546 | ) |
1291 | | - quantized = spec.quantized_import.value if spec.is_importable else "unreachable" |
| 1547 | + reason = spec.reason or "Validated graph and runtime contract." |
1292 | 1548 | rows.append( |
1293 | | - f"| `{spec.gguf_arch}` | {aliases} | {model_type} | {status} | {quantized} |" |
| 1549 | + f"| `{spec.gguf_arch}` | {aliases} | {model_type} | {status} | {reason} |" |
1294 | 1550 | ) |
1295 | 1551 | return rows |
1296 | 1552 |
|
|
0 commit comments