Skip to content

Commit a96e74a

Browse files
justinchubyCopilot
andauthored
Add encoder GGUF import cohort (#579)
## Summary - add exact GGUF `feature-extraction` imports for BERT and a constrained ModernBERT subset derived from llama.cpp `8d9af256337d1a501250f9bbf4c0859a654bddd6` - enforce token-level `last_hidden_state` output and reject generative tasks, cache options, pooling, classifier/reranker heads, causal metadata, sliding-window ModernBERT, malformed tensors, and quantization sidecars - map BERT absolute/token-type embeddings and biased post-norm blocks; map ModernBERT fused QKV/GeGLU, RoPE, padding masks, and bias-free pre-norm blocks - explicitly defer EuroBERT, Jina BERT v2/v3, NeoBERT, Nomic BERT, and Nomic BERT MoE with evidence-based incompatibility reasons - add pinned suffix-exact closure, negative falsification, float/Q4 source build-save-load-runtime tests, variable sequence/mask tests, and non-generative GGUF documentation ## Real artifact evidence - `PierreMesure/sentence-bert-swedish-cased-gguf@f737e1c3fa76176845a1a9dfc3fd8aee82e8f159`, `sentence-bert-swedish-cased.F32.gguf`, 497,449,376 bytes, SHA-256 `9ee1505b22d4bc8d192095f924ddb62bc4783a48fbd411252310933e879930f8`: metadata/tensor census verified by ranged reads; runtime deferred because it requires mean pooling - `keisuke-miyako/modernbert-ja-30m-gguf-q8_0@b51053917455553a61b5319560dbd00b7d53323d`, `modernbert-ja-30m-Q8_0.gguf`, 41,466,080 bytes, SHA-256 `b56a63b0adc5942dbc949153b071bd90557380fa32ca190cc833e85fb1529932`: metadata/tensor census verified by ranged reads; runtime deferred because it requires sliding-window attention No independent real-artifact parity is claimed for those rejected variants. ## Validation - focused encoder/closure/runtime suite: 303 passed - broad non-integration suite: 5,721 passed, 52 skipped after deselecting two unrelated, independently reproducible `glm_moe_dsa` shape-inference failures - full lintrunner: passed Stacked on #577 (`justinchuby-gguf-mamba-recurrent`). --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: c4bf2eec-ec8f-4856-8bfd-b1654ce7718a
1 parent 0b5ea12 commit a96e74a

12 files changed

Lines changed: 991 additions & 52 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ reason.
147147
|---|---|---|---|---|
148148
| `arcee` | — | `arcee` | runtime deferred | supported |
149149
| `arwkv7` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
150+
| `bert` | — | `bert` | runtime deferred | supported |
150151
| `bloom` | — | `bloom` | tensor_map deferred | unreachable |
151152
| `clip` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected | unreachable |
152153
| `cohere2` | — | `cohere2` | runtime deferred | supported |
153154
| `deci` | — | `llama` | supported | supported |
154155
| `deepseek4` | — | `deepseek_v4` | supported | supported |
156+
| `eurobert` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
155157
| `exaone` | — | `exaone` | runtime deferred | supported |
156158
| `falcon` | — | `falcon` | supported | supported |
157159
| `gemma` | — | `gemma` | supported | supported |
@@ -163,12 +165,18 @@ reason.
163165
| `granitemoe` | — | `granitemoe` | runtime deferred | supported |
164166
| `hunyuan-dense` | `hunyuan_v1_dense` | `hunyuan_v1_dense` | supported | supported |
165167
| `internlm2` | — | `internlm2` | supported | rejected |
168+
| `jina-bert-v2` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
169+
| `jina-bert-v3` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
166170
| `llama` | `mistral` | `llama` | supported | supported |
167171
| `mamba` | — | `mamba` | runtime deferred | rejected |
168172
| `mamba2` | — | `mamba2` | runtime deferred | rejected |
173+
| `modern-bert` | — | `modernbert` | runtime deferred | supported |
169174
| `muse-glimmer` | `muse_glimmer` | `muse_glimmer_text` | supported | supported |
170175
| `nemotron` | — | `nemotron` | supported | supported |
171176
| `nemotron_h_moe` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected | unreachable |
177+
| `neo-bert` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
178+
| `nomic-bert` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
179+
| `nomic-bert-moe` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
172180
| `olmo` | — | `olmo` | supported | supported |
173181
| `olmo2` | — | `olmo2` | supported | supported |
174182
| `olmoe` | — | `olmoe` | runtime deferred | supported |
@@ -195,6 +203,45 @@ validated against a vendored census of the 147 architectures llama.cpp defines
195203
at commit `8d9af256337d1a501250f9bbf4c0859a654bddd6`. Aliases are spellings
196204
llama.cpp does not emit but that mobius still accepts.
197205

206+
### Encoder-only GGUF contract
207+
208+
`bert` and `modern-bert` import only backbone files whose metadata requests
209+
non-causal, unpooled token embeddings. They produce one `model` component with
210+
`input_ids`, `attention_mask`, and `token_type_ids` inputs and one
211+
`last_hidden_state` output shaped `[batch, sequence, hidden]`. They never emit
212+
causal logits, KV cache, or recurrent state. `task` overrides other than
213+
`feature-extraction`, static cache, non-`NONE` pooling, classifier labels,
214+
`cls*` tensors, and ModernBERT sliding-window attention are rejected rather than
215+
ignored.
216+
217+
Pinned BERT files may use either split Q/K/V tensors or float fused
218+
`attn_qkv.{weight,bias}` tensors; fused rows are split losslessly before weight
219+
application. Quantized fused QKV is rejected because splitting packed blocks is
220+
not lossless. For both supported encoders, `attention.head_count_kv` defaults to
221+
`attention.head_count`; different values are rejected until the graphs support
222+
GQA-sized K/V.
223+
224+
Compatible 2-D encoder projection matrices use `MatMulNBits`, while a quantized
225+
`token_embd.weight` explicitly dequantizes: encoder modules do not yet expose the
226+
`QuantizedEmbedding`/`GatherBlockQuantized` ABI. This is intentionally not a
227+
packed-embedding preservation claim. Token-position, token-type, normalization,
228+
and bias tensors remain float; GGUF
229+
`.scale`/`.input_scale` sidecars are rejected before graph construction.
230+
231+
Runtime remains **deferred**. Header-range inspection pinned these representative
232+
artifacts before any payload use:
233+
234+
| GGUF artifact | Revision / file | Size / LFS SHA-256 | Header evidence |
235+
|---|---|---|---|
236+
| `PierreMesure/sentence-bert-swedish-cased-gguf` | `f737e1c3fa76176845a1a9dfc3fd8aee82e8f159` / `sentence-bert-swedish-cased.F32.gguf` | 497,449,376 bytes / `9ee1505b22d4bc8d192095f924ddb62bc4783a48fbd411252310933e879930f8` | `bert`, 12x768, F32 closure; rejected because `pooling_type=MEAN`. Source config/tokenizer: `KBLab/sentence-bert-swedish-cased@6b5e83cd29c03729cfdc33d13b1423399b0efb5c`. |
237+
| `keisuke-miyako/modernbert-ja-30m-gguf-q8_0` | `b51053917455553a61b5319560dbd00b7d53323d` / `modernbert-ja-30m-Q8_0.gguf` | 41,466,080 bytes / `b56a63b0adc5942dbc949153b071bd90557380fa32ca190cc833e85fb1529932` | `modern-bert`, 10x256, Q8_0 matrices/F32 norms; rejected because it declares symmetric sliding-window attention. Source config/tokenizer: `sbintuitions/modernbert-ja-30m@8cb03f54cb9e30e72459e5f1cedc6d89c7d8dcb5`. |
238+
239+
Neither artifact is runtime evidence: both are deliberately rejected before
240+
weight loading, so no independent embedding or reranker-logit parity is claimed.
241+
EuroBERT, JinaBERT v2/v3, NeoBERT, NomicBERT, and NomicBERT-MoE remain deferred
242+
because their pinned normalization, ALiBi/RoPE, gated FFN, Q/K norm, or routed
243+
expert semantics do not match the existing encoder graphs.
244+
198245
### Pure recurrent Mamba evidence
199246

200247
`mamba` and `mamba2` have config, suffix-exact C++ tensor-name closure,

‎docs/cli_reference.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ Quantized files containing only qtypes with no supported preservation target
374374
(for example, pure Q6_K or Q5_K weights) fail instead of silently becoming
375375
float. Re-run with `--dequantize` to request explicit float conversion.
376376

377+
Encoder-only BERT and ModernBERT GGUF backbones auto-select
378+
`feature-extraction` and output `last_hidden_state`; they do not produce logits
379+
or cache tensors. Static cache, generative task overrides, pooled/reranker
380+
metadata, classifier tensors, and unsupported ModernBERT sliding-window variants
381+
are rejected explicitly.
382+
Quantized encoder linear weights use `MatMulNBits`, but quantized token
383+
embeddings dequantize because these graphs do not yet implement
384+
`GatherBlockQuantized`. BERT and ModernBERT GQA metadata are rejected; BERT
385+
quantized fused QKV is also rejected, while float fused QKV is split losslessly.
386+
377387
Sharded GGUF inputs are rejected because a single shard has an incomplete
378388
tensor table. `nemotron_h_moe` is also rejected until its MTP block, Mamba2
379389
parity, mixed expert quantization, tokenizer provenance, and real ORT/ORT GenAI

‎docs/model-catalog.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ source qtypes can require dequantization/requantization, so this does not imply
273273
byte preservation for every tensor. Use `--dequantize` for an explicitly float
274274
model.
275275

276+
Encoder GGUF imports for `bert` and `modern-bert` select
277+
`feature-extraction` and expose token-level `last_hidden_state` only. Pooling,
278+
classifier/reranker heads, generative task overrides, and cache options are
279+
rejected unless their exact output contracts are implemented.
280+
276281
## Summary
277282

278283
| Category | Count | Primary Classes |

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@
117117
"the wrong recurrence. Build from a supported source/runtime instead."
118118
)
119119

120+
_ENCODER_RUNTIME_VALIDATION_PENDING = (
121+
"Config extraction, exact pinned tensor closure, encoder-only task dispatch, and "
122+
"synthetic ORT execution are covered, but no pinned real GGUF artifact has passed "
123+
"independent embedding parity. Runtime packaging remains deferred until that evidence "
124+
"exists."
125+
)
126+
127+
_ENCODER_GRAPH_MISMATCH = {
128+
"eurobert": (
129+
"EuroBERT uses pre-norm RMSNorm, RoPE, bias-free split Q/K/V attention, and a "
130+
"parallel SwiGLU FFN. Neither the post-norm BertModel nor ModernBertModel graph "
131+
"matches that architecture."
132+
),
133+
"jina-bert-v2": (
134+
"JinaBERT v2 uses ALiBi, optional full-width Q/K norms, an extra attention norm, "
135+
"and either separate or fused GeGLU inputs. Mobius has no graph with that exact "
136+
"combination."
137+
),
138+
"jina-bert-v3": (
139+
"JinaBERT v3 uses RoPE and may alternate dense GELU and routed MoE layers. "
140+
"BertModel has absolute positions and no MoE path."
141+
),
142+
"neo-bert": (
143+
"NeoBERT uses pre-norm RMSNorm, RoPE, fused QKV, and fused SwiGLU. The existing "
144+
"encoder graphs differ in normalization and projection layout."
145+
),
146+
"nomic-bert": (
147+
"NomicBERT uses RoPE and a parallel gated FFN with BERT-style post norms. "
148+
"BertModel uses absolute positions and a non-gated sequential GELU FFN."
149+
),
150+
"nomic-bert-moe": (
151+
"NomicBERT-MoE alternates dense and routed-expert FFNs according to "
152+
"moe_every_n_layers. Mobius has no encoder MoE graph with that schedule."
153+
),
154+
}
155+
120156

121157
_SPECS: tuple[GGUFArchitectureSpec, ...] = (
122158
# ---------------------------------------------------------------- Llama
@@ -282,6 +318,43 @@
282318
quantized_import=Support.REJECTED,
283319
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING + " " + _NO_QUANTIZED_PROJECTION_REASON,
284320
),
321+
# --------------------------------------------------------- Encoder-only
322+
GGUFArchitectureSpec(
323+
gguf_arch="bert",
324+
model_type="bert",
325+
tensor_map_recipe=("bert",),
326+
config_postprocessor="bert_encoder",
327+
required_metadata=(
328+
"attention.causal",
329+
"attention.layer_norm_epsilon",
330+
),
331+
runtime=Support.DEFERRED,
332+
reason=_ENCODER_RUNTIME_VALIDATION_PENDING,
333+
),
334+
GGUFArchitectureSpec(
335+
gguf_arch="modern-bert",
336+
model_type="modernbert",
337+
tensor_map_recipe=("modern_bert",),
338+
config_postprocessor="modern_bert_encoder",
339+
required_metadata=(
340+
"attention.causal",
341+
"attention.layer_norm_epsilon",
342+
"rope.freq_base",
343+
),
344+
runtime=Support.DEFERRED,
345+
reason=_ENCODER_RUNTIME_VALIDATION_PENDING,
346+
),
347+
*(
348+
GGUFArchitectureSpec(
349+
gguf_arch=architecture,
350+
config=Support.DEFERRED,
351+
tensor_map=Support.DEFERRED,
352+
graph=Support.DEFERRED,
353+
runtime=Support.DEFERRED,
354+
reason=reason,
355+
)
356+
for architecture, reason in _ENCODER_GRAPH_MISMATCH.items()
357+
),
285358
GGUFArchitectureSpec(
286359
gguf_arch="starcoder2",
287360
model_type="starcoder2",

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@
5656
#: Number of importable architectures. Pinned so that adding support is a
5757
#: deliberate act that also updates the documented support matrix, and so that
5858
#: accidentally losing an architecture is a failure rather than a silence.
59-
_EXPECTED_SUPPORTED_COUNT = 33
59+
_EXPECTED_SUPPORTED_COUNT = 35
6060

6161
# Quantized reachability is separately pinned from float importability. A new
6262
# architecture must explicitly prove that its graph exposes packed projection
6363
# modules before joining this set.
6464
_EXPECTED_QUANTIZED_IMPORT_ARCHITECTURES = frozenset(
6565
{
6666
"arcee",
67+
"bert",
6768
"cohere2",
6869
"deci",
6970
"deepseek4",
@@ -77,6 +78,7 @@
7778
"granitemoe",
7879
"hunyuan-dense",
7980
"llama",
81+
"modern-bert",
8082
"muse-glimmer",
8183
"nemotron",
8284
"olmo",
@@ -284,6 +286,8 @@ class TestPinnedTensorClosure:
284286
"granitemoe",
285287
"mamba",
286288
"mamba2",
289+
"bert",
290+
"modern-bert",
287291
)
288292

289293
@staticmethod
@@ -331,6 +335,27 @@ def test_deleting_one_mapping_breaks_closure(self) -> None:
331335
olmo_mapping["blk.{bid}.attn_q"] = removed
332336
_build_mapping.cache_clear()
333337

338+
@pytest.mark.parametrize(
339+
("architecture", "mapping_key"),
340+
[
341+
("bert", "blk.{bid}.attn_q"),
342+
("bert", "blk.{bid}.attn_qkv"),
343+
("modern-bert", "blk.{bid}.attn_qkv"),
344+
],
345+
)
346+
def test_deleting_encoder_mapping_breaks_closure(
347+
self, architecture: str, mapping_key: str
348+
) -> None:
349+
table_name = "bert" if architecture == "bert" else "modern_bert"
350+
mapping = _MAPPING_TABLES[table_name]
351+
removed = mapping.pop(mapping_key)
352+
_build_mapping.cache_clear()
353+
try:
354+
assert any(name.startswith(mapping_key) for name in self._unmapped(architecture))
355+
finally:
356+
mapping[mapping_key] = removed
357+
_build_mapping.cache_clear()
358+
334359
def test_deleting_expert_mapping_breaks_moe_closure(self) -> None:
335360
moe_mapping = _MAPPING_TABLES["moe_extras"]
336361
removed = moe_mapping.pop("blk.{bid}.ffn_gate_exps")

0 commit comments

Comments
 (0)