Skip to content

Commit 29d33a9

Browse files
justinchubyCopilot
andcommitted
Add dense GGUF architecture cohort
Add exact config and tensor mappings for OLMo, OLMo2, Cohere2, Arcee, SmolLM3, and Exaone against the pinned llama.cpp architecture census. Preserve architecture-specific normalization, RoPE, attention schedules, quantized module wiring, and InternLM2 Q/K permutation semantics. Validate strict tensor closure, synthetic float and quantized graph execution, and pinned real OLMo-family GGUF artifacts while deferring runtime claims that lack real-weight evidence. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 7958f1a commit 29d33a9

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
@@ -99,10 +99,13 @@ reason.
9999

100100
| GGUF architecture | Accepted aliases | mobius `model_type` | Status |
101101
|---|---|---|---|
102+
| `arcee` | — | `arcee` | runtime deferred |
102103
| `bloom` | — | `bloom` | tensor_map deferred |
103104
| `clip` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected |
105+
| `cohere2` | — | `cohere2` | runtime deferred |
104106
| `deci` | — | `llama` | supported |
105107
| `deepseek4` | — | `deepseek_v4` | supported |
108+
| `exaone` | — | `exaone` | runtime deferred |
106109
| `falcon` | — | `falcon` | supported |
107110
| `gemma` | — | `gemma` | supported |
108111
| `gemma2` | — | `gemma2` | supported |
@@ -117,13 +120,16 @@ reason.
117120
| `muse-glimmer` | `muse_glimmer` | `muse_glimmer_text` | supported |
118121
| `nemotron` | — | `nemotron` | supported |
119122
| `nemotron_h_moe` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected |
123+
| `olmo` | — | `olmo` | supported |
124+
| `olmo2` | — | `olmo2` | supported |
120125
| `phi3` | — | `phi3` | supported |
121126
| `qwen2` | — | `qwen2` | supported |
122127
| `qwen2moe` | `qwen2_moe` | `qwen2_moe` | supported |
123128
| `qwen3` | — | `qwen3` | supported |
124129
| `qwen35` | — | `qwen3_5_text` | supported |
125130
| `qwen35moe` | — | `qwen3_5_moe` | supported |
126131
| `qwen3moe` | `qwen3_moe` | `qwen3_moe` | supported |
132+
| `smollm3` | — | `smollm3` | supported |
127133
| `stablelm` | — | `stablelm` | supported |
128134
| `starcoder2` | — | `starcoder2` | supported |
129135
| `t5` | — | `t5` | tensor_map deferred |
@@ -143,6 +149,34 @@ upstream cohort, so an unsupported input is never mistaken for a broken one.
143149
Sharded GGUF files are rejected. A single shard has only part of the tensor
144150
table, and treating it as a complete checkpoint would create a corrupt model.
145151

152+
### Dense-transformer validation
153+
154+
The first dense-transformer cohort adds exact config, tensor-map, and graph
155+
support for OLMo, OLMo2, Cohere2, Arcee, SmolLM3, and Exaone. Runtime remains
156+
deferred for Cohere2, Arcee, and Exaone until pinned real-weight parity or
157+
generation evidence is available; synthetic graph execution alone is not a
158+
runtime claim.
159+
160+
Runtime coverage for the other three mappings is pinned to:
161+
162+
| Architecture | Revision and file | Size | SHA-256 | Stored qtypes |
163+
|---|---|---:|---|---|
164+
| 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 |
165+
| 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 |
166+
| 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 |
167+
168+
For these mixed Q4_K_M artifacts, projections are not preserved natively.
169+
Q4_K and Q6_K tensors are dequantized and affine-requantized to explicit
170+
zero-point 4-bit/block-32 `MatMulNBits`; compatible token embeddings use
171+
`GatherBlockQuantized`, and float normalization tensors remain float.
172+
Pinned integration tests save the packages, open ORT CPU sessions, and verify
173+
repeatable logits and greedy outputs.
174+
175+
Other C01 candidates remain excluded until their distinct semantics are
176+
implemented and validated. These include fused/interleaved or dual-form QKV
177+
(GPT-NeoX and Phi-2), ALiBi (Baichuan and MPT), learned position embeddings
178+
(StarCoder), and unproven model aliases (Qwen and Command-R).
179+
146180
## Supported stored quantization types
147181

148182
`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
@@ -112,7 +112,14 @@ def _write_quantized_gguf(
112112
writer.add_head_count(num_heads)
113113
writer.add_head_count_kv(num_kv_heads)
114114
writer.add_rope_freq_base(10000.0)
115-
writer.add_layer_norm_rms_eps(1e-5)
115+
if architecture in {"olmo", "cohere2"}:
116+
writer.add_layer_norm_eps(1e-5)
117+
else:
118+
writer.add_layer_norm_rms_eps(1e-5)
119+
if architecture == "cohere2":
120+
writer.add_sliding_window(128)
121+
writer.add_logit_scale(0.0625)
122+
writer.add_rope_dimension_count(head_dim := hidden_size // num_heads)
116123
writer.add_vocab_size(vocab_size)
117124

118125
head_dim = hidden_size // num_heads
@@ -262,16 +269,25 @@ def add_projection(name: str, n_out: int, k_in: int) -> None:
262269
hidden_size,
263270
num_heads * head_dim,
264271
)
265-
add_projection(f"blk.{i}.ffn_gate.weight", intermediate_size, hidden_size)
272+
if architecture != "arcee":
273+
add_projection(f"blk.{i}.ffn_gate.weight", intermediate_size, hidden_size)
266274
add_projection(f"blk.{i}.ffn_up.weight", intermediate_size, hidden_size)
267275
add_projection(f"blk.{i}.ffn_down.weight", hidden_size, intermediate_size)
268-
# Norms (float32)
269-
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
270-
add_float(f"blk.{i}.ffn_norm.weight", (hidden_size,))
276+
if architecture == "olmo2":
277+
add_float(f"blk.{i}.post_attention_norm.weight", (hidden_size,))
278+
add_float(f"blk.{i}.post_ffw_norm.weight", (hidden_size,))
279+
add_float(f"blk.{i}.attn_q_norm.weight", (num_heads * head_dim,))
280+
add_float(f"blk.{i}.attn_k_norm.weight", (num_kv_heads * head_dim,))
281+
elif architecture == "cohere2":
282+
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
283+
elif architecture != "olmo":
284+
add_float(f"blk.{i}.attn_norm.weight", (hidden_size,))
285+
add_float(f"blk.{i}.ffn_norm.weight", (hidden_size,))
271286

272287
# Output norm + optional untied lm_head
273-
add_float("output_norm.weight", (hidden_size,))
274-
if not tie_embeddings:
288+
if architecture != "olmo":
289+
add_float("output_norm.weight", (hidden_size,))
290+
if architecture != "cohere2" and not tie_embeddings:
275291
if output_quantization == "q4_0":
276292
_add_q4_0("output.weight", vocab_size, hidden_size)
277293
elif output_quantization == "q8_0":
@@ -441,6 +457,53 @@ def test_float_only_default_uses_float_path(self, float_only_gguf: Path):
441457
assert "GatherBlockQuantized" not in op_types
442458
assert "BlockQuantizedMatMul" not in op_types
443459

460+
@pytest.mark.parametrize(
461+
"architecture",
462+
["olmo", "olmo2", "cohere2", "arcee", "smollm3", "exaone"],
463+
)
464+
@pytest.mark.parametrize("projection_quantization", ["f32", "q4_0"])
465+
def test_dense_cohort_builds_complete_graphs(
466+
self,
467+
architecture: str,
468+
projection_quantization: str,
469+
tmp_path: Path,
470+
) -> None:
471+
"""Exact per-architecture tensor sets satisfy the full graph."""
472+
from mobius.integrations.gguf import build_from_gguf
473+
474+
path = tmp_path / f"{architecture}-{projection_quantization}.gguf"
475+
_write_quantized_gguf(
476+
path,
477+
architecture=architecture,
478+
projection_quantization=projection_quantization,
479+
)
480+
481+
model = build_from_gguf(path)["model"]
482+
op_types = {node.op_type for node in model.graph}
483+
if projection_quantization == "q4_0":
484+
assert "MatMulNBits" in op_types
485+
else:
486+
assert "MatMulNBits" not in op_types
487+
488+
output_dir = tmp_path / f"{architecture}-{projection_quantization}-onnx"
489+
build_from_gguf(path).save(output_dir, progress_bar=False)
490+
session = ort.InferenceSession(
491+
str(output_dir / "model.onnx"),
492+
providers=["CPUExecutionProvider"],
493+
)
494+
feeds = {
495+
"input_ids": np.array([[1, 2]], dtype=np.int64),
496+
"attention_mask": np.ones((1, 2), dtype=np.int64),
497+
"position_ids": np.array([[0, 1]], dtype=np.int64),
498+
"past_key_values.0.key": np.empty((1, 2, 0, 16), dtype=np.float32),
499+
"past_key_values.0.value": np.empty((1, 2, 0, 16), dtype=np.float32),
500+
}
501+
first = session.run(["logits"], feeds)[0]
502+
second = session.run(["logits"], feeds)[0]
503+
assert first.shape == (1, 2, 256)
504+
assert np.isfinite(first).all()
505+
np.testing.assert_array_equal(first, second)
506+
444507
def test_q4_0_matmulnbits_has_explicit_zero_points(self, q4_0_gguf: Path):
445508
"""GGUF Q4_0 projections explicitly encode zp=8 instead of EP defaults."""
446509
from mobius.integrations.gguf import build_from_gguf

0 commit comments

Comments
 (0)