Repository navigation
Commit 7958f1a
Introduce a GGUF support registry and fix five architecture drift bugs (#571)
Foundation for supporting every GGUF architecture and stored
quantization type llama.cpp supports. This PR is structure and
drift-proofing only — no new architecture cohorts, no sharded GGUF, no
new dequantizers.
## Problem
GGUF support was asserted implicitly by nine hand-maintained containers
spread across five modules, keyed inconsistently on either the GGUF
`general.architecture` string or the mobius `model_type`. Nothing
cross-checked them, and they had drifted apart: 25 architectures had a
config mapping, 28 had a tensor mapping, and the two sets disagreed in
both directions.
## Design
One immutable source of truth per question, with everything else
derived.
- **`GGUFArchitectureSpec`** answers four capability questions
*independently* — `config`, `tensor_map`, `graph`, `runtime` — instead
of one boolean, because they genuinely differ per architecture. Anything
short of `SUPPORTED` must carry a reason, so listing an architecture is
never itself a support claim.
- **`GGUFQuantSpec`** does the same for stored quantization: parse-layer
`readable`, `dequantize`, `native_preserve`, `affine_repack`.
- Specs reference behavior **by name**, never by callable. The owning
module resolves the name. That keeps `_arch_registry` an import leaf and
makes both a typo and an *unreferenced implementation* a test failure
rather than dead weight.
Derived from the registry: `GGUF_ARCH_TO_MODEL_TYPE`, `_ARCH_KEY_MAPS`,
`_CONFIG_POSTPROCESSORS`, the five `_*_FAMILY` frozensets and the
`_build_mapping` if/elif chain, `LLAMA_QK_PERMUTE_MODEL_TYPES` and the
processor table, `_OFFSET_NORM_GGUF_ARCHS`,
`_V_HEAD_REORDER_GGUF_ARCHS`, the disabled-architecture guard, the
mmproj VLM dispatch, and nine quantization tables across `_repacker` and
`_builder`.
## Upstream pin
llama.cpp `8d9af256337d1a501250f9bbf4c0859a654bddd6` — 147 real
`llm_arch` entries and all 43 `ggml_type` slots, extracted mechanically
(block geometry read from a compiled `libggml-base` via
`ggml_get_type_traits()`).
Vendored as **data**, trimmed to the fields the registry actually reads
(198 lines). It exists to make coverage *measurable*, not to claim it:
canonical names are validated against it so a mobius `model_type` can no
longer masquerade as an architecture, and an unrecognized architecture
gets a message naming its upstream cohort.
## Five proven bugs
Each was reproduced and root-caused before being touched.
1. **Gemma 3 silent norm corruption.** The weight processor was keyed by
`model_type` and registered under `gemma3`, but GGUF `gemma3` resolves
to `gemma3_text`, so the Gemma un-offset never ran.
`models/gemma3_text.py` uses `OffsetRMSNorm`, so llama.cpp's baked-in
`+1` was applied twice on every norm.
2. **Nemotron norm sign inverted.** `_process_nemotron` *added* one
while citing HF's `NemotronTensorProcessor`, which subtracts. llama.cpp
`conversion/nemotron.py:191` writes `w_gguf = w_hf + 1` and
`models/nemotron.py` uses `OffsetLayerNorm`, so the effective scale was
`w_hf + 3` — a stored weight of 1.25 scaled by 3.25. Corrected, it is
byte-identical to Gemma's, so the two consolidated into one processor.
3. **`qwen2moe`/`qwen3moe` unreachable.** mobius keyed on
`qwen2_moe`/`qwen3_moe`, which are mobius `model_type` strings no GGUF
carries. A real Qwen-MoE GGUF passed tensor mapping and then failed
registry lookup: the reachable keys were dead and the dead keys were
reachable. Now canonical, with the old spellings as declared aliases.
4. **`_gguf_arch` dropped by `dataclasses.replace`**, leaving the new
registry dispatch dead on every non-float32 and every quantized import.
5. **`_build_mapping` exception base changed** for `clip`, which is
reachable via `build_from_gguf` on an mmproj file.
`gemma` and `internlm2` previously worked only by an unmapped
`.get(arch, arch)` fall-through and are now declared explicitly. `bloom`
and `t5` are declared configurable but unmappable, so they fail before
config extraction with a reason instead of a contradiction — they never
imported successfully.
## Behavior boundaries
Behavior-preserving except for the five fixes above.
- Tensor mappings are **byte-identical** for all 28 previously mappable
architecture spellings, verified by reconstructing the old `if/elif`
chain and diffing.
- Every replaced quantization literal is pinned verbatim in
`_quant_registry_test.py` and asserted equal to the derived table.
- Public API unchanged: `__all__` untouched, `mobius.build_from_gguf`
and `__main__` untouched, `GGUF_ARCH_TO_MODEL_TYPE` retained (now a
derived read-only proxy).
- New exceptions subclass the types each path already raised, so
existing `except ValueError` / `except NotImplementedError` callers keep
working. The tensor-mapping gate still reports every unmapped
architecture as a `ValueError`; `_validate_gguf_model` still raises
`NotImplementedError` for deliberately disabled ones.
- Preserved unchanged: mmproj, MTP sidecar, Tencent Q1_0, native
IQ/MXFP4 preservation, mixed-preset requantization, sharded-GGUF
rejection.
## Validation
- **1083** GGUF tests pass (was 377).
- Broad suite: **5473 passed**. Two `glm_moe_dsa` failures are
pre-existing, confirmed by stashing onto clean `main`.
- `lintrunner` clean.
- Every invariant was **mutation-tested** — reverting the Gemma 3 fix,
re-introducing a `model_type`-as-architecture, adding an orphan
processor, claiming tensor mapping without config, re-inverting the norm
sign, and deleting the `_gguf_arch` re-attachment each failed exactly
the intended test and nothing else.
- `docs/api/build_from_gguf.md` replaces "Most decoder-only LLM
architectures are supported" with a support matrix that a test asserts
equals the registry.
## Follow-up
The `OffsetRMSNorm` `Add(weight, 1.0)` is not constant-folded and ships
in the graph. A separate PR will propose folding the offset at weight
load on both the HF and GGUF paths; out of scope here.
---------
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>1 parent 0f1fc0c commit 7958f1a
21 files changed
Lines changed: 2931 additions & 394 deletions
File tree
- docs/api
- src/mobius/integrations/gguf
- _upstream_data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
90 | 142 | | |
91 | 143 | | |
92 | 144 | | |
93 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
94 | 164 | | |
95 | 165 | | |
96 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
0 commit comments