Skip to content

Commit 0c2d501

Browse files
justinchubyCopilot
andauthored
Add Nemotron-H MoE GGUF support (#614)
## Summary - add exact `nemotron_h_moe` GGUF backbone import with mixed Mamba2/attention/dense/MoE schedule reconstruction - preserve sigmoid correction-bias routing, ReLU-squared stacked experts, shared experts, and optional latent projections with strict tensor closure - require explicit dequantization for quantized sources and fail closed on unsupported sidecars, MTP blocks, static cache, and generic task overrides - add Transformers parity, expert-order, float/Q4 import, ORT mixed-state decode, package round-trip, malformed-input, registry, and documentation coverage ## Validation - `python -m pytest src/mobius/integrations/gguf -q --tb=short` — 2623 passed - `python -m pytest tests/build_graph_test.py tests/synthetic_parity_test.py -k nemotron_h -q --tb=short` — 11 passed, 6 skipped - changed-file Ruff check and format check — passed - two independent reviews completed; all findings fixed The broad non-integration suite reached 7135 passing tests and exposed two unrelated existing `glm_moe_dsa` shape-inference/checker failures. Stacked on #613 (`justinchuby-complete-jamba-gguf`). ORT GenAI packaging remains deferred to #605 because the released runtime schema does not represent heterogeneous KV/convolution/recurrent state slots. Released 30B-A3B GGUFs also remain rejected before graph construction because they append an unsupported combined attention+MoE MTP block. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 18b617a commit 0c2d501

15 files changed

Lines changed: 895 additions & 295 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 45 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from mobius import build_from_gguf
1515

1616
| Census | Total | Closure |
1717
|---|---:|---|
18-
| Architectures | 147 | graph verdicts: {'deferred': 88, 'rejected': 3, 'supported': 56}; importable: 54; quantized import: {'rejected': 11, 'supported': 136}; runtime: {'deferred': 144, 'rejected': 3} |
18+
| Architectures | 147 | graph verdicts: {'deferred': 88, 'rejected': 2, 'supported': 57}; importable: 55; quantized import: {'rejected': 11, 'supported': 136}; runtime: {'deferred': 145, 'rejected': 2} |
1919
| Active stored qtypes | 25 | 24 have an import route; 1 are explicitly deferred with no route |
2020
| Serialized projector strings | 60 | {'graph-importable': 2, 'runtime-supported': 0} |
2121
| Tokenizer pre identifiers | 87 | 56 semantic groups; all default to deferred and become exact-copy only with a validated embedded `tokenizer.huggingface.json` |
@@ -442,7 +442,7 @@ before graph construction or durable output.
442442
| `nanbeige` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | Nanbeige reuses physical layer weights across a configurable logical loop count, optionally normalizes between loops, and allocates a distinct KV slot for every logical occurrence. A Llama alias would build the wrong layer count and cache ABI. |
443443
| `nemotron` | — | model=`nemotron`; tensor=`llama` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | Config extraction, exact tensor-name closure, and a full synthetic GGUF graph build are covered, but no representative real-weight GGUF has yet passed ORT parity or generation validation. Runtime packaging remains deferred until that evidence exists. |
444444
| `nemotron_h` | — | model=`nemotron_h`; tensor=`nemotron_h` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=rejected | Config extraction, exact pinned tensor-name closure, GGUF value transforms, and synthetic recurrent-state execution are covered, but no representative real-weight GGUF has yet passed independent full-logit parity and deterministic multi-token stateful ORT generation. Runtime packaging remains deferred until that evidence exists. The mobius graph uses floating Linear modules for this architecture, so no MatMulNBits or BlockQuantizedMatMul target can consume preserved GGUF projection weights. Use keep_quantized=False for explicit float import. |
445-
| `nemotron_h_moe` | — | none (fails before config extraction) | not claimed | config=rejected; tensor_map=rejected; graph=rejected; runtime=rejected; quantized_import=rejected | Direct GGUF conversion is intentionally disabled. GGUF block_count includes a combined attention+MoE MTP auxiliary block, so aliasing it to the 52-layer 'nemotron_h' backbone would build the wrong graph. The Nemotron-H Mamba2 path also lacks passing full-logit/generation parity, and common GGUF presets contain Q5_0/Q5_1 expert tensors that cannot be preserved by MatMulNBits. Use llama.cpp/Unsloth to run the GGUF without changing its quantization, or start from the official pinned BF16 Hugging Face checkpoint and quantize the validated ONNX export with Olive only after L4/L5 semantic generation passes. See docs/api/build_from_gguf.md for the pinned recipe and waiver. |
445+
| `nemotron_h_moe` | — | model=`nemotron_h`; tensor=`nemotron_h_moe` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=rejected | Exact mixed attention/Mamba2/dense/MoE scheduling, sigmoid correction-bias routing, shared experts, optional latent projections, and strict GGUF tensor closure are supported. Generic ORT GenAI runtime packaging remains deferred because its released cache schema cannot represent heterogeneous KV, convolution, and recurrent state slots; tracked by onnxruntime/mobius#605. Quantization preservation is unsupported because mixed Mamba2 recurrent parameters must remain dequantized and correction-biased sigmoid experts cannot use the fused MoE ABI. Use keep_quantized=False for explicit float import. |
446446
| `neo-bert` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | NeoBERT uses pre-norm RMSNorm, RoPE, fused QKV, and fused SwiGLU. The existing encoder graphs differ in normalization and projection layout. |
447447
| `nomic-bert` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | NomicBERT uses RoPE and a parallel gated FFN with BERT-style post norms. BertModel uses absolute positions and a non-gated sequential GELU FFN. |
448448
| `nomic-bert-moe` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | NomicBERT-MoE alternates dense and routed-expert FFNs according to moe_every_n_layers. Mobius has no encoder MoE graph with that schedule. |
@@ -604,8 +604,10 @@ deferred pending the heterogeneous-state schema tracked by
604604
[`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605) and
605605
real full-logit plus deterministic stateful-generation evidence.
606606

607-
`nemotron_h_moe` remains rejected because its folded MTP attention+MoE head has
608-
no equivalent package contract.
607+
`nemotron_h_moe` backbone import is supported with exact mixed Mamba2,
608+
attention, dense-MLP, and routed-MoE scheduling. Files with a folded MTP block
609+
still fail before graph construction because no released package contract
610+
represents that auxiliary attention+MoE head.
609611

610612
### Audio/TTS/codec cohort
611613

@@ -1393,163 +1395,42 @@ reported only as graph/import evidence.
13931395
as documented above. It does not establish runtime support for an architecture.
13941396

13951397

1396-
## NVIDIA Nemotron 3.5 Lightning waiver
1397-
1398-
Direct conversion of GGUF architecture `nemotron_h_moe` is intentionally
1399-
disabled. The following evidence is pinned:
1400-
1401-
- GGUF repository:
1402-
`unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF` at
1403-
`f2d3fe3694501008786e81e5f20360cbf715496a`.
1404-
- Official BF16 comparison:
1405-
`nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16` at
1406-
`d468880b6ad3c6e0d21377ce7242adaea4cc884d`.
1407-
- The official backbone has exactly 52 layers: 23 Mamba, 23 MoE, and
1408-
6 attention layers. GGUF block 52 is a separate combined attention+MoE MTP
1409-
auxiliary block, so `block_count=53` cannot be aliased to the backbone.
1410-
1411-
### Quantization findings
1412-
1413-
| GGUF file | Relevant tensor inventory | Direct preservation |
1414-
|---|---|---|
1415-
| `...-Q8_0.gguf` | 32.904B parameters in `Q8_0` | Qtype-compatible, but blocked by architecture and semantic validation |
1416-
| `...-MXFP4_MOE.gguf` | 14.687B `MXFP4`, 12.772B `Q5_1`, 5.445B `Q8_0` | No; the 5-bit expert weights require a quantization-changing float round-trip |
1417-
| `...-UD-Q4_K_M.gguf` | 15.326B `Q5_0`, 12.772B `Q5_1`, 4.806B `Q8_0` | No; the preset name does not describe its actual per-tensor types |
1418-
| `BF16/...-0000*-of-00002.gguf` | 329 tensors in shard 1 and 88 in shard 2 | No; Mobius does not assemble GGUF shards |
1419-
1420-
The GGUF embeds GPT-2/Pixtral BPE metadata with BOS 1 and EOS 11, but declares
1421-
padding ID 999 (`<SPECIAL_999>`). The pinned official tokenizer declares
1422-
`<|im_end|>` (ID 11) as padding. The GGUF also names the BF16 base repository
1423-
without recording its immutable source commit. Both discrepancies must be
1424-
resolved before a self-contained runtime package can be accepted.
1425-
1426-
The guard also reflects missing semantic evidence: Nemotron-H Mamba2 synthetic
1427-
full-logit parity is not passing, and no real-weight ORT or ORT GenAI generation
1428-
has passed. Graph creation, config emission, or session creation is not a
1429-
substitute for generation.
1430-
1431-
### Reproduce the guard with a pinned download
1432-
1433-
The `Q8_0` file is the only practical candidate whose large quantized tensors
1434-
all use a currently repackable type. Download it explicitly so the source does
1435-
not move:
1436-
1437-
```powershell
1438-
$repo = "unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF"
1439-
$revision = "f2d3fe3694501008786e81e5f20360cbf715496a"
1440-
$file = "NVIDIA-Nemotron-3.5-Lightning-30B-A3B-Q8_0.gguf"
1441-
1442-
python -m pip install `
1443-
--index-url https://packagefeedproxy.microsoft.io/pypi/simple `
1444-
huggingface_hub
1445-
hf download $repo $file --revision $revision --local-dir .\nemotron-gguf
1446-
1447-
# Expected: fail-fast NotImplementedError; no ONNX package is emitted.
1448-
python -m mobius build-gguf ".\nemotron-gguf\$file" `
1449-
--ep cpu `
1450-
--external-data safetensors --output .\nemotron-gguf-onnx
1451-
```
1452-
1453-
`mobius build-gguf --runtime ort-genai` is rejected separately. The GGUF CLI
1454-
does not emit `genai_config.json` until a selected architecture's cache and
1455-
tokenizer contracts have passed real ORT GenAI generation.
1456-
1457-
To execute the pinned GGUF without changing its quantization, use current
1458-
llama.cpp instead:
1459-
1460-
```powershell
1461-
.\llama-cli.exe `
1462-
--model ".\nemotron-gguf\$file" `
1463-
--temp 0.6 --top-p 0.95 --min-p 0.01
1464-
```
1465-
1466-
### Option A: official BF16, then Olive
1467-
1468-
Option A is the ONNX route because it preserves authoritative config,
1469-
tokenizer, and weight provenance. It is still a candidate until Nemotron-H
1470-
semantic tests pass, and currently targets direct ONNX Runtime rather than
1471-
ORT GenAI:
1472-
1473-
```powershell
1474-
$repo = "nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16"
1475-
$revision = "d468880b6ad3c6e0d21377ce7242adaea4cc884d"
1476-
1477-
hf download $repo --revision $revision --local-dir .\nemotron-bf16
1478-
python -m mobius build `
1479-
--config .\nemotron-bf16 `
1480-
--dtype bf16 --ep cuda `
1481-
--external-data safetensors --max-shard-size 5GB `
1482-
--output .\nemotron-bf16-onnx
1483-
```
1484-
1485-
After the BF16 package passes full-logit and generation parity, quantize its
1486-
decoder with an initialized Olive environment:
1487-
1488-
```json
1489-
{
1490-
"input_model": {
1491-
"type": "OnnxModel",
1492-
"model_path": "nemotron-bf16-onnx/model.onnx"
1493-
},
1494-
"passes": {
1495-
"int4": {
1496-
"type": "OnnxKQuantQuantization",
1497-
"bits": 4,
1498-
"block_size": 32
1499-
}
1500-
},
1501-
"output_dir": "nemotron-int4-onnx"
1502-
}
1503-
```
1504-
1505-
```powershell
1506-
python -m pip install `
1507-
--index-url https://packagefeedproxy.microsoft.io/pypi/simple `
1508-
olive-ai onnxruntime
1509-
olive run --config .\olive-int4.json
1510-
Copy-Item .\nemotron-bf16\tokenizer* .\nemotron-int4-onnx\
1511-
Copy-Item .\nemotron-bf16\special_tokens_map.json .\nemotron-int4-onnx\
1512-
Copy-Item .\nemotron-bf16\chat_template.jinja .\nemotron-int4-onnx\
1513-
```
1514-
1515-
The candidate can be checked for direct ORT session loading:
1516-
1517-
```python
1518-
import onnxruntime as ort
1519-
1520-
session = ort.InferenceSession(
1521-
r".\nemotron-int4-onnx\model.onnx",
1522-
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
1523-
)
1524-
print(session.get_providers())
1525-
print([(value.name, value.shape, value.type) for value in session.get_inputs()])
1526-
```
1527-
1528-
Session loading is not generation evidence. There is intentionally no ORT
1529-
GenAI generation command for this model at the pinned revisions:
1530-
1531-
- ORT GenAI 0.15.2 does not register model type `nemotron_h`.
1532-
- The generated generic decoder config does not bind the graph's Mamba
1533-
`conv_state` and `recurrent_state` cache inputs.
1534-
- The official `generation_config.json` uses EOS IDs `[2, 11]`, while the
1535-
architecture config alone supplies EOS 2.
1536-
1537-
Do not publish the package unless BF16 full logits match the pinned reference,
1538-
direct-ORT greedy generation is coherent and deterministic through an
1539-
independently validated hybrid-cache loop, the quantized package remains
1540-
non-degenerate, and ORT GenAI model/cache/token support is implemented before
1541-
claiming ORT GenAI compatibility.
1542-
1543-
### Prerequisites for revisiting direct GGUF conversion
1544-
1545-
1. Map the 52-layer schedule exactly and model block 52 as MTP, or explicitly
1546-
exclude it with generation evidence.
1547-
2. Fix Nemotron-H Mamba2 full-logit parity before testing quantized output.
1548-
3. Preserve every large source qtype. For Q5 variants this requires a validated
1549-
5-bit runtime kernel and repacker; dequantize/requantize is not direct
1550-
preservation.
1551-
4. Resolve the GGUF padding-token mismatch and record an immutable upstream
1552-
BF16 source revision.
1553-
5. Pass real-weight prefill, cached decode, deterministic multi-token
1554-
generation, ORT load/inference, and ORT GenAI package generation on each
1555-
claimed EP.
1398+
## NVIDIA Nemotron-H MoE support boundary
1399+
1400+
`nemotron_h_moe` backbone conversion is supported against pinned llama.cpp
1401+
`8d9af256337d1a501250f9bbf4c0859a654bddd6`. Import reconstructs the exact
1402+
per-layer Mamba2/attention/dense/MoE schedule and validates every required
1403+
tensor before graph construction. Routed experts use sigmoid probabilities,
1404+
correction bias only for top-k selection, optional probability normalization,
1405+
and the serialized routed scaling factor. Experts are non-gated ReLU-squared
1406+
MLPs; one shared expert and optional latent down/up projections are represented
1407+
explicitly.
1408+
1409+
The importer accepts only the canonical stacked expert tensors and canonical
1410+
`blk.N.exp_probs_b.bias`. Missing expert tensors, separate or fused variants,
1411+
partial latent projections, unsupported scale/input-scale sidecars, and
1412+
inconsistent metadata or logical shapes fail before graph construction.
1413+
Quantized-source import is available only with `keep_quantized=False`
1414+
(`mobius build-gguf --dequantize`): mixed recurrent roles and the custom
1415+
sigmoid/ReLU-squared expert graph do not have an exact current quantized ABI.
1416+
1417+
Synthetic evidence covers:
1418+
1419+
- full-logit parity with Transformers for dense, routed/shared, and latent-MoE
1420+
schedules, including correction-bias-driven expert selection;
1421+
- float and dequantized Q4 GGUF import, expert-order value checks, ORT execution
1422+
with convolution/recurrent/KV state threading, and package round-trip;
1423+
- strict malformed-family, sidecar, shape, and MTP rejection.
1424+
1425+
The smallest public full-MoE source is still the 30B-A3B model, so no practical
1426+
small real-weight checkpoint exists for CI parity. The pinned public pair is
1427+
`nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16` and
1428+
`unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF`.
1429+
1430+
Those released GGUFs append a combined attention+MoE MTP block to the
1431+
52-layer backbone (23 Mamba2, 23 MoE, 6 attention). Mobius rejects that MTP
1432+
sidecar before graph construction rather than aliasing `block_count=53` to a
1433+
52-layer decoder. ORT GenAI packaging also remains deferred because released
1434+
runtime schemas do not represent the heterogeneous KV, convolution, and
1435+
recurrent state slots; see
1436+
[`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605).

‎docs/cli_reference.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,12 @@ embeddings dequantize because these graphs do not yet implement
389389
quantized fused QKV is also rejected, while float fused QKV is split losslessly.
390390

391391
Sharded GGUF inputs are rejected because a single shard has an incomplete
392-
tensor table. `nemotron_h_moe` is also rejected until its MTP block, Mamba2
393-
parity, mixed expert quantization, tokenizer provenance, and real ORT/ORT GenAI
394-
generation are validated. See
395-
[`build_from_gguf()`](api/build_from_gguf.md#nvidia-nemotron-35-lightning-waiver).
392+
tensor table. MTP-free `nemotron_h_moe` backbones are supported with exact
393+
hybrid scheduling and routed/shared/latent expert semantics; quantized sources
394+
require `--dequantize`. Files with the released combined attention+MoE MTP
395+
sidecar fail before graph construction, and ORT GenAI packaging remains
396+
deferred. See
397+
[`build_from_gguf()`](api/build_from_gguf.md#nvidia-nemotron-h-moe-support-boundary).
396398

397399
Runtime packaging requires a validated embedded `tokenizer.huggingface.json`;
398400
opaque tokenizer pre-types are never reconstructed. Deferred/rejected

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@
7474
"checkpoint with `mobius build` instead."
7575
)
7676

77-
_NEMOTRON_H_MOE_REASON = (
78-
"Direct GGUF conversion is intentionally disabled. GGUF block_count includes a "
79-
"combined attention+MoE MTP auxiliary block, so aliasing it to the 52-layer "
80-
"'nemotron_h' backbone would build the wrong graph. The Nemotron-H Mamba2 path "
81-
"also lacks passing full-logit/generation parity, and common GGUF presets "
82-
"contain Q5_0/Q5_1 expert tensors that cannot be preserved by MatMulNBits. Use "
83-
"llama.cpp/Unsloth to run the GGUF without changing its quantization, or start "
84-
"from the official pinned BF16 Hugging Face checkpoint and quantize the "
85-
"validated ONNX export with Olive only after L4/L5 semantic generation passes. "
86-
"See docs/api/build_from_gguf.md for the pinned recipe and waiver."
87-
)
88-
8977
_MMPROJ_REASON = (
9078
"This is a multimodal projector sidecar, not a language model. Upstream it is a "
9179
"quant-only stub whose runtime lives outside libllama. Pass it to "
@@ -1093,6 +1081,38 @@
10931081
quantized_import=Support.REJECTED,
10941082
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING + " " + _NO_QUANTIZED_PROJECTION_REASON,
10951083
),
1084+
GGUFArchitectureSpec(
1085+
gguf_arch="nemotron_h_moe",
1086+
model_type="nemotron_h",
1087+
tensor_map_recipe=("nemotron_h_moe",),
1088+
config_key_map="nemotron_h",
1089+
config_postprocessor="nemotron_h_moe",
1090+
tensor_processor="mamba",
1091+
required_metadata=(
1092+
"attention.layer_norm_rms_epsilon",
1093+
"ssm.conv_kernel",
1094+
"ssm.group_count",
1095+
"ssm.inner_size",
1096+
"ssm.state_size",
1097+
"ssm.time_step_rank",
1098+
"expert_count",
1099+
"expert_used_count",
1100+
"expert_feed_forward_length",
1101+
"expert_shared_feed_forward_length",
1102+
),
1103+
runtime=Support.DEFERRED,
1104+
quantized_import=Support.REJECTED,
1105+
reason=(
1106+
"Exact mixed attention/Mamba2/dense/MoE scheduling, sigmoid correction-bias "
1107+
"routing, shared experts, optional latent projections, and strict GGUF tensor "
1108+
"closure are supported. Generic ORT GenAI runtime packaging remains deferred "
1109+
"because its released cache schema cannot represent heterogeneous KV, "
1110+
"convolution, and recurrent state slots; tracked by onnxruntime/mobius#605. "
1111+
"Quantization preservation is unsupported because mixed Mamba2 recurrent "
1112+
"parameters must remain dequantized and correction-biased sigmoid experts "
1113+
"cannot use the fused MoE ABI. Use keep_quantized=False for explicit float import."
1114+
),
1115+
),
10961116
GGUFArchitectureSpec(
10971117
gguf_arch="granitehybrid",
10981118
model_type="granitemoehybrid",
@@ -1746,15 +1766,6 @@
17461766
runtime=Support.DEFERRED,
17471767
reason=_RWKV_GRAPH_REASONS["rwkv7"],
17481768
),
1749-
GGUFArchitectureSpec(
1750-
gguf_arch="nemotron_h_moe",
1751-
config=Support.REJECTED,
1752-
tensor_map=Support.REJECTED,
1753-
graph=Support.REJECTED,
1754-
runtime=Support.REJECTED,
1755-
quantized_import=Support.REJECTED,
1756-
reason=_NEMOTRON_H_MOE_REASON,
1757-
),
17581769
GGUFArchitectureSpec(
17591770
gguf_arch=MMPROJ_ARCHITECTURE,
17601771
config=Support.REJECTED,

0 commit comments

Comments
 (0)