You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b6d166a
Browse filesBrowse the repository at this point in the historyBrowse files
Reuse compatible GGUF weights as ONNX external data (#573)
## Summary
Stacked on #571 (`justinchuby-gguf-registry-foundation`). Adds an
explicit opt-in path that publishes ONNX beside the original GGUF
without writing a second full copy of byte-compatible weights.
```bash
mobius build-gguf output/model.gguf --output output/ --reuse-gguf-weights
```
```python
package = build_from_gguf("output/model.gguf", reuse_gguf_weights=True)
package.save("output/")
```
## Storage and transform behavior
- Unchanged F32/F16 tensors and consumer-compatible native IQ4_NL,
IQ4_XS, IQ3_S, IQ3_XXS, IQ2_XXS, IQ2_XS, IQ2_S, IQ1_S, IQ1_M, and MXFP4
tensors point at exact GGUF `location + offset + length` ranges.
- Float transpose, norm offset, Llama Q/K row permutation, and Mamba
`A_log`/shape transforms keep the source bytes and run as ONNX graph
operations. Opaque packed UINT8 is never generically transposed.
- Repacked, requantized, dequantized, synthesized, or otherwise
materialized large tensors are written exactly once to
`model.onnx.data`.
- Disabling constant folding preserves the on-disk reuse but transformed
weights may still allocate runtime buffers and add startup/execution
cost.
## Persistence and verification
A persistent same-directory advisory lock serializes writers, recovery,
and shared verification. Mixed saving stages and fsyncs the sidecar,
model, and manifest, validates the complete staged package, then
installs it through an atomically published durable transaction journal
with hard-linked rollback backups. The journal records
replacing/committed state so crashes cannot produce mixed rollback or
leak full backup copies. Interrupted reruns recover before
save/verification; failed reruns restore prior artifacts; obsolete
sidecars are removed transactionally.
Recovery deletes only staged and backup paths owned by a structurally
and path-validated journal; generated-looking filenames are never
treated as proof of ownership. Lock, journal, staged, backup, model,
manifest, and sidecar paths reject symlinks and non-regular artifacts.
Lock acquisition validates directory-entry/opened inode identity;
journal files are created through exclusive no-follow temporary files
and atomic replacement.
`gguf-reuse.json` pins source location, size, SHA-256, source
tensor/qtype/range, initializer dtype/length, source/final shapes,
transform name, and transform parameters. Verification enumerates every
ONNX external initializer: each must be either an exact manifest-pinned
GGUF range or a non-overlapping range in the one permitted sidecar.
Sidecar ranges must exactly equal the byte count implied by concrete
non-negative shape and supported dtype. Verification rejects
unmanifested/unsafe locations, wrong dtype/qtype/shape/ranges, mixed
reused/converted claims, and mutated transform
wiring/constants/permutations.
## Scope and runtime requirements
This PR supports one flat text-model package. The real little-endian
GGUF must already be in the output directory. It rejects nested/non-flat
packaging, mmproj/MTP packages, symlinks, unsafe hardlinks,
generated-name collisions, changed source identity, safetensors output,
and sidecar sharding rather than copying or linking the GGUF.
Use direct ONNX Runtime with graph optimization disabled:
```python
options = ort.SessionOptions()
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
```
`--reuse-gguf-weights --runtime ort-genai` is rejected because the
current `genai_config.json` schema has no supported setting that
requires disabled constant folding.
## Validation
- 214 affected GGUF builder, ModelPackage, runtime-package, CLI, API,
and option-parity tests pass.
- Synthetic mixed GGUF/sidecar execution matches the ordinary converted
package numerically on ORT CPU with optimizations disabled.
- Tests cover writer/verifier ownership, committed and interrupted crash
recovery, atomic journal publication, unsafe links/artifacts, source
collisions, preservation of generated-looking source/user files,
complete external enumeration, exact sidecar nbytes, qtype/dtype/range
and transform mutations, source identity, hardlink capability,
stale-sidecar removal, and exception rollback.
- `lintrunner f --output oneline --all-files` and `lintrunner -a` pass
locally.
## Waiver
No multi-GB public GGUF was downloaded. Real-weight validation is
deferred to avoid a large network/storage dependency; synthetic files
use the real GGUF writer/reader, exact offsets, native block routes,
mixed persistence, reload, and ORT execution.
---------
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: e99f9fcb-697e-4853-b34c-b854c3995535
|`reuse_gguf_weights`|`bool`|`False`| Reuse byte-compatible F32/F16 and native IQ/MXFP4 tensor ranges from the original GGUF instead of copying them into ONNX external data. |
0 commit comments