Skip to content

Commit 01008cf

Browse files
justinchubyCopilot
andauthored
Guard unsupported Nemotron 3.5 GGUF conversion (#486)
## Summary - Fail fast for `nemotron_h_moe` GGUFs before remote multi-GB downloads (when Hub metadata is available) and again from the local header before graph construction. - Reject split GGUF shards, including text/mmproj paths, rather than emitting incomplete weights. - Reject `mobius build-gguf --runtime ort-genai` before artifacts because that path cannot yet emit a valid cache/tokenizer contract. - Document the pinned Nemotron 3.5 GGUF/BF16 evidence, exact file-selection commands, Option A direct-ORT recipe, acceptance gates, and waiver; refine the quantization skill with reusable direct-GGUF checks. ## Pinned evidence - GGUF: `unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF@f2d3fe3694501008786e81e5f20360cbf715496a` - Official BF16: `nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16@d468880b6ad3c6e0d21377ce7242adaea4cc884d` - Backbone schedule: 23 Mamba + 23 MoE + 6 attention layers; GGUF block 52 is the separate combined attention+MoE MTP block. - `Q8_0` is qtype-compatible, but lacks semantic acceptance. `MXFP4_MOE` contains 12.772B Q5_1 parameters; `UD-Q4_K_M` contains 15.326B Q5_0 + 12.772B Q5_1 parameters, so neither preserves quantization end to end. - GGUF padding ID 999 conflicts with the official `<|im_end|>` padding token (ID 11), and the GGUF records no immutable upstream BF16 commit. ## Validation - Rebased linearly onto repaired main commit `2073725840e007c1fba59ce3cb1f06e4ad9fe75a`; the #484 fixes are inherited, not duplicated. - `86 passed`: GGUF builder/mmproj/CLI plus quantization integration regression suites. - Canonical non-integration suite: `3,933 passed, 58 skipped`. - Live Hub metadata preflight rejected the pinned 35 GB Q8 file before download. - Initialized `lintrunner -a` and `git diff --check` pass; the worktree is clean. - Independent release review found no remaining significant issues. - Refreshed CI passes Lint, all Ubuntu/Windows test jobs, Build, L1 smoke, Architecture Diff, benchmarks, CodeQL, affected-model detection, CLA, and lintrunner. - Self-hosted `Integration (fast)`: `16 passed, 4 skipped, 2 failed`, exclusively the same two DeepSeek parity failures as #484's repaired-main job (`test_deepseek_v2_lite_prefill_logits_match` and `test_deepseek_non_mla_decoder_prefill_logits_match`). This PR changes no DeepSeek code. ## Waivers - No Nemotron GGUF ONNX artifact, ORT load, ORT GenAI load, or generation is claimed: the new guard intentionally prevents unsupported artifacts. Current Nemotron-H synthetic parity is skipped/xfail (expert shape transfer mismatch and Mamba2 recurrence divergence). - Foundry Local and L4/L5 generation are waived until architecture parity, MTP handling, tokenizer provenance, and runtime cache bindings are implemented. - The inherited DeepSeek GPU parity failures are outside this focused PR; fixing them here would mix unrelated model work. Tracks #483. Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 17a1deb commit 01008cf

9 files changed

Lines changed: 650 additions & 7 deletions

File tree

‎.agents/skills/onnx-export-quantization/SKILL.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ output/
9696
└── genai_config.json
9797
```
9898

99+
### Direct GGUF import acceptance
100+
101+
Do not infer a GGUF's quantization from its filename. Presets such as
102+
`Q4_K_M`, `MXFP4_MOE`, and Unsloth Dynamic variants can contain large tensors
103+
in different per-tensor formats (for example Q5_0, Q5_1, Q8_0, and MXFP4).
104+
Before implementing or claiming a direct conversion:
105+
106+
1. Pin the GGUF repository revision, filename, file size, and LFS SHA-256.
107+
2. Inspect the GGUF metadata and complete tensor table (names, logical shapes,
108+
and quantization types) without downloading tensor payloads when range
109+
requests are available.
110+
3. Compare the layer schedule and tensor shapes with a separately pinned
111+
official config and safetensors headers. `block_count` may include auxiliary
112+
MTP/draft blocks rather than decoder backbone layers.
113+
4. Classify every large tensor as byte-preserved native blocks, lossless affine
114+
repacking, or dequantize/requantize. If any large tensor takes the third
115+
path, the conversion does **not** preserve the source quantization.
116+
5. Reject split GGUF shards unless the importer explicitly assembles every
117+
shard. Reading one shard can build a plausible but incomplete model.
118+
6. Compare embedded tokenizer special-token IDs and chat template with the
119+
pinned upstream tokenizer. A self-contained package is invalid when padding,
120+
EOS, or BOS semantics disagree.
121+
7. Require real-weight full-logit parity and deterministic multi-token
122+
generation through both ONNX Runtime and the declared GenAI runtime. Graph,
123+
config, and session creation are not acceptance evidence.
124+
125+
Use Hub GGUF architecture metadata to fail before downloading multi-gigabyte
126+
unsupported files, then repeat the guard from the local GGUF header so local
127+
paths receive the same actionable error.
128+
99129
## Quantization with Olive
100130

101131
### Installation

‎docs/api/build_from_gguf.md‎

Lines changed: 174 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ def build_from_gguf(
1818
task: str | None = None,
1919
dtype: str | None = None,
2020
keep_quantized: bool = False,
21+
execution_provider: str = "default",
22+
mmproj: str | Path | None = None,
23+
static_cache: bool = False,
24+
max_seq_len: int | None = None,
2125
) -> ModelPackage:
2226
```
2327

2428
## Parameters
2529

2630
| Parameter | Type | Default | Description |
2731
|---|---|---|---|
28-
| `gguf_path` | `str \| Path` | (required) | Path to a `.gguf` model file. |
32+
| `gguf_path` | `str \| Path` | (required) | Local `.gguf` path or `owner/repo:filename.gguf` Hub reference. |
2933
| `task` | `str \| None` | `None` | Override the model task (e.g. `"text-generation"`). When `None`, the task is auto-detected from the model type. |
3034
| `dtype` | `str \| None` | `None` | Override model dtype (e.g. `"f16"`). When `None`, defaults to float32. |
31-
| `keep_quantized` | `bool` | `False` | When `True`, preserve quantization for supported GGUF types (Q4_0, Q4_1, Q8_0) by repacking linear-layer weights into MatMulNBits format. Unsupported types are dequantized to float. |
35+
| `keep_quantized` | `bool` | `False` | Preserve supported affine blocks as `MatMulNBits` and supported IQ/MXFP4 blocks in the onnx-genai native format. A mixed preset may still require dequantization/requantization. |
36+
| `execution_provider` | `str` | `"default"` | Target EP for EP-aware graph optimization. |
37+
| `mmproj` | `str \| Path \| None` | `None` | Optional companion multimodal-projector GGUF. |
38+
| `static_cache` | `bool` | `False` | Build a fixed-width KV cache when the architecture supports it. |
39+
| `max_seq_len` | `int \| None` | `None` | Static-cache sequence limit. |
3240

3341
## Returns
3442

@@ -71,3 +79,167 @@ mobius build-gguf llama-3.2-1b-q4_0.gguf --output output/llama/
7179
The GGUF builder maps GGUF architecture names (e.g. `llama`, `qwen2`,
7280
`gemma`) to the same model classes used by `build()`. Most decoder-only
7381
LLM architectures are supported.
82+
83+
Sharded GGUF files are rejected. A single shard has only part of the tensor
84+
table, and treating it as a complete checkpoint would create a corrupt model.
85+
86+
## NVIDIA Nemotron 3.5 Lightning waiver
87+
88+
Direct conversion of GGUF architecture `nemotron_h_moe` is intentionally
89+
disabled. The following evidence is pinned:
90+
91+
- GGUF repository:
92+
`unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF` at
93+
`f2d3fe3694501008786e81e5f20360cbf715496a`.
94+
- Official BF16 comparison:
95+
`nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16` at
96+
`d468880b6ad3c6e0d21377ce7242adaea4cc884d`.
97+
- The official backbone has exactly 52 layers: 23 Mamba, 23 MoE, and
98+
6 attention layers. GGUF block 52 is a separate combined attention+MoE MTP
99+
auxiliary block, so `block_count=53` cannot be aliased to the backbone.
100+
101+
### Quantization findings
102+
103+
| GGUF file | Relevant tensor inventory | Direct preservation |
104+
|---|---|---|
105+
| `...-Q8_0.gguf` | 32.904B parameters in `Q8_0` | Qtype-compatible, but blocked by architecture and semantic validation |
106+
| `...-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 |
107+
| `...-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 |
108+
| `BF16/...-0000*-of-00002.gguf` | 329 tensors in shard 1 and 88 in shard 2 | No; Mobius does not assemble GGUF shards |
109+
110+
The GGUF embeds GPT-2/Pixtral BPE metadata with BOS 1 and EOS 11, but declares
111+
padding ID 999 (`<SPECIAL_999>`). The pinned official tokenizer declares
112+
`<|im_end|>` (ID 11) as padding. The GGUF also names the BF16 base repository
113+
without recording its immutable source commit. Both discrepancies must be
114+
resolved before a self-contained runtime package can be accepted.
115+
116+
The guard also reflects missing semantic evidence: Nemotron-H Mamba2 synthetic
117+
full-logit parity is not passing, and no real-weight ORT or ORT GenAI generation
118+
has passed. Graph creation, config emission, or session creation is not a
119+
substitute for generation.
120+
121+
### Reproduce the guard with a pinned download
122+
123+
The `Q8_0` file is the only practical candidate whose large quantized tensors
124+
all use a currently repackable type. Download it explicitly so the source does
125+
not move:
126+
127+
```powershell
128+
$repo = "unsloth/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF"
129+
$revision = "f2d3fe3694501008786e81e5f20360cbf715496a"
130+
$file = "NVIDIA-Nemotron-3.5-Lightning-30B-A3B-Q8_0.gguf"
131+
132+
python -m pip install `
133+
--index-url https://packagefeedproxy.microsoft.io/pypi/simple `
134+
huggingface_hub
135+
hf download $repo $file --revision $revision --local-dir .\nemotron-gguf
136+
137+
# Expected: fail-fast NotImplementedError; no ONNX package is emitted.
138+
python -m mobius build-gguf ".\nemotron-gguf\$file" `
139+
--keep-quantized --ep cpu `
140+
--external-data safetensors --output .\nemotron-gguf-onnx
141+
```
142+
143+
`mobius build-gguf --runtime ort-genai` is rejected separately. The GGUF CLI
144+
does not emit `genai_config.json` until a selected architecture's cache and
145+
tokenizer contracts have passed real ORT GenAI generation.
146+
147+
To execute the pinned GGUF without changing its quantization, use current
148+
llama.cpp instead:
149+
150+
```powershell
151+
.\llama-cli.exe `
152+
--model ".\nemotron-gguf\$file" `
153+
--temp 0.6 --top-p 0.95 --min-p 0.01
154+
```
155+
156+
### Option A: official BF16, then Olive
157+
158+
Option A is the ONNX route because it preserves authoritative config,
159+
tokenizer, and weight provenance. It is still a candidate until Nemotron-H
160+
semantic tests pass, and currently targets direct ONNX Runtime rather than
161+
ORT GenAI:
162+
163+
```powershell
164+
$repo = "nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16"
165+
$revision = "d468880b6ad3c6e0d21377ce7242adaea4cc884d"
166+
167+
hf download $repo --revision $revision --local-dir .\nemotron-bf16
168+
python -m mobius build `
169+
--config .\nemotron-bf16 `
170+
--dtype bf16 --ep cuda `
171+
--external-data safetensors --max-shard-size 5GB `
172+
.\nemotron-bf16-onnx
173+
```
174+
175+
After the BF16 package passes full-logit and generation parity, quantize its
176+
decoder with an initialized Olive environment:
177+
178+
```json
179+
{
180+
"input_model": {
181+
"type": "OnnxModel",
182+
"model_path": "nemotron-bf16-onnx/model.onnx"
183+
},
184+
"passes": {
185+
"int4": {
186+
"type": "OnnxKQuantQuantization",
187+
"bits": 4,
188+
"block_size": 32
189+
}
190+
},
191+
"output_dir": "nemotron-int4-onnx"
192+
}
193+
```
194+
195+
```powershell
196+
python -m pip install `
197+
--index-url https://packagefeedproxy.microsoft.io/pypi/simple `
198+
olive-ai onnxruntime
199+
olive run --config .\olive-int4.json
200+
Copy-Item .\nemotron-bf16\tokenizer* .\nemotron-int4-onnx\
201+
Copy-Item .\nemotron-bf16\special_tokens_map.json .\nemotron-int4-onnx\
202+
Copy-Item .\nemotron-bf16\chat_template.jinja .\nemotron-int4-onnx\
203+
```
204+
205+
The candidate can be checked for direct ORT session loading:
206+
207+
```python
208+
import onnxruntime as ort
209+
210+
session = ort.InferenceSession(
211+
r".\nemotron-int4-onnx\model.onnx",
212+
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
213+
)
214+
print(session.get_providers())
215+
print([(value.name, value.shape, value.type) for value in session.get_inputs()])
216+
```
217+
218+
Session loading is not generation evidence. There is intentionally no ORT
219+
GenAI generation command for this model at the pinned revisions:
220+
221+
- ORT GenAI 0.15.2 does not register model type `nemotron_h`.
222+
- The generated generic decoder config does not bind the graph's Mamba
223+
`conv_state` and `recurrent_state` cache inputs.
224+
- The official `generation_config.json` uses EOS IDs `[2, 11]`, while the
225+
architecture config alone supplies EOS 2.
226+
227+
Do not publish the package unless BF16 full logits match the pinned reference,
228+
direct-ORT greedy generation is coherent and deterministic through an
229+
independently validated hybrid-cache loop, the quantized package remains
230+
non-degenerate, and ORT GenAI model/cache/token support is implemented before
231+
claiming ORT GenAI compatibility.
232+
233+
### Prerequisites for revisiting direct GGUF conversion
234+
235+
1. Map the 52-layer schedule exactly and model block 52 as MTP, or explicitly
236+
exclude it with generation evidence.
237+
2. Fix Nemotron-H Mamba2 full-logit parity before testing quantized output.
238+
3. Preserve every large source qtype. For Q5 variants this requires a validated
239+
5-bit runtime kernel and repacker; dequantize/requantize is not direct
240+
preservation.
241+
4. Resolve the GGUF padding-token mismatch and record an immutable upstream
242+
BF16 source revision.
243+
5. Pass real-weight prefill, cached decode, deterministic multi-token
244+
generation, ORT load/inference, and ORT GenAI package generation on each
245+
claimed EP.

‎docs/cli_reference.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,13 @@ mobius build-gguf GGUF_PATH [options]
311311
| Option | Description |
312312
|--------|-------------|
313313
| `--output DIR`, `-o DIR` | Output directory. Default: `<gguf_stem>_onnx/`. |
314-
| `--keep-quantized` | Preserve GGUF quantization as `MatMulNBits` (Q4_0/Q4_1/Q8_0). |
314+
| `--keep-quantized` | Preserve supported affine blocks as `MatMulNBits` and supported native IQ/MXFP4 blocks. Mixed presets may still require requantization. |
315315
| `--dtype DTYPE` | Target dtype for model weights: `f16`, `bf16`, `f32`. |
316316
| `--external-data FORMAT` | External data format: `onnx` (default) or `safetensors`. |
317+
| `--ep EP` | Target execution provider for EP-aware optimization. |
318+
| `--runtime RUNTIME` | `onnx-genai` emits supported runtime metadata. `ort-genai` is rejected until GGUF cache/tokenizer generation coverage exists. |
319+
| `--static-cache` | Build a fixed-width cache where supported. |
320+
| `--max-seq-len N` | Set the fixed cache length; requires `--static-cache`. |
317321

318322
### Examples
319323

@@ -328,6 +332,12 @@ mobius build-gguf model.gguf --output output/ --keep-quantized
328332
mobius build-gguf model.gguf --output output/ --dtype f16
329333
```
330334

335+
Sharded GGUF inputs are rejected because a single shard has an incomplete
336+
tensor table. `nemotron_h_moe` is also rejected until its MTP block, Mamba2
337+
parity, mixed expert quantization, tokenizer provenance, and real ORT/ORT GenAI
338+
generation are validated. See
339+
[`build_from_gguf()`](api/build_from_gguf.md#nvidia-nemotron-35-lightning-waiver).
340+
331341
---
332342

333343
## `mobius list`

‎src/mobius/__main__.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ def _cmd_build_gguf(args: argparse.Namespace) -> None:
504504
)
505505
raise SystemExit(1)
506506

507+
if getattr(args, "runtime", None) == "ort-genai":
508+
raise SystemExit(
509+
"Error: mobius build-gguf does not yet support --runtime ort-genai. "
510+
"The command cannot emit a valid genai_config.json until the selected "
511+
"GGUF architecture's cache and tokenizer contracts have passed real "
512+
"ORT GenAI generation. Use --runtime onnx-genai where supported, or "
513+
"omit --runtime and run the ONNX model directly."
514+
)
515+
507516
mmproj_path = getattr(args, "mmproj", None)
508517

509518
if args.keep_quantized:
@@ -862,8 +871,8 @@ def main(argv: list[str] | None = None) -> None:
862871
"Generate runtime-specific config files after building. "
863872
"'onnx-genai' writes inference_metadata.yaml plus a tokenizer.json "
864873
"reconstructed from the GGUF's embedded tokenizer metadata; "
865-
"'ort-genai' writes genai_config.json + copies tokenizer files. "
866-
"Either way the quantized model runs directly in the target runtime."
874+
"'ort-genai' is currently rejected until GGUF cache/tokenizer "
875+
"contracts have runtime generation coverage."
867876
),
868877
)
869878
gguf_parser.add_argument(

0 commit comments

Comments
 (0)