Validate MLAS blockwise QDQ index ranges - #32007
Merged
Akshay Sonawane (apsonawane) merged 3 commits intoAug 13, 2026
Merged
Conversation
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 05:26
View session
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 05:30
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds safety validation around MLAS blockwise QDQ quantization/transposition to ensure internal int32 index arithmetic cannot overflow, and wires those checks into both the MLAS kernels and the QDQ transformer path.
Changes:
- Introduces
MlasQDQBlockwiseShapeIsValidto validate blockwise QDQ shapes against the MLAS int32 index domain. - Enforces the validation in MLAS blockwise quantize/transpose routines and returns an error in the QDQ transformer when the shape is invalid.
- Adds a unit test to verify invalid shapes are rejected.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/mlas/inc/mlas_q4.h | Adds the shared shape validation helper used to guard int32 index arithmetic. |
| onnxruntime/core/mlas/lib/q4_dq.cpp | Enforces the new validation at entry points for blockwise QDQ quantize/transpose. |
| onnxruntime/core/optimizer/qdq_transformer/selectors_actions/qdq_actions.cc | Adds an early shape validity check in the MatMulNBits weight transpose path. |
| onnxruntime/test/mlas/unittest/test_blockq4.cpp | Adds a unit test ensuring out-of-domain shapes are rejected (including exception expectations). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/mlas-blockwise-index-overflow
branch
August 13, 2026 17:54
This was referenced Sep 10, 2026
Open
This was referenced Sep 14, 2026
Open
Closed
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.
This pull request introduces important safety checks to the quantization code in ONNX Runtime to ensure that blockwise quantization shapes do not exceed the valid
int32_tindex range, preventing potential overflows and runtime errors. The main changes include the addition of a validation function, integration of this check into quantization and transpose routines, and new unit tests to verify the behavior.Shape validation and enforcement:
MlasQDQBlockwiseShapeIsValidfunction inmlas_q4.hto validate that quantization shape parameters fit within theint32_tindex domain, guarding against arithmetic overflows.MlasQDQQuantizeBlockwiseandMlasQDQTransposeBlockwiseQuantizedinq4_dq.cppto enforce this validation usingORT_ENFORCE, throwing an exception if the shape is invalid. [1] [2]TransposeDQWeightsForMatMulNBitsto return an error if the shape is invalid.Testing and code hygiene:
RejectsShapesOutsideInt32IndexDomainintest_blockq4.cppto verify that invalid shapes are correctly rejected and exceptions are thrown as expected.<cstdint>and<limits>inmlas_q4.hto support the new validation logic.