Repository navigation
Normalize negative axes in blocked quantization helpers - #34181
Open
Afloat (Afloat16) wants to merge 2 commits into
Open
Afloat (Afloat16) wants to merge 2 commits into
Afloat (Afloat16) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the negative-axis handling fix.
No open issues 🎉
What changed in this PR
Fixes negative-axis handling in two lower-level blocked quantization helpers so equivalent positive and negative axes produce identical results.
Changes:
- Normalizes negative axes after indexing the selected dimension, preserving existing out-of-range validation.
- Adds regression tests for parameter and initializer equality, read-only noncontiguous inputs, existing constraints, and native CPU dequantization followed by MatMul.
No actionable findings were identified.
| File | Description |
|---|---|
onnxruntime/test/python/quantization/test_blocked_negative_axes.py |
Adds negative-axis regression tests and native CPU integration coverage. |
onnxruntime/python/tools/quantization/quant_utils.py |
Normalizes negative axes in both blocked quantization helpers. |
Review effort: Balanced
mirounga
self-requested a review
November 13, 2026 16:10
| import unittest | ||
|
|
||
| import numpy as np | ||
| import onnx |
Remove the mixed import forms flagged by CodeQL without changing the test behavior.
This branch has not been deployed
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.
Description
Both
compute_scale_zp_blockedand the blocked path ofquantize_onnx_initializeraccept an axis but use its original value when enumerating the other dimensions. For a rank-2 weight and axis -1 or -2, that enumeration includes both dimensions, so valid input fails while reshaping the weights.Normalize a negative axis immediately after indexing the selected dimension. This preserves the existing out-of-range-axis validation and makes the remaining layout calculations use the same axis as NumPy. Scale computation, rounding, clipping, per-channel quantization and the rank-2 restriction are unchanged. The main QDQ quantizer already normalizes its axis; this fixes the two lower-level entry points.
Validation
test_quant_util.py/test_qdq_block_size.py: 24 methods passed, 193 subtests passed.git diff --checkpassed.Native validation: https://github.com/Afloat16/onnxruntime/actions/runs/43308384299
The runtime was built with the repository's official CPU Release build.py/CMake path from commit 8dea119, whose C++ sources match base a8246c0. This run installs that built wheel, verifies the unchanged native-source baseline, and overlays the complete quantization package from this exact patch with byte-for-byte checks and a SHA-256 manifest. It uses ordinary native imports. This is targeted Linux CPU validation; it does not claim GPU or the full C++ test suite.
Motivation and Context
Negative axes are an existing supported way to identify tensor dimensions. Equivalent positive and negative values should produce identical blocked quantization parameters and initializers, including when these helpers are called directly.