Repository navigation
feat(onnx): opt-in INT8 quantized sidecar in the ONNX export - #498
Merged
NandhaKishorM merged 1 commit intoSep 27, 2026
Merged
Conversation
Add --quantize to scripts/export_onnx.py: dynamic per-channel INT8 weight-only quantization of the MatMul layers, written as a sidecar (<output>.int8.onnx) next to the fp32 export so A/B stays possible. Measured on the English checkpoint (CPU, 20 ticket states x choice/noul/score): 1.6 GB -> 581 MB, p50 ~340 ms -> ~250 ms, zero decision changes (max probability drift 0.09); per-tensor scales flipped 3 of 20 states, so per-channel is what ships. Weight-free suite on a synthetic MatMul graph, run in a new CI lane that installs onnx.
Owner
|
Thanks @aashish254, merged. The per-channel vs per-tensor numbers are exactly the kind of measurement that makes this easy to accept. It ships in 0.3.21. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in
--quantizeflag toscripts/export_onnx.py. After the fp32 export it writes adynamic per-channel INT8 weight-only quantized sidecar next to it:
laya.onnxalso produceslaya.int8.onnx.ONNXAgentloads it unchanged — the graph keeps the fp32 export's input/outputnames, so it is just
ONNXAgent(ckpt, onnx_path="laya.int8.onnx").Nothing changes unless the flag is passed, and the fp32 model is untouched, so A/B stays possible.
Measured on the English checkpoint (CPU, M-series, 20 realistic support-ticket states x
choice/noul/score through
ONNXAgent.system_one)Dynamic quantization needs no calibration dataset. Per-channel scales are load-bearing:
per-tensor int8 on the same graph flipped 3 of 20 states (noul booleans crossing 0.5 and a score
level) with drift up to 0.29 — parity-unusable; per-channel flipped none at the same file size and
speed. That comparison is why the exporter hard-codes
per_channel=True, with the numbers in acode comment.
Two implementation notes from the real graph
value_infoshapes that disagree with the quantizer'sown shape-inference re-derivation (
ShapeInferenceError: (1028) vs (256)on the real export).The declarations are informational, so
quantize_modeldrops them before quantizing.CUDAExecutionProvider. Documented in the flag help and the reference page.Tests + CI
tests/test_onnx_quantize.py(14 checks, standalone assert-style PASS/FAIL + exit code) isweight-free: it exercises
quantize_modelon a tiny hand-built MatMul graph — INT8 initializerpresent, per-channel scales asserted, I/O names preserved, outputs close to fp32 through ORT,
weight bytes shrink, fp32 sidecar untouched, sidecar naming, and the
--quantizeCLI surfacethrough
--help. No checkpoint download.onnx export (quantization, weight-free)inci.yml. The existingtestjob'scomment says onnx-dependent tests belong "in a lane that installs onnx" rather than
skip-guarding into a trivial pass, so this adds that lane instead of touching the shared
install lists.
docs/reference/agent.md: a short "Quantized export" section with the command and the measuredtable.
Gates run locally:
ruff(repo's select set) clean on the changed files,python -m compileallclean,
zensical build --strict --cleanpasses.laya[onnx]already shipsonnx+onnxruntime, so no dependency changes.