Repository navigation
Add native PyTorch INT3 weight quantization - #2715
Closed
Ti-Tai Wang (titaiwangms) wants to merge 1 commit into
Closed
Ti-Tai Wang (titaiwangms) wants to merge 1 commit into
Ti-Tai Wang (titaiwangms) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation is internally consistent and includes focused coverage for packing, persistence, mixed precision, and unsupported export boundaries.
Review effort: Balanced
Findings: None
What changed in this PR
Adds native INT3 checkpoint quantization for PyTorch RTN, KQuant, and GPTQ while explicitly blocking unsupported export paths.
Changes:
- Implements row-local, LSB-first INT3 packing, unpacking, placeholders, and reload support.
- Enables INT3 in native passes, mixed precision, and AutoClip.
- Adds export guards, documentation, and comprehensive tests.
| File | Description |
|---|---|
olive/constants.py |
Adds the 3-bit precision enum. |
olive/common/quant/utils.py |
Implements INT3 packing and unpacking. |
olive/common/quant/hf_utils.py |
Supports INT3 checkpoint loading and export validation. |
olive/common/hf/quant.py |
Rejects INT3 ONNX export. |
olive/passes/pytorch/quant_utils.py |
Exposes INT3 to native quantization passes. |
olive/passes/pytorch/kquant.py |
Documents KQuant INT3 support. |
olive/passes/pytorch/autoclip.py |
Allows INT3 clipping simulation. |
olive/passes/pytorch/autogptq.py |
Rejects INT3 in AutoGPTQ. |
olive/passes/pytorch/gptqmodel.py |
Rejects INT3 in GptqModel. |
olive/passes/pytorch/autoawq.py |
Rejects INT3 in AutoAWQ. |
olive/passes/onnx/model_builder.py |
Blocks native INT3 model building. |
olive/passes/onnx/mobius_model_builder.py |
Blocks native INT3 Mobius builds. |
olive/passes/onnx/inc_quantization.py |
Rejects INT3 in INC weight-only quantization. |
test/common/quant/test_utils.py |
Tests packed INT3 byte layout and round trips. |
test/common/quant/test_tensor.py |
Tests INT3 dequantization and tensor operations. |
test/common/quant/test_hf_utils.py |
Tests placeholders and export validation. |
test/common/hf/test_quant.py |
Tests INT3 export rejection. |
test/passes/pytorch/test_int3.py |
Covers passes, checkpoints, MoE, and mixed precision. |
test/passes/pytorch/test_kquant.py |
Extends KQuant parameter tests to INT3. |
test/passes/onnx/test_model_builder.py |
Tests ModelBuilder rejection. |
test/passes/onnx/test_mobius_model_builder.py |
Tests Mobius rejection. |
docs/source/features/quantization.md |
Documents format, usage, and limitations. |
skills/olive/references/quantization-onboarding.md |
Updates quantization onboarding guidance. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
Superseded by #2716, which uses a branch pushed directly to microsoft/Olive instead of the fork. |
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.
Describe your changes
Add native PyTorch INT3 weight quantization for Olive's RTN, KQuant, and GPTQ passes, including explicit mixed-precision overrides and checkpoint save/reload.
This is Torch checkpoint support, not an INT3 ONNX export or accelerated-kernel implementation. No real-model accuracy or performance qualification is claimed. Quantized fused-MoE forward execution currently requires eager experts.
Validation
Validated on an isolated branch based on upstream main at
ba856b69ec21a3080319c7affce62dc1546b94e2.Result: 712 passed.
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 timeout 180 python -m pytest test/common/quant/test_forward_parity.py test/passes/onnx/test_model_builder.py test/passes/pytorch/test_kquant.py -k 'not real_hf and (forward_parity or onnx_export_parity or export_rejected or rejects_int3 or find_qparams or saved_test_model_path or config_only_test_dir or single_file_fallback or multi_file_output or prechecks_extra_options or structured_config or cpu_embedding or active_loader)' -q --disable-warnings --maxfail=3Result: 42 passed, 43 deselected.
After removing a redundant test import:
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 timeout 120 python -m pytest test/passes/onnx/test_model_builder.py -k 'rejects_int3' -q --disable-warningsResult: 3 passed, 24 deselected.
Result: All commands exited successfully; Ruff checked/formatted all 21 changed Python files.
Result: Failed only with 21
RUFF/CPY001copyright-notice findings. This rule also flags existing unchanged files with the repository's copyright headers. No unrelated headers or lint configuration were changed; the same finding also affects the new test file.The full test suite, hardware-specific kernels, and real-model download-dependent tests were not run.
Checklist before requesting a review
lintrunner -aRelease notes: Native PyTorch RTN, KQuant, and GPTQ now support INT3 weight checkpoints and explicit mixed-precision INT3 overrides. INT3 uses tightly packed storage and supports save/reload and eager dequantized execution; ONNX export and accelerated INT3 inference are not yet supported.
(Optional) Issue link
Related runtime design discussion: microsoft/onnxruntime#32657. This change does not depend on or implement that runtime proposal.