Fix float16 QuantizeLinear rounding on CPU - #32452
Open
kadyrbekovhamit-cyber wants to merge 1 commit into
Open
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.
🟡 Changes recommended
The test does not yet verify exact ties-to-even behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes CPU float16 QuantizeLinear to round fractional values before integer conversion.
Changes:
- Applies nearest rounding in the scalar float16 quantization path.
- Adds a regression test for positive and negative fractional values.
File summaries
| File | Description |
|---|---|
onnxruntime/core/util/qmath.h |
Corrects float16 quantization rounding. |
onnxruntime/test/providers/cpu/tensor/quantize_linear_test.cc |
Adds regression coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: kadyrbekovhamit-cyber <288885044+kadyrbekovhamit-cyber@users.noreply.github.com>
kadyrbekovhamit-cyber
force-pushed
the
codex/fix-float16-quantizelinear-rounding
branch
from
September 5, 2026 17:37
144e0b8 to
70dd31b
Compare
Author
|
@microsoft-github-policy-service agree |
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
Fixes the still-reproducible numerical issue reported in #18576.
The CPU
MLFloat16overload ofParQuantizeLinearStdconvertedx / scaledirectly withstatic_cast<int32_t>, which truncates toward zero. ONNXQuantizeLinearrequires round-to-nearest with ties to even.This change applies
std::nearbyintbefore the integer conversion, matching the ONNX contract and the nearby blocked float16 paths in the same file.Minimal reproduction
For opset 19:
NumPy nearest-even and ONNX
ReferenceEvaluatorboth return[1, -1]. A 4,096-value float16 differential check found 2,041 mismatches, all toward zero and by at most one quantization unit. The float32 control path matched the oracle.Changes
std::nearbyint;Testing
onnxruntime==1.29.0andonnx==1.22.0;ReferenceEvaluator;OpTestercase is included for CI.This is a numerical-correctness fix, not a security change.