Skip to content

Commit 05b4417

Browse files
justinchubyCopilot
andauthored
Add dense GGUF architecture cohort (#572)
## Summary Adds the first reviewable C01 dense-transformer GGUF cohort on top of #571, using llama.cpp commit `8d9af256337d1a501250f9bbf4c0859a654bddd6` as the tensor-family source of truth. | GGUF architecture | mobius graph | Config/tensor/graph | Runtime | |---|---|---|---| | `olmo` | `OLMoCausalLMModel` | supported | supported with pinned real GGUF evidence | | `olmo2` | `OLMo2CausalLMModel` | supported | supported with pinned real GGUF evidence | | `cohere2` | `CohereCausalLMModel` | supported | deferred pending real parity/generation evidence | | `arcee` | `ArceeCausalLMModel` | supported | deferred pending real parity/generation evidence | | `smollm3` | `SmolLM3CausalLMModel` | supported | supported with pinned real GGUF evidence | | `exaone` | `CausalLMModel` | supported | deferred pending real parity/generation evidence | ## Architecture correctness - Adds exact pinned upstream tensor-family closure and a falsification test that removes a required mapping. - Rejects missing required metadata rather than synthesizing success-shaped configs. - Preserves OLMo weight-free LayerNorm, OLMo2 post-norm/full-width QK norms, Cohere2 parallel pre-norm/interleaved RoPE/3-sliding-1-full NoPE schedule, Arcee ReLU² non-gated MLP, and SmolLM3 every-fourth-layer NoPE behavior. - Explicitly rejects `olmo2` files carrying OLMo3 sliding-window patterns until the graph supports per-layer sliding attention. - Fixes the existing InternLM2 Q/K reverse permutation with a direct value regression against pinned converter behavior. - Centralizes quantization-aware linear/embedding construction so specialized graph classes do not silently replace packed modules with float modules. - Rebinds tied quantized LM heads when specialized models replace their text backbones. ## Real GGUF evidence Pinned revisions, exact filenames, sizes, SHA-256 values, and per-tensor qtype tables are encoded in `tests/gguf_dense_cohort_integration_test.py` for: - `QuantFactory/AMD-OLMo-1B-GGUF@5f34243a42dbae2141b8f5286320bf63d51eeefb` - `allenai/OLMo-2-0425-1B-Instruct-GGUF@62f8c199538474c3e33ed5d7e0580abd66686a27` - `ggml-org/SmolLM3-3B-GGUF@4965cb60b150737b68a0408c36aeefb65078f894` All three packages build, save, open in ORT CPU, and produce deterministic finite logits and pinned greedy outputs. The mixed Q4_K_M files do **not** use native preservation. Q4_K and Q6_K projections are dequantized and affine-requantized to explicit-zero-point 4-bit/block-32 `MatMulNBits`; compatible embeddings use `GatherBlockQuantized`; float norm tensors remain float. ## Explicit exclusions The PR does not infer compatibility from common names. Deferred candidates include GPT-NeoX and Phi-2 (fused/interleaved or dual-form QKV), Baichuan and MPT (ALiBi), StarCoder (learned positions), and unproven Qwen/Command-R aliases. Large Command-R/Seed artifacts were not downloaded. ## Validation - 1,112 GGUF unit tests - 52 affected model graph tests - 3 pinned real-GGUF integration tests - 5,511 broader non-integration tests - Changed-file lintrunner clean The existing `glm_moe_dsa` symbolic shape-inference/checker failures reproduce independently and are excluded from the final broad run. Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent b6d166a commit 05b4417

17 files changed

Lines changed: 817 additions & 76 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ reason.
145145

146146
| GGUF architecture | Accepted aliases | mobius `model_type` | Status |
147147
|---|---|---|---|
148+
| `arcee` | — | `arcee` | runtime deferred |
148149
| `bloom` | — | `bloom` | tensor_map deferred |
149150
| `clip` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected |
151+
| `cohere2` | — | `cohere2` | runtime deferred |
150152
| `deci` | — | `llama` | supported |
151153
| `deepseek4` | — | `deepseek_v4` | supported |
154+
| `exaone` | — | `exaone` | runtime deferred |
152155
| `falcon` | — | `falcon` | supported |
153156
| `gemma` | — | `gemma` | supported |
154157
| `gemma2` | — | `gemma2` | supported |
@@ -163,13 +166,16 @@ reason.
163166
| `muse-glimmer` | `muse_glimmer` | `muse_glimmer_text` | supported |
164167
| `nemotron` | — | `nemotron` | supported |
165168
| `nemotron_h_moe` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected |
169+
| `olmo` | — | `olmo` | supported |
170+
| `olmo2` | — | `olmo2` | supported |
166171
| `phi3` | — | `phi3` | supported |
167172
| `qwen2` | — | `qwen2` | supported |
168173
| `qwen2moe` | `qwen2_moe` | `qwen2_moe` | supported |
169174
| `qwen3` | — | `qwen3` | supported |
170175
| `qwen35` | — | `qwen3_5_text` | supported |
171176
| `qwen35moe` | — | `qwen3_5_moe` | supported |
172177
| `qwen3moe` | `qwen3_moe` | `qwen3_moe` | supported |
178+
| `smollm3` | — | `smollm3` | supported |
173179
| `stablelm` | — | `stablelm` | supported |
174180
| `starcoder2` | — | `starcoder2` | supported |
175181
| `t5` | — | `t5` | tensor_map deferred |
@@ -189,6 +195,34 @@ upstream cohort, so an unsupported input is never mistaken for a broken one.
189195
Sharded GGUF files are rejected. A single shard has only part of the tensor
190196
table, and treating it as a complete checkpoint would create a corrupt model.
191197

198+
### Dense-transformer validation
199+
200+
The first dense-transformer cohort adds exact config, tensor-map, and graph
201+
support for OLMo, OLMo2, Cohere2, Arcee, SmolLM3, and Exaone. Runtime remains
202+
deferred for Cohere2, Arcee, and Exaone until pinned real-weight parity or
203+
generation evidence is available; synthetic graph execution alone is not a
204+
runtime claim.
205+
206+
Runtime coverage for the other three mappings is pinned to:
207+
208+
| Architecture | Revision and file | Size | SHA-256 | Stored qtypes |
209+
|---|---|---:|---|---|
210+
| OLMo | `QuantFactory/AMD-OLMo-1B-GGUF@5f34243a42dbae2141b8f5286320bf63d51eeefb`<br>`AMD-OLMo-1B.Q4_K_M.gguf` | 733,520,128 | `2a848051ef7a3edfd829ce915835794e789e6ed7f425066c242759b8dbc645b4` | 96 Q4_K, 17 Q6_K |
211+
| OLMo2 | `allenai/OLMo-2-0425-1B-Instruct-GGUF@62f8c199538474c3e33ed5d7e0580abd66686a27`<br>`OLMo-2-0425-1B-Instruct-Q4_K_M.gguf` | 935,515,296 | `abd8187934a438fbf7cfff0a1de5b9d2793ce913f158794df1951dcba6c93cc6` | 97 Q4_K, 17 Q6_K, 65 F32 |
212+
| SmolLM3 | `ggml-org/SmolLM3-3B-GGUF@4965cb60b150737b68a0408c36aeefb65078f894`<br>`SmolLM3-Q4_K_M.gguf` | 1,915,305,312 | `8334b850b7bd46238c16b0c550df2138f0889bf433809008cc17a8b05761863e` | 216 Q4_K, 37 Q6_K, 73 F32 |
213+
214+
For these mixed Q4_K_M artifacts, projections are not preserved natively.
215+
Q4_K and Q6_K tensors are dequantized and affine-requantized to explicit
216+
zero-point 4-bit/block-32 `MatMulNBits`; compatible token embeddings use
217+
`GatherBlockQuantized`, and float normalization tensors remain float.
218+
Pinned integration tests save the packages, open ORT CPU sessions, and verify
219+
repeatable logits and greedy outputs.
220+
221+
Other C01 candidates remain excluded until their distinct semantics are
222+
implemented and validated. These include fused/interleaved or dual-form QKV
223+
(GPT-NeoX and Phi-2), ALiBi (Baichuan and MPT), learned position embeddings
224+
(StarCoder), and unproven model aliases (Qwen and Command-R).
225+
192226
## Supported stored quantization types
193227

194228
`mobius/integrations/gguf/_quant_registry.py` covers all 43 `ggml_type` slots

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
"than building it directly."
9393
)
9494

95+
_RUNTIME_VALIDATION_PENDING = (
96+
"Config extraction, exact tensor-name closure, and a full synthetic GGUF graph build "
97+
"are covered, but no representative real-weight GGUF has yet passed ORT parity or "
98+
"generation validation. Runtime packaging remains deferred until that evidence exists."
99+
)
100+
95101

96102
_SPECS: tuple[GGUFArchitectureSpec, ...] = (
97103
# ---------------------------------------------------------------- Llama
@@ -224,6 +230,64 @@
224230
gguf_arch="internlm2",
225231
model_type="internlm2",
226232
tensor_map_recipe=("llama",),
233+
tensor_processor="llama",
234+
llama_qk_permute=True,
235+
),
236+
GGUFArchitectureSpec(
237+
gguf_arch="olmo",
238+
model_type="olmo",
239+
tensor_map_recipe=("olmo",),
240+
config_postprocessor="olmo",
241+
required_metadata=("attention.layer_norm_epsilon",),
242+
tensor_processor="llama",
243+
llama_qk_permute=True,
244+
),
245+
GGUFArchitectureSpec(
246+
gguf_arch="olmo2",
247+
model_type="olmo2",
248+
tensor_map_recipe=("llama", "olmo2_extras"),
249+
config_postprocessor="dense_sliding",
250+
required_metadata=("attention.layer_norm_rms_epsilon",),
251+
),
252+
GGUFArchitectureSpec(
253+
gguf_arch="cohere2",
254+
model_type="cohere2",
255+
tensor_map_recipe=("llama",),
256+
config_postprocessor="dense_sliding",
257+
required_metadata=(
258+
"attention.layer_norm_epsilon",
259+
"attention.sliding_window",
260+
"logit_scale",
261+
),
262+
runtime=Support.DEFERRED,
263+
reason=_RUNTIME_VALIDATION_PENDING,
264+
),
265+
GGUFArchitectureSpec(
266+
gguf_arch="arcee",
267+
model_type="arcee",
268+
tensor_map_recipe=("arcee",),
269+
required_metadata=("attention.layer_norm_rms_epsilon",),
270+
tensor_processor="llama",
271+
llama_qk_permute=True,
272+
runtime=Support.DEFERRED,
273+
reason=_RUNTIME_VALIDATION_PENDING,
274+
),
275+
GGUFArchitectureSpec(
276+
gguf_arch="smollm3",
277+
model_type="smollm3",
278+
tensor_map_recipe=("llama",),
279+
config_postprocessor="dense_sliding",
280+
required_metadata=("attention.layer_norm_rms_epsilon",),
281+
tensor_processor="llama",
282+
llama_qk_permute=True,
283+
),
284+
GGUFArchitectureSpec(
285+
gguf_arch="exaone",
286+
model_type="exaone",
287+
tensor_map_recipe=("llama",),
288+
required_metadata=("attention.layer_norm_rms_epsilon",),
289+
runtime=Support.DEFERRED,
290+
reason=_RUNTIME_VALIDATION_PENDING,
227291
),
228292
GGUFArchitectureSpec(
229293
gguf_arch="nemotron",

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@
4444
)
4545
from mobius.integrations.gguf._mmproj import _VLM_BUILDERS
4646
from mobius.integrations.gguf._spec import Support
47-
from mobius.integrations.gguf._tensor_mapping import _MAPPING_TABLES
47+
from mobius.integrations.gguf._tensor_mapping import (
48+
_MAPPING_TABLES,
49+
_build_mapping,
50+
is_known_skip,
51+
map_gguf_to_hf_names,
52+
)
4853
from mobius.integrations.gguf._tensor_processors import _PROCESSOR_IMPLS
4954
from mobius.integrations.gguf._upstream import upstream_architectures
5055

5156
#: Number of importable architectures. Pinned so that adding support is a
5257
#: deliberate act that also updates the documented support matrix, and so that
5358
#: accidentally losing an architecture is a failure rather than a silence.
54-
_EXPECTED_SUPPORTED_COUNT = 23
59+
_EXPECTED_SUPPORTED_COUNT = 29
5560

5661

5762
class TestCapabilityClosure:
@@ -197,6 +202,37 @@ def test_model_type_map_is_read_only(self) -> None:
197202
GGUF_ARCH_TO_MODEL_TYPE["nope"] = "nope" # type: ignore[index]
198203

199204

205+
class TestPinnedTensorClosure:
206+
"""Every pinned source tensor must map or be an intentional computed skip."""
207+
208+
_NEW_ARCHITECTURES = ("olmo", "olmo2", "cohere2", "arcee", "smollm3", "exaone")
209+
210+
@staticmethod
211+
def _unmapped(architecture: str) -> list[str]:
212+
upstream = upstream_architectures()[architecture]
213+
unmapped = []
214+
for family in upstream.tensor_families:
215+
name = family.replace("{bid}", "0") + ".weight"
216+
if map_gguf_to_hf_names(name, architecture) is None and not is_known_skip(name):
217+
unmapped.append(family)
218+
return unmapped
219+
220+
@pytest.mark.parametrize("architecture", _NEW_ARCHITECTURES)
221+
def test_every_pinned_tensor_family_closes(self, architecture: str) -> None:
222+
assert not self._unmapped(architecture)
223+
224+
def test_deleting_one_mapping_breaks_closure(self) -> None:
225+
"""Falsify the support claim rather than only testing the happy path."""
226+
olmo_mapping = _MAPPING_TABLES["olmo"]
227+
removed = olmo_mapping.pop("blk.{bid}.attn_q")
228+
_build_mapping.cache_clear()
229+
try:
230+
assert self._unmapped("olmo") == ["blk.{bid}.attn_q"]
231+
finally:
232+
olmo_mapping["blk.{bid}.attn_q"] = removed
233+
_build_mapping.cache_clear()
234+
235+
200236
class TestRejectionsAreActionable:
201237
"""An unsupported input must say what it is and what to do instead."""
202238

@@ -257,7 +293,7 @@ def _expected_rows() -> list[str]:
257293
model_type = f"`{spec.model_type}`" if spec.model_type else "—"
258294
status = (
259295
"supported"
260-
if spec.is_importable
296+
if all(verdict is Support.SUPPORTED for verdict in spec.verdicts.values())
261297
else "; ".join(
262298
f"{name} {verdict.value}"
263299
for name, verdict in spec.verdicts.items()

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

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ def _write_quantized_gguf(
114114
writer.add_head_count(num_heads)
115115
writer.add_head_count_kv(num_kv_heads)
116116
writer.add_rope_freq_base(10000.0)
117-
writer.add_layer_norm_rms_eps(1e-5)
117+
if architecture in {"olmo", "cohere2"}:
118+
writer.add_layer_norm_eps(1e-5)
119+
else:
120+
writer.add_layer_norm_rms_eps(1e-5)
121+
if architecture == "cohere2":
122+
writer.add_sliding_window(128)
123+
writer.add_logit_scale(0.0625)
124+
writer.add_rope_dimension_count(head_dim := hidden_size // num_heads)
118125
writer.add_vocab_size(vocab_size)
119126

120127
head_dim = hidden_size // num_heads
@@ -264,16 +271,25 @@ def add_projection(name: str, n_out: int, k_in: int) -> None:
264271
hidden_size,
265272
num_heads * head_dim,
266273
)
267-
add_projection(f"blk.{i}.ffn_gate.weight", intermediate_size, hidden_size)
274+
if architecture != "arcee":
275+
add_projection(f"blk.{i}.ffn_gate.weight", intermediate_size, hidden_size)
268276
add_projection(f"blk.{i}.ffn_up.weight", intermediate_size, hidden_size)
269277
add_projection(f"blk.{i}.ffn_down.weight", hidden_size, intermediate_size)
270-
# Norms (float32)
271-
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
272-
add_float(f"blk.{i}.ffn_norm.weight", (hidden_size,))
278+
if architecture == "olmo2":
279+
add_float(f"blk.{i}.post_attention_norm.weight", (hidden_size,))
280+
add_float(f"blk.{i}.post_ffw_norm.weight", (hidden_size,))
281+
add_float(f"blk.{i}.attn_q_norm.weight", (num_heads * head_dim,))
282+
add_float(f"blk.{i}.attn_k_norm.weight", (num_kv_heads * head_dim,))
283+
elif architecture == "cohere2":
284+
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
285+
elif architecture != "olmo":
286+
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
287+
add_float(f"blk.{i}.ffn_norm.weight", (hidden_size,))
273288

274289
# Output norm + optional untied lm_head
275-
add_float("output_norm.weight", (hidden_size,))
276-
if not tie_embeddings:
290+
if architecture != "olmo":
291+
add_float("output_norm.weight", (hidden_size,))
292+
if architecture != "cohere2" and not tie_embeddings:
277293
if output_quantization == "q4_0":
278294
_add_q4_0("output.weight", vocab_size, hidden_size)
279295
elif output_quantization == "q8_0":
@@ -1081,6 +1097,53 @@ def test_float_only_default_uses_float_path(self, float_only_gguf: Path):
10811097
assert "GatherBlockQuantized" not in op_types
10821098
assert "BlockQuantizedMatMul" not in op_types
10831099

1100+
@pytest.mark.parametrize(
1101+
"architecture",
1102+
["olmo", "olmo2", "cohere2", "arcee", "smollm3", "exaone"],
1103+
)
1104+
@pytest.mark.parametrize("projection_quantization", ["f32", "q4_0"])
1105+
def test_dense_cohort_builds_complete_graphs(
1106+
self,
1107+
architecture: str,
1108+
projection_quantization: str,
1109+
tmp_path: Path,
1110+
) -> None:
1111+
"""Exact per-architecture tensor sets satisfy the full graph."""
1112+
from mobius.integrations.gguf import build_from_gguf
1113+
1114+
path = tmp_path / f"{architecture}-{projection_quantization}.gguf"
1115+
_write_quantized_gguf(
1116+
path,
1117+
architecture=architecture,
1118+
projection_quantization=projection_quantization,
1119+
)
1120+
1121+
model = build_from_gguf(path)["model"]
1122+
op_types = {node.op_type for node in model.graph}
1123+
if projection_quantization == "q4_0":
1124+
assert "MatMulNBits" in op_types
1125+
else:
1126+
assert "MatMulNBits" not in op_types
1127+
1128+
output_dir = tmp_path / f"{architecture}-{projection_quantization}-onnx"
1129+
build_from_gguf(path).save(output_dir, progress_bar=False)
1130+
session = ort.InferenceSession(
1131+
str(output_dir / "model.onnx"),
1132+
providers=["CPUExecutionProvider"],
1133+
)
1134+
feeds = {
1135+
"input_ids": np.array([[1, 2]], dtype=np.int64),
1136+
"attention_mask": np.ones((1, 2), dtype=np.int64),
1137+
"position_ids": np.array([[0, 1]], dtype=np.int64),
1138+
"past_key_values.0.key": np.empty((1, 2, 0, 16), dtype=np.float32),
1139+
"past_key_values.0.value": np.empty((1, 2, 0, 16), dtype=np.float32),
1140+
}
1141+
first = session.run(["logits"], feeds)[0]
1142+
second = session.run(["logits"], feeds)[0]
1143+
assert first.shape == (1, 2, 256)
1144+
assert np.isfinite(first).all()
1145+
np.testing.assert_array_equal(first, second)
1146+
10841147
def test_q4_0_matmulnbits_has_explicit_zero_points(self, q4_0_gguf: Path):
10851148
"""GGUF Q4_0 projections explicitly encode zp=8 instead of EP defaults."""
10861149
from mobius.integrations.gguf import build_from_gguf

0 commit comments

Comments
 (0)