Skip to content

Add recurrent Mamba GGUF import - #577

Merged
justinchuby merged 3 commits into
mainfrom
justinchuby-gguf-mamba-recurrent
Aug 25, 2026
Merged

justinchuby merged 3 commits into
mainfrom
justinchuby-gguf-mamba-recurrent

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • add direct GGUF registry, config, tensor mapping, and transform support for pure mamba and mamba2
  • preserve recurrent conv/SSM state I/O, make Mamba1's one-token prompt threading explicit, retain Mamba2 multi-token prefill, and reject KV static-cache mode
  • validate GGUF conv/A/D/norm transforms, quantized-role dequantization, tied outputs, exact pinned tensor closure, malformed inputs, state evolution, and save/load
  • explicitly defer arwkv7, rwkv6, rwkv6qwen2, and rwkv7 because Mobius has no matching RWKV graph

Runtime status

Runtime remains deferred pending independent full-logit parity and deterministic stateful generation on real GGUF payloads. Header-only range audits pinned:

  • Mamba Q2_K: QuantFactory/mamba-130m-hf-GGUF@f781792fcca13eb3457a00dc41674715608b02da, 69,302,464 bytes, SHA-256 922a9c947f979024fe3675b11a9257637d2226f8953f1831a351890953a5209a
  • Mamba2 Q8_0: rpatel622/mamba2-130m-hf-Q8_0-GGUF@0daf70963405439f2102f6fefe92d7584e2c76eb, 180,669,152 bytes, SHA-256 c5d91a0653794a159f19d60159c362b179b506a206be120f8b63f43013155839

Validation

  • 1,268 affected GGUF/Mamba/task tests passed, 2 skipped
  • Mamba2 synthetic Hugging Face full-logit parity passed for single-token and multi-step state threading
  • full lintrunner passed
  • broad non-integration suite: 5,656 passed, 52 skipped; its only 2 failures reproduce independently in untouched glm_moe_dsa symbolic shape inference

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 89fe423 → 5f941f5

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 89fe423 → 5f941f5

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 1 🔴
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪
mamba (ssm-text-generation) / model — 1 change(s)

Op summary: 94 → 94 nodes

No op-sequence changes.

Interface changes:

  • input[0]: shape ['?', '?'] → ['?', '1']; output[0]: shape ['?', '?', '256'] → ['?', '1', '256']; output[1]: shape ['?', '128', '?'] → ['?', '128', '3']; output[3]: shape ['?', '128', '?'] → ['?', '128', '3']

Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@justinchuby
justinchuby force-pushed the justinchuby-gguf-moe-transformer-cohort branch from 72b4f42 to 4d6efb5 Compare August 25, 2026 15:07
Base automatically changed from justinchuby-gguf-moe-transformer-cohort to main August 25, 2026 15:08
@justinchuby
justinchuby requested a review from a team August 25, 2026 15:08
justinchuby and others added 3 commits August 25, 2026 08:09
Implement pinned llama.cpp metadata, tensor mappings, and value transforms for pure Mamba and Mamba2 GGUF files. Preserve recurrent state I/O, reject KV static-cache mode, validate quantized-source dequantization, and defer runtime claims pending independent real-model parity. Explicitly defer RWKV architectures that lack matching Mobius graphs.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Match llama.cpp's optional Mamba dt_b_c_rms default and replace family-only closure with suffix-exact tensor names from the pinned C++ creation sites. Reject malformed recurrent suffixes before graph construction and add mutation and negative regressions.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Preserve the reviewed Mamba and Mamba2 recurrent import semantics atop the parent squash while honoring the parent branch's explicit quantized-reachability contract. Reject keep_quantized for recurrent graphs without packed projection consumers, retain explicit float dequantization and stateful execution coverage, and regenerate the support matrix.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby force-pushed the justinchuby-gguf-mamba-recurrent branch from 486641c to 5f941f5 Compare August 25, 2026 15:13
Copilot AI lite review requested due to automatic review settings August 25, 2026 15:13
@justinchuby
justinchuby merged commit 0b5ea12 into main Aug 25, 2026
19 of 22 checks passed
@justinchuby
justinchuby deleted the justinchuby-gguf-mamba-recurrent branch August 25, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class GGUF import plumbing for pure recurrent Mamba (mamba) and Mamba2 (mamba2) models in Mobius, including config extraction, suffix-exact tensor-name closure (pinned to llama.cpp), tensor mapping + value transforms, and recurrent conv/SSM state I/O for state-threaded execution. The PR explicitly keeps runtime status deferred pending independent real-weight parity/determinism evidence, and adds explicit deferrals for RWKV architectures due to missing Mobius graphs.

Changes:

  • Extend the GGUF architecture registry/pins to recognize mamba/mamba2 (and explicitly defer RWKV variants), including suffix-exact pinned tensor names and new pre-build validation for malformed tensor names.
  • Implement Mamba/Mamba2 GGUF config + tensor mapping/processing (A_log/D/norm transforms, bare parameters, and state shape conventions), and make Mamba1’s single-token recurrence contract explicit (while preserving Mamba2 multi-token prefill).
  • Add broad unit/integration-style coverage for recurrent GGUF import behavior: malformed inputs, quantized-source dequantization policy, state evolution, save/load, and static-cache rejection; plus docs updates to the support matrix and evidence notes.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/mamba2_integration_test.py Aligns Mamba2 SSM state tensor layout used in integration stepping.
src/mobius/tasks/_task_test.py Adds assertions for Mamba1 fixed seq-len vs Mamba2 symbolic seq-len task I/O.
src/mobius/tasks/_ssm_causal_lm.py Makes SSM task input sequence length configurable (fixed for Mamba1, symbolic for Mamba2).
src/mobius/models/mamba.py Threads Mamba2 chunk_size into block construction and updates stated SSM state layout.
src/mobius/integrations/gguf/_upstream.py Extends upstream pin schema to include suffix-exact tensor_names.
src/mobius/integrations/gguf/_upstream_data/llamacpp_pin.json Pins Mamba/Mamba2 tensor families + exact tensor names emitted by llama.cpp.
src/mobius/integrations/gguf/_tensor_processors.py Implements Mamba/Mamba2 GGUF tensor value/shape transforms (A_log/D/norm).
src/mobius/integrations/gguf/_tensor_processors_test.py Adds tests for decay transform correctness, malformed input rejection, and Mamba2 squeezing rules.
src/mobius/integrations/gguf/_tensor_mapping.py Adds Mamba mapping, splits Mamba2 mapping, and enforces allowed recurrent suffixes.
src/mobius/integrations/gguf/_tensor_mapping_test.py Updates/extends mapping tests for Mamba and Mamba2 bare parameters + suffix behavior.
src/mobius/integrations/gguf/_config_mapping.py Adds Mamba/Mamba2 GGUF config postprocessors and recurrent-specific key handling.
src/mobius/integrations/gguf/_config_mapping_test.py Adds config extraction tests for pure recurrent metadata and error conditions.
src/mobius/integrations/gguf/_builder.py Adds pre-build malformed recurrent tensor validation and rejects static_cache for Mamba/Mamba2.
src/mobius/integrations/gguf/_builder_test.py Adds end-to-end recurrent GGUF build/state threading/save-load and rejection coverage.
src/mobius/integrations/gguf/_arch_registry.py Registers mamba/mamba2 as deferred runtime, rejects quantized import, and defers RWKV arches.
src/mobius/integrations/gguf/_arch_registry_test.py Updates pinned support counts, quantized verdict pinning, and adds recurrent tensor-name closure tests.
src/mobius/_configs/_base.py Adds persistent identity/token fields to BaseModelConfig and adds Mamba2 chunk_size.
docs/api/build_from_gguf.md Updates the published support matrix and documents the “pure recurrent Mamba evidence” status.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 35 to 39
conv_state_shape: list,
ssm_state_shape: list,
sequence_length: int | ir.SymbolicDim,
) -> ModelPackage:
"""Shared implementation for SSM causal LM tasks.
justinchuby added a commit that referenced this pull request Aug 25, 2026
## 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
justinchuby added a commit that referenced this pull request Aug 25, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants