Skip to content

Commit 13b2f84

Browse files
justinchubyCopilot
andauthored
Close pinned GGUF architecture census (#601)
## Summary - close the immutable llama.cpp architecture census at `8d9af256337d1a501250f9bbf4c0859a654bddd6`: every one of 147 real `general.architecture` IDs now resolves to exactly one capability spec - classify the final 50 IDs without fabricating aliases or overclaiming graph/runtime support; reject dead `gptj` and defer all other newly closed IDs before config extraction because their exact graph/task/cache/tensor/quantization contracts are not representable - pin helper-expanded loader tensor unions, suffixless tensors, required/defaulted scalar and array metadata, RWKV variant state ABI distinctions, exact 25-qtype closure, and generated 147-row support documentation - prevent unknown architectures from silently falling through generic Hugging Face config/model dispatch and run architecture verdicts before MTP/qtype policy ## Final closure set `afmoe`, `bailingmoe`, `bailingmoe2`, `bitnet`, `codeshell`, `cohere2moe`, `command-r`, `deepseek`, `deepseek2`, `deepseek32`, `dots1`, `dots3note`, `ernie4_5`, `ernie4_5-moe`, `exaone-moe`, `exaone4`, `gemma-embedding`, `gemma4-assistant`, `glm-dsa`, `glm4`, `glm4moe`, `gptj`, `gptneox`, `granite`, `granite_swa`, `graniteswitch`, `hunyuan-moe`, `hy_v3`, `jais`, `jais2`, `laguna`, `llama-embed`, `maincoder`, `mellum`, `mimo2`, `minicpm`, `minimax-m2`, `minimax-m3`, `mistral4`, `nanbeige`, `orion`, `pangu-embedded`, `plamo`, `plamo3`, `plm`, `qwen`, `refact`, `starcoder`, `step35`, `xverse`. ## Validation - focused registry/census/qtype: 1,663 passed - full GGUF suite: 2,564 passed - broad non-integration suite excluding inherited `glm_moe_dsa` baseline failures: 6,994 passed, 52 skipped - initialized lintrunner format and full lint: clean - two independent GPT-5.6 Sol full-diff reviews: clean after findings were fixed and affected gates rerun The two `glm_moe_dsa` ONNX shape/checker failures reproduce unchanged on the exact stacked base SHA `7ac405e6394bc595d359945263bf724516720450`; this PR does not touch that model. Stacked on #600. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 85fb322 commit 13b2f84

8 files changed

Lines changed: 917 additions & 190 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 184 additions & 99 deletions
Large diffs are not rendered by default.

‎src/mobius/integrations/gguf/_arch_registry.py‎

Lines changed: 335 additions & 9 deletions
Large diffs are not rendered by default.

‎src/mobius/integrations/gguf/_arch_registry_test.py‎

Lines changed: 262 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from mobius._registry import _REGISTRATIONS
2929
from mobius.integrations.gguf._arch_registry import (
3030
MMPROJ_ARCHITECTURE,
31+
_validate_census_closure,
3132
get_arch_spec,
3233
iter_arch_specs,
3334
supported_architectures,
@@ -56,7 +57,87 @@
5657
#: Number of importable architectures. Pinned so that adding support is a
5758
#: deliberate act that also updates the documented support matrix, and so that
5859
#: 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+
)
60141

61142
# Quantized reachability is separately pinned from float importability. A new
62143
# 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) ->
155236

156237
def test_the_supported_set_is_pinned(self) -> None:
157238
"""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
159240

160241
def test_falcon_h1_is_not_a_generic_falcon_alias(self) -> None:
161242
"""Falcon-H1 must fail before constructing the incompatible Falcon graph."""
@@ -273,6 +354,35 @@ def test_aliases_do_not_collide(self) -> None:
273354
)
274355
seen[name] = spec.gguf_arch
275356

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+
276386
@pytest.mark.parametrize("spec", iter_arch_specs(), ids=lambda s: s.gguf_arch)
277387
def test_alias_resolution_is_total(self, spec) -> None:
278388
for name in spec.names:
@@ -542,6 +652,152 @@ def test_deleting_recurrent_mapping_breaks_closure(
542652
_build_mapping.cache_clear()
543653

544654

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+
545801
class TestPinnedAudioCohort:
546802
"""Pin the audited C09 inventories without implying graph support."""
547803

@@ -1236,12 +1492,12 @@ def test_deliberately_disabled_architectures_raise_the_disabled_error(
12361492
def test_a_dead_upstream_architecture_says_so(self) -> None:
12371493
"""``gptj`` is registered upstream but has no loader, so nothing can read it."""
12381494
with pytest.raises(
1239-
UnsupportedGGUFArchitectureError, match=re.escape("no llama.cpp model loader")
1495+
DisabledGGUFArchitectureError, match=re.escape("llama.cpp has no model loader")
12401496
):
12411497
get_arch_spec("gptj")
12421498

12431499
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"):
12451501
get_arch_spec("rwkv6")
12461502

12471503
def test_an_unknown_architecture_is_distinguished_from_an_upstream_one(self) -> None:
@@ -1288,9 +1544,9 @@ def _expected_rows() -> list[str]:
12881544
if verdict is not Support.SUPPORTED
12891545
)
12901546
)
1291-
quantized = spec.quantized_import.value if spec.is_importable else "unreachable"
1547+
reason = spec.reason or "Validated graph and runtime contract."
12921548
rows.append(
1293-
f"| `{spec.gguf_arch}` | {aliases} | {model_type} | {status} | {quantized} |"
1549+
f"| `{spec.gguf_arch}` | {aliases} | {model_type} | {status} | {reason} |"
12941550
)
12951551
return rows
12961552

‎src/mobius/integrations/gguf/_builder.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ def _raise_for_unsupported_gguf_architecture(
134134
"""
135135
spec = try_get_arch_spec(architecture)
136136
if spec is None:
137-
return
137+
raise UnsupportedGGUFArchitectureError(
138+
f"GGUF architecture {architecture!r} has no immutable capability-registry "
139+
f"spec for {source!r}; refusing generic Hugging Face config/model dispatch "
140+
"before config extraction. No ONNX artifacts were emitted."
141+
)
138142
if spec.gguf_arch == MMPROJ_ARCHITECTURE and allow_mmproj_companion:
139143
# mmproj sidecars are opened deliberately by the multimodal path, which
140144
# pairs them with a text backbone and applies role-specific validation.
@@ -598,15 +602,15 @@ def _validate_gguf_model(
598602
if not isinstance(gguf_model, GgufShardSet):
599603
split_count = int(gguf_model.get_metadata("split.count", 1))
600604
_raise_for_sharded_gguf(source=source, split_count=split_count)
601-
from mobius.integrations.gguf._mtp import validate_mtp_tensor_contract
602-
603-
validate_mtp_tensor_contract(gguf_model)
604605
_raise_for_unsupported_gguf_architecture(
605606
gguf_model.architecture,
606607
source=source,
607608
tensor_names=gguf_model.tensor_names,
608609
allow_mmproj_companion=allow_mmproj_companion,
609610
)
611+
from mobius.integrations.gguf._mtp import validate_mtp_tensor_contract
612+
613+
validate_mtp_tensor_contract(gguf_model)
610614
_raise_for_unsupported_auxiliary_quantization(gguf_model)
611615
_raise_for_invalid_hybrid_tensor_contract(gguf_model)
612616
_raise_for_invalid_t5_tensor_contract(gguf_model)

‎src/mobius/integrations/gguf/_quant_registry_test.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ def test_declared_float_decoders_execute_one_pinned_block(self, spec) -> None:
236236
assert values.size == spec.block_elements
237237
assert np.isfinite(values).all()
238238

239+
def test_all_pinned_stored_quantized_types_are_registered(self) -> None:
240+
stored_quantized = [
241+
spec
242+
for spec in iter_quant_specs()
243+
if spec.readable and spec.role is StorageRole.QUANTIZED
244+
]
245+
assert len(stored_quantized) == 25
246+
239247
@pytest.mark.parametrize("spec", iter_quant_specs(), ids=lambda s: s.name)
240248
def test_geometry_matches_upstream(self, spec) -> None:
241249
upstream = upstream_quant_types()[spec.ggml_type_id]

0 commit comments

Comments
 (0)