Skip to content

Report GGUF quantization fidelity truthfully - #668

Merged
justinchuby merged 3 commits into
mainfrom
justinchuby-report-gguf-quantization-fidelity
Aug 27, 2026
Merged

justinchuby merged 3 commits into
mainfrom
justinchuby-report-gguf-quantization-fidelity

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • classify mapped GGUF tensors before payload conversion using the authoritative qtype registry
  • allow lossy quantized-to-quantized normalization with one deterministic warning and a typed quantization_report.json
  • separate source fidelity, target storage, explicit float tensors, and runtime compute capability across text, Gemma4 multimodal, and MTP packages
  • keep unknown qtypes, unsupported targets, and unclassified mapped tensors fail-closed
  • document that MatMulNBits fallback compute does not change packed initializer storage

Validation

  • python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q -k "not phi4mm and not apply_weights_unknown" --tb=short — 8,362 passed, 56 skipped, 12 deselected
  • focused GGUF policy suite — 811 passed
  • lintrunner f --output oneline --all-files
  • python scripts/generate_gguf_support_docs.py --check
  • independent code review — no significant findings

The pinned multi-gigabyte motivating artifact was not downloaded; coverage uses synthetic mixed-qtype GGUF fixtures and the pinned integration-test metadata.

Classify each mapped GGUF tensor before conversion, allow explicitly reported lossy normalization, and persist a typed package-level quantization report that separates source fidelity, target storage, and runtime compute capability. Keep unknown routes fail-closed and aggregate warnings across text, multimodal, and MTP package components.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 27, 2026 02:26
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing ee521b0 → b4f9338

Model Sub-model Changes Status

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing ee521b0 → b4f9338

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 324 KB 324 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 265 265 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 127 127 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 450 450 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes GGUF import semantics to report quantization fidelity explicitly: quantized target storage remains the default where supported, while lossy normalization (dequantize → requantize) is permitted with a single deterministic warning and a persistent, typed quantization_report.json saved alongside the package.

Changes:

  • Add GGUFQuantizationReport (typed report + JSON round-trip) and plumb it through GGUF builders (text, Gemma4 VLM, and MTP sidecar), including a single aggregated warning for lossy conversions.
  • Update GGUF quantization routing to classify tensors before payload conversion using the qtype registry, and allow controlled lossy normalization to the supported affine target (fail-closed remains for unknown/unclassifiable qtypes and unsupported targets).
  • Update tests and docs to reflect the new “quantized target storage” default and to assert storage-vs-compute separation (e.g., MatMulNBits inline fallback does not change packed initializer storage).

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/gguf_test.py Updates CLI flag parsing test docstring to match new semantics.
tests/gguf_dense_cohort_integration_test.py Switches from fail-closed to warning+report assertions for real artifacts.
src/mobius/models/talkie_test.py Extends GGUF test stub with reader_tensors() for preflight classification.
src/mobius/models/gguf_embeddings_test.py Extends GGUF test stub with reader_tensors() for preflight classification.
src/mobius/integrations/gguf/_repacker_test.py Strengthens lossiness assertions (non-zero error) for repack tests.
src/mobius/integrations/gguf/_quantization_report.py New typed quantization fidelity report (create/combine/warn/write/read/validate).
src/mobius/integrations/gguf/_quantization_report_test.py New unit tests for determinism, round-trip, fail-closed validation, and combine().
src/mobius/integrations/gguf/_quant_registry.py Tightens/clarifies target support for lossy requantization routes (affine (4,32) only).
src/mobius/integrations/gguf/_quant_registry_test.py Adds coverage for unsupported targets and explicit lossy declarations.
src/mobius/integrations/gguf/_mtp.py Adds preflight hook and attaches quantization report to MTP sidecar packages.
src/mobius/integrations/gguf/_mtp_test.py Updates expectations: lossiness is reported (not rejected) for dedicated-head scenarios.
src/mobius/integrations/gguf/_mmproj.py Generates and attaches quantization report for Gemma4 multimodal packages.
src/mobius/integrations/gguf/_mmproj_test.py Asserts report persistence and updated fail-closed messaging for source-float tensors.
src/mobius/integrations/gguf/_kimi_k3_test.py Updates Kimi K3 behavior to warning+report for lossy MLA reshapes.
src/mobius/integrations/gguf/_docs.py Updates rendered GGUF docs to explain storage vs compute + reporting.
src/mobius/integrations/gguf/_builder.py Adds _preflight_quantization_report() and plumbs report/warnings through GGUF build flow (including MTP combine).
src/mobius/integrations/gguf/_builder_test.py Adds K-quant fixtures and updates many tests from rejection to report+warning assertions.
src/mobius/integrations/gguf/init.py Exposes report types in the public GGUF integration API.
src/mobius/functions/matmul_nbits_test.py Verifies inline fallback keeps packed UINT8 initializer storage intact.
src/mobius/_model_package.py Persists quantization_report.json on save/load and reserves the filename.
src/mobius/main.py Updates CLI messaging and --dequantize help text to match reporting semantics.
docs/model-catalog.md Updates GGUF description to match new default/report behavior.
docs/getting-started.md Adds explicit guidance on fidelity/reporting and storage-vs-compute separation.
docs/design/gguf-support-proposal.md Updates design doc to reflect persistent fidelity reporting.
docs/cli_reference.md Updates CLI reference for GGUF quantized-target mode and reporting semantics.
docs/api/build_from_gguf.md Updates API docs to explain fidelity/reporting and storage-vs-compute separation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mobius/_model_package.py Resolved
justinchuby and others added 2 commits August 26, 2026 19:38
Match the repository lint policy by raising TypeError for malformed JSON field types while retaining ValueError for invalid values and inconsistent fidelity summaries.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Align preflight and loading with actual float graph targets, classify Tencent Q1_0 layouts using their exact storage geometry, and record every mapped tensor. Merge Gemma4 mmproj dispositions into package reports and reject stale report files during report-less saves.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 99b3ba15-953f-4f2b-8238-7b3581075947
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby enabled auto-merge (squash) August 27, 2026 05:06
@justinchuby
justinchuby merged commit 20e00b0 into main Aug 27, 2026
23 of 26 checks passed
@justinchuby
justinchuby deleted the justinchuby-report-gguf-quantization-fidelity branch August 27, 2026 05:08
justinchuby added a commit that referenced this pull request Aug 27, 2026
Bind every pinned graph and runtime package to its post-#668 quantization_report.json identity. Validate report save/load equality, qualify lossy Q4_K_M-derived INT4 target storage separately from source fidelity, and retain exact Q8/full-state runtime evidence.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: da8e7ec7-2747-41aa-99eb-05a1c5227ce2
Signed-off-by: Justin Chu <[email protected]>
justinchuby added a commit that referenced this pull request Aug 27, 2026
## Summary

Follow-up to merged #659 and rebased onto current `main` (`cc3647ea`).

- generate `testdata/evidence/gguf_quantization_capabilities.json` for
all 25 stored qtypes and every projection, affine-only, output,
embedding, expert-major, and non-MatMul route
- separate parse/dequantization capability, packed target storage,
source fidelity, operator ABI, compute capability, and real runtime
evidence
- retain Q4_K/Q6_K as supported lossy affine INT4 target-storage routes
while reporting `source_fidelity=false`; dequantize/requantize is never
labeled preserved
- retain qtype-level runtime support only for the exact Q8_0
projection/output/embedding CPU route
- keep all IQ/MXFP4 `pkg.nxrt::BlockQuantizedMatMul/v1` execution
deferred; byte ABI compatibility is not execution evidence
- strictly parse runtime import routes as duplicate-free JSON and
require top-level `preserve_quantization` to be exactly boolean `true`
- persist and hash-verify `quantization_report.json` in every evidenced
graph/runtime package

## Pinned artifacts

Selected total: **1,763,532,768 bytes** (1.64 GiB), below the 16 GiB
policy.

| Artifact | Bytes | SHA-256 | Result |
|---|---:|---|---|
|
`Qwen/Qwen2.5-0.5B-Instruct-GGUF@9217f5db79a29953eb74d5343926648285ec7e67/qwen2.5-0.5b-instruct-q8_0.gguf`
| 675,710,816 |
`ca59ca7f13d0e15a8cfa77bd17e65d24f6844b554a7b6c12e07a5f89ff76844e` |
Q8_0 source-faithful packed target; full logits, prefill + 20 decode
steps, replay, rollback, reorder, deterministic generation; ORT 1.29.0
CPU and ORT GenAI 0.15.2 passed |
|
`unsloth/SmolLM2-135M-Instruct-GGUF@9e6855bc4be717fca1ef21360a1db4b29d5c559a/SmolLM2-135M-Instruct-Q4_K_M.gguf`
| 105,454,144 |
`ed5fa30c487b282ec156c29062f1222e5c20875a944ac98289dbd242e947f747` |
lossy INT4 affine block-32 target storage succeeds with
`source_fidelity=false`; explicit float import passed same-artifact
full-logit prefill/decode and deterministic generation; runtime support
remains deferred |
|
`neopolita/smollm-135m-gguf@22cca988936eafe92908e7558907c3964e10bba7/ggml-model-f16.gguf`
| 270,885,504 |
`ec8c775c16944a7e4b5251f97b3f848500dcc3e701b0d492ce9055cea42138a2` |
float package/runtime evidence retained and regenerated post-#668 |
|
`LiquidAI/LFM2-350M-GGUF@8fdc9d526b7ed346b19257551b05816c7912ecc2/LFM2-350M-F16.gguf`
| 711,482,304 |
`379ffdcbf08147c0313f6f1ce7ff558a2bc935eda633f4b46c52347032419c42` |
heterogeneous convolution/KV state package/runtime evidence retained and
regenerated post-#668 |

## Post-#668 package identities

| Route | Graph SHA-256 | Runtime package SHA-256 |
|---|---|---|
| SmolLM F16 / ONNX runtime |
`4b608b099fb17471f342c925c20173f297abd0f8456c9e96a11b1d044272d1ad` |
`57038e28e83a2b4251e334b6098f59b4344c7e526746e29d9fa42eeaebfcbddc` |
| SmolLM F16 / ORT GenAI | same graph |
`15d0218a4b326648d514a98c4f073251c674312b1faa83bec9022cc91daa0a53` |
| Qwen2.5 Q8_0 / ORT GenAI |
`240e5e374803c94efdb17eee39c09b0d3e9aed10b6d8b4e1c92e39918ea2155e` |
`5029bbfcdd8d1ae1d2b0ed9587cc288a68cb38bb7f92b9e10f9bf64a436b1762` |
| LFM2 F16 / ORT GenAI |
`27e4ebb4c0c8b6c01ee57fa7825f34c5ddadc8ca5dc0c75d989e4507d4dcdfdb` |
`ef3816d4f93c7061fd4653248629f0439d6ad1c623bdd0f27d31fe0349cb3505` |

Every graph and runtime identity includes validated
`quantization_report.json`; tests assert exact report save/load
equality.

## Validation

- 394 focused capability/registry/report/repacker/evidence/doc tests
passed
- 8,488 broad serial tests passed, 62 skipped, 12 deselected, 1 subtest
passed
- all 3 pinned real runtime-evidence routes passed together with zero
process exit
- pinned Q4_K_M lossy-target + explicit-float qualification passed
- initialized pinned Ruff/format linters passed
- strict changed-source mypy passed
- final GPT-5.6 Sol medium independent review: no findings
- all 17 prior lint review threads replied to and resolved

## Limitations

- Native IQ/MXFP4 execution remains deferred pending pinned
real-artifact full-logit and deterministic native-runtime proof.
- ORT GenAI is optional downstream evidence and pinned here to 0.15.2;
direct ORT evidence is pinned to 1.29.0 CPU.

Do not merge directly.

---------

Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: da8e7ec7-2747-41aa-99eb-05a1c5227ce2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants