@@ -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/
7179The GGUF builder maps GGUF architecture names (e.g. ` llama ` , ` qwen2 ` ,
7280` gemma ` ) to the same model classes used by ` build() ` . Most decoder-only
7381LLM 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 " . \n emotron-int4-onnx\m odel. 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.
0 commit comments