Skip to content

Commit c8fb589

Browse files
justinchubyCopilot
andauthored
Preserve original GGUF weights with opset 29 (#827)
Keep packed and typed GGUF tensors in their original files as ONNX external data. Use DequantizePacked, exact layout operations, selected-row embedding decoding, and GroupedMatMul for ordinary gated experts. Remove lossy affine rounding/requantization; unsupported legacy routes and floating reparameterizations now fail explicitly. Consolidate GGUF docs and add a per-format/per-architecture survey. Current scope is flat, little-endian packages. Runtime kernels, selected-bank fusion, multi-component packaging, and remaining architecture contracts are documented gaps. DequantizePacked-29 addresses the primary representation request in onnx/onnx#8359. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent d8a303f commit c8fb589

31 files changed

Lines changed: 5746 additions & 3373 deletions

‎.github/workflows/main.yml‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Install released dependencies
4848
run: |
4949
# Test-only dependencies allow source collection before marker selection.
50-
pip install -e . pytest httpx "gguf>=0.10.0" "jsonschema>=4.0" \
50+
pip install -e . pytest pytest-cov httpx "gguf>=0.10.0" "jsonschema>=4.0" \
5151
onnx==1.19.0 onnxruntime==1.31.1 onnxruntime-easy==0.1.2 \
5252
onnxscript==0.7.2 onnx_ir==1.1.0
5353
- name: Test with released ONNX 1.19 schemas
@@ -57,11 +57,36 @@ jobs:
5757
- name: Install pinned opset-29 schemas
5858
run: |
5959
pip install --no-cache-dir --no-deps --force-reinstall \
60-
https://github.com/onnx/onnx/archive/82721c0908fa965dd84e674c006147791313f3e1.tar.gz
61-
python -c "import onnx; assert onnx.defs.has('GroupedMatMul', 29)"
60+
https://github.com/onnx/onnx/archive/c7609c4ad5445c548e0e18a465666dd0f4084215.tar.gz
61+
python -c "import onnx; assert onnx.defs.has('GroupedMatMul', 29); assert onnx.defs.has('DequantizePacked', 29)"
6262
- name: Test with pinned opset-29 schemas
6363
run: |
64-
python -m pytest src/mobius tests/ep_optimization_test.py -m opset29 -q -rs
64+
python -m pytest src/mobius tests/ep_optimization_test.py -m opset29 -q -rs \
65+
--cov=src --cov-report=xml:coverage-opset29.xml --cov-branch \
66+
--junitxml=junit-opset29.xml
67+
- name: Upload opset-29 coverage to Codecov
68+
if: always()
69+
uses: codecov/codecov-action@v7
70+
with:
71+
token: ${{ secrets.CODECOV_TOKEN }}
72+
files: coverage-opset29.xml
73+
flags: unittests
74+
- name: Save opset-29 coverage and test reports
75+
if: always()
76+
uses: actions/upload-artifact@v7
77+
with:
78+
name: opset29-coverage
79+
path: |
80+
coverage-opset29.xml
81+
junit-opset29.xml
82+
- name: Upload opset-29 test results to Codecov
83+
if: ${{ !cancelled() }}
84+
uses: codecov/codecov-action@v7
85+
with:
86+
token: ${{ secrets.CODECOV_TOKEN }}
87+
files: junit-opset29.xml
88+
flags: unittests
89+
report_type: test_results
6590

6691
detect-affected:
6792
name: Detect affected models

‎docs/api/build_from_gguf.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ package.save("output")
2222
Quantized target storage is requested by default. Use
2323
`keep_quantized=False` when the output must use float storage.
2424

25+
## Original GGUF external data (opset 29)
26+
27+
Enable `MOBIUS_EXPERIMENTAL_OPSET29=1`, retain `keep_quantized=True`, and select
28+
`execution_provider="onnx-standard"`. Save **beside the original GGUF file(s)**:
29+
Construction does not require installed opset-29 schemas. Checking and reference
30+
execution require ONNX with `DequantizePacked-29` and `GroupedMatMul-29` schemas.
31+
32+
```bash
33+
MOBIUS_EXPERIMENTAL_OPSET29=1 mobius build-gguf weights/model.gguf \
34+
--ep onnx-standard --output weights
35+
```
36+
37+
The experimental path keeps original typed tensors and packed payloads as ONNX
38+
external-data ranges in those files. It emits `DequantizePacked` and standard
39+
layout operations, with `GroupedMatMul` for ordinary routed experts. It does not
40+
repack, requantize, copy payloads into a new blob, or materialize a dense vocabulary
41+
at export time. Row-aligned packed embeddings decode only requested rows.
42+
43+
Current packaging is one flat model with its original, little-endian GGUF shards,
44+
`gguf-packed.json`, and reports. Multi-component/mmproj/MTP packages, transcoded
45+
safetensors output, and new weight sharding are rejected. Treat source files as
46+
immutable; load/save verifies source digests and original external bindings.
47+
The flag does **not** add runtime kernels. See the
48+
[opset-29 survey](../gguf-capability-catalog.md#lossless-opset-29-survey).
49+
50+
Former lossy affine/requantization routes now raise actionable errors when the
51+
flag is off. Exact legacy routes remain available. Explicit `--dequantize` is a
52+
separate float-storage choice, not source-byte preservation.
53+
2554
## Signature
2655

2756
```python
@@ -48,7 +77,7 @@ def build_from_gguf(
4877
| `gguf_path` | GGUF model path. |
4978
| `task` | Optional task override; otherwise selected from GGUF architecture metadata. |
5079
| `dtype` | Target float dtype, such as `"f32"`, `"f16"`, or `"bf16"`. |
51-
| `keep_quantized` | Request quantized target storage where the selected graph and qtype route support it. This does not promise source-byte or numerical fidelity. |
80+
| `keep_quantized` | Request supported exact legacy packed storage; with the opset-29 flag, retain original GGUF external payloads. Unsupported routes fail rather than requantize. |
5281
| `execution_provider` | Target EP for EP-aware graph optimization; `"default"` emits portable ONNX. |
5382
| `mmproj` | Companion projector GGUF for a registry-evidenced multimodal route. |
5483
| `image_token_id` | Processor-owned image placeholder ID for an `mmproj` package. |

0 commit comments

Comments
 (0)