Repository navigation
Add encoder GGUF import cohort - #579
Conversation
Performance Comparison
|
486641c to
5f941f5
Compare
Register exact BERT and constrained ModernBERT feature-extraction imports from the pinned llama.cpp schema. Reject unsupported pooling, classifier, cache, causal, sliding-window, and auxiliary quantization contracts instead of silently dropping them. Add suffix-exact closure, synthetic float and quantized source runtime coverage, artifact evidence, and non-generative CLI/API documentation. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Support pinned float fused BERT QKV tensors with exact row splitting and mixed-file repacking, while rejecting packed fused forms and ambiguous or malformed alternatives before graph construction. Fail closed on BERT GQA metadata. Route compatible encoder projections through MatMulNBits while explicitly dequantizing token embeddings until encoder GatherBlockQuantized support exists. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c4bf2eec-ec8f-4856-8bfd-b1654ce7718a Signed-off-by: Justin Chu <[email protected]>
Apply the encoder KV-head equality invariant to both BERT and ModernBERT before tensor validation and graph construction. Share absent, equal, and unequal metadata coverage so future encoder additions cannot silently drift from full-width K/V projections. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c4bf2eec-ec8f-4856-8bfd-b1654ce7718a Signed-off-by: Justin Chu <[email protected]>
Apply role-aware qtype validation to encoder module-relative names while preserving the reviewed float token-embedding fallback and packed projection path. Extend the generated capability matrix and quantized-import closure pins for BERT and ModernBERT. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
032a967 to
a7a8aad
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a new GGUF import “cohort” for encoder-only architectures (BERT and a constrained ModernBERT subset), with strict contract validation and documentation/tests to ensure only token-level last_hidden_state feature-extraction graphs are produced (no pooling/heads/generation/cache).
Changes:
- Add GGUF architecture registry + tensor/config mappings for
bertandmodern-bert, and enforce encoder-only task/metadata/tensor-shape contracts during GGUF validation/build. - Extend BERT/ModernBERT model implementations to support quantized linear factories (MatMulNBits) while explicitly dequantizing encoder embeddings.
- Add focused encoder GGUF tests (float + quantized, fused-QKV split behavior, variable masks/sequence lengths) and update docs/model catalog.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/mobius/models/modernbert.py | Use quantized linear factory when configured; switch encoder norms to bias-free LayerNorm; build 4D padding mask for ONNX Attention. |
| src/mobius/models/bert.py | Thread quantized linear factory through BERT encoder layers so keep-quantized imports can target MatMulNBits projections. |
| src/mobius/integrations/gguf/_upstream_data/llamacpp_pin.json | Pin encoder tensor families/names for upstream llama.cpp cohort closure checks. |
| src/mobius/integrations/gguf/_tensor_mapping.py | Add GGUF→HF tensor mapping tables for BERT and ModernBERT encoders. |
| src/mobius/integrations/gguf/_config_mapping.py | Map hidden_activation metadata; add encoder postprocessors and encoder metadata validation. |
| src/mobius/integrations/gguf/_builder.py | Add encoder head rejection + strict encoder tensor-contract validation; enforce encoder-only task/static-cache constraints; generalize fused-projection splitting for quantized repack. |
| src/mobius/integrations/gguf/_builder_test.py | Add synthetic encoder GGUF build/save/load/runtime tests, quantized-vs-float execution comparisons, and negative contract tests. |
| src/mobius/integrations/gguf/_arch_registry.py | Register bert and modern-bert GGUF specs (runtime deferred) and defer known-incompatible encoder variants with reasons. |
| src/mobius/integrations/gguf/_arch_registry_test.py | Update pinned supported counts and closure coverage for new encoder architectures. |
| docs/model-catalog.md | Document encoder GGUF import behavior and strict contract (token embeddings only). |
| docs/cli_reference.md | Document encoder-only GGUF behavior, rejections, and quantization limitations (no quantized embeddings). |
| docs/api/build_from_gguf.md | Extend support matrix + document the encoder-only GGUF contract and deferred runtime evidence. |
Suppressed comments (1)
src/mobius/integrations/gguf/_builder.py:427
- In
_raise_for_invalid_encoder_tensor_contract,tokenizer.ggml.token_type_countdefaults to 0 when missing. That can make the required shape fortoken_types.weightbecome(0, hidden), which leads to confusing "invalid encoder tensor shape" errors if the tensor exists (it will never be 0 rows).
It’s clearer to fail early with a dedicated error when token_type_count is missing or <= 0 (matching the later config postprocessor’s contract).
if architecture == "bert":
token_types = int(metadata.get("tokenizer.ggml.token_type_count", 0))
required.update(
{
"token_types.weight": (token_types, hidden),
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| metadata = gguf_model.metadata | ||
| hidden = int(metadata[f"{architecture}.embedding_length"]) | ||
| intermediate = int(metadata[f"{architecture}.feed_forward_length"]) | ||
| layers = int(metadata[f"{architecture}.block_count"]) | ||
| num_heads = int(metadata[f"{architecture}.attention.head_count"]) |
| if offset != int(np_shape[0]): | ||
| raise ValueError( | ||
| f"Fused QKV tensor {hf_name!r} has {np_shape[0]} rows, " | ||
| f"but Q/K/V targets require {offset}" | ||
| ) |
## Summary - add suffix-exact pinned llama.cpp mappings and config extraction for `t5` and `t5encoder` - preserve separate encoder/decoder namespaces, per-layer relative bias ownership, FFN gating, shared embeddings, unequal stack depths, masks, and T5 cross-attention caching - preserve compatible quantized projections through `MatMulNBits` while explicitly dequantizing token embeddings and rejecting unsupported sidecars/layouts - add encoder-only and seq2seq synthetic float/quantized ORT coverage, value-level transforms, malformed-input falsification, save/load, variable masks, prefill/decode cache tests, and HuggingFace T5/mT5/FLAN-T5/BART parity - document pinned real GGUF candidates and keep runtime support deferred pending independent real-artifact parity ## Validation - `lintrunner f --output oneline --all-files` - `python -m pytest tests/seq2seq_integration_test.py -q --tb=short` — 10 passed - broad non-integration suite excluding the pre-existing `glm_moe_dsa` shape-inference failure — 5,742 passed, 52 skipped - the two `glm_moe_dsa` failures in the unfiltered broad run reproduce unchanged on base commit `032a967` Stacked on #579 / `justinchuby-gguf-encoder-cohort`. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: 59c34ad7-370a-4534-96f4-d5a97f36f808
## Summary - clean up still-valid typing, documentation, test robustness, error-message, maintainability, and performance findings left by the GGUF PR stack - preserve the behavioral fixes merged in #625-#632 - hash reused multi-GB GGUF sources once, at the final pre-publication integrity gate, while retaining cheap identity checks around staging Exact base: `2db9d33debdc254d879a51b14434c9a81c230f4f` Exact head: `4541ed2bc9d2ab4227484510b4a85b2d9113eb25` ## Reconstructed original 17-item low-priority tranche The persisted audit retained only the totals, so this list was reconstructed from the live threads and current source. All but the already-fixed #596 comment are addressed in this PR. | PR | Comment | Disposition | |---|---:|---| | #550 | 3837144656 | Implemented: correct tuple return annotation | | #552 | 3837389183 | Implemented: multichannel waveform shape docs | | #559 | 3837716261 | Implemented: name-based cache assertions | | #573 | 3854308350 | Implemented: one final GGUF hash, with integrity regression coverage | | #574 | 3854345521 | Implemented: `TensorRole \| None` typing | | #574 | 3854345597 | Implemented: removed obsolete verdict filtering | | #577 | 3854472859 | Implemented: documented SSM sequence length | | #578 | 3843112613 | Implemented: documented F64 passthrough | | #579 | 3854518332 | Implemented: generalized fused-projection error | | #580 | 3854576300 | Implemented: removed brittle node counts | | #583 | 3854681386 | Implemented: documented conditional draft outputs | | #587 | 3854816872 | Implemented: corrected MTP output contract docs | | #596 | 3846110059 | Already fixed on base: unambiguous GQA bias comment | | #600 | 3855174281 | Implemented: metadata-count-only MTP error | | #607 | 3855776048 | Implemented: stable route-field assertions | | #607 | 3855776086 | Implemented: public tensor iterator | | #609 | 3856486136 | Implemented: fail-closed LM-head comment | ## Current unresolved-thread disposition This covers all 48 Copilot threads returned by the reproducible #600-#630 query. The one human #623 thread is excluded. | PR | Comment | Current-main disposition and evidence | |---|---:|---| | #600 | 3855174177 | Already fixed by #629: package cycle and reserved-sidecar validation | | #600 | 3855174238 | Already fixed by #629: explicit MTP sidecar naming/loading | | #600 | 3855174281 | Implemented here: error no longer invents an observed block count | | #602 | 3848155961 | Outside exact stack; already fixed: top-level `expert_dtype` is classified before early return | | #602 | 3848155983 | Outside exact stack; still-valid behavioral block-quant validation, unchanged | | #602 | 3848156000 | Outside exact stack; still-valid truncated-read behavioral finding, unchanged | | #602 | 3848156022 | Outside exact stack; still-valid descriptor byte/dtype validation, unchanged | | #602 | 3848156040 | Outside exact stack; still-valid expert-bank payload validation, unchanged | | #603 | 3855249765 | Already fixed by #630: runtime preflight preserves shard sets | | #603 | 3855249840 | Already fixed by #630: success output follows durable runtime publication | | #604 | 3855343082 | Implemented here: graph-only MTP persistence distinguished from runtime rejection | | #604 | 3855343131 | Already fixed by #630: runtime success messages are atomic | | #607 | 3855776001 | Implemented here: missing generation golden skips before provenance read | | #607 | 3855776048 | Implemented here: only stable route fields are asserted | | #607 | 3855776086 | Implemented here: tensor count uses `tensor_items_raw()` | | #608 | 3856079371 | Still-valid behavioral cache-symlink containment finding; unchanged | | #608 | 3856079415 | Still-valid behavioral lowercase-digest validation finding; unchanged | | #609 | 3856486136 | Implemented here: comment matches value-preserving policy | | #610 | 3855541683 | Already fixed by #628: Falcon bias precedence is explicit | | #610 | 3855541761 | Already fixed by #628: CTRL tiny config exercises projection biases | | #611 | 3856595840 | Implemented here: runtime test resolves the distribution providing the module | | #612 | 3855677383 | Already fixed by #625: supported-version endianness detection | | #612 | 3855677427 | Implemented here: shared `INT64_MAX` sentinel | | #612 | 3855677460 | Implemented here: shared PLaMo2 width inference | | #612 | 3855677486 | Implemented here: accepted PLaMo2 activation spellings are explicit | | #613 | 3855845678 | Implemented here: canonical issue URL | | #613 | 3855845757 | Implemented here: Mamba-1 function-registration docs | | #613 | 3855845806 | Implemented here: test expects the canonical issue URL | | #614 | 3855988545 | Implemented here: removed stale Nemotron-H divergence comments | | #614 | 3855988597 | Already fixed by #628: zero-head geometry raises actionable `ValueError` | | #615 | 3856082290 | Already fixed by #626: dense GraniteHybrid bias closure | | #618 | 3856729330 | Implemented here: required routes filter ORT GenAI evidence | | #618 | 3856729409 | Implemented here: env-selected runtime version is authoritative | | #618 | 3856729490 | Stale/N/A: PR-description-only matrix claim; repository workflow claims one pinned version | | #618 | 3856729563 | Implemented here: schema tail restored to normal indentation | | #619 | 3856342484 | Already fixed on base: Kimi Linear uses `/issues/605` | | #619 | 3856342532 | Already fixed by #628: config rejects convolution kernels below 2 | | #619 | 3856342580 | Already fixed by #628: GGUF contract rejects convolution kernels below 2 | | #620 | 3855717041 | Already fixed by #627: tied LM-head-only checkpoints are retained | | #621 | 3856722324 | Already fixed by #628: Kimi-K3 required metadata is complete | | #623 | 3855931210 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939302 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939358 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939394 | N/A to current main: comment belongs to open, unmerged #623 | | #624 | 3856777152 | Implemented here: runtime compatibility reuses the emitted model type | | #625 | 3857049733 | Implemented here: unsupported header reports both endian candidates | | #629 | 3857313182 | Newer post-audit behavioral sidecar-symlink cleanup finding; unchanged | | #629 | 3857313251 | Newer post-audit cross-platform path-safety finding; unchanged | ## Validation - affected GGUF/package/ORT GenAI/model/schema tests: 1,040 passed - broad non-integration suite: 7,851 passed, 56 skipped, 1 subtest passed - generated GGUF docs checks: 7 passed - initialized `lintrunner`; full lint/format passed - GPT-5.6 Sol medium review: one integrity finding fixed; re-review found no significant issues Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
Summary
feature-extractionimports for BERT and a constrained ModernBERT subset derived from llama.cpp8d9af256337d1a501250f9bbf4c0859a654bddd6last_hidden_stateoutput and reject generative tasks, cache options, pooling, classifier/reranker heads, causal metadata, sliding-window ModernBERT, malformed tensors, and quantization sidecarsReal artifact evidence
PierreMesure/sentence-bert-swedish-cased-gguf@f737e1c3fa76176845a1a9dfc3fd8aee82e8f159,sentence-bert-swedish-cased.F32.gguf, 497,449,376 bytes, SHA-2569ee1505b22d4bc8d192095f924ddb62bc4783a48fbd411252310933e879930f8: metadata/tensor census verified by ranged reads; runtime deferred because it requires mean poolingkeisuke-miyako/modernbert-ja-30m-gguf-q8_0@b51053917455553a61b5319560dbd00b7d53323d,modernbert-ja-30m-Q8_0.gguf, 41,466,080 bytes, SHA-256b56a63b0adc5942dbc949153b071bd90557380fa32ca190cc833e85fb1529932: metadata/tensor census verified by ranged reads; runtime deferred because it requires sliding-window attentionNo independent real-artifact parity is claimed for those rejected variants.
Validation
glm_moe_dsashape-inference failuresStacked on #577 (
justinchuby-gguf-mamba-recurrent).