Handle empty initializer axis scaling - #32138
Merged
Akshay Sonawane (apsonawane) merged 1 commit intoAug 20, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 17, 2026 21:36
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 17, 2026 21:40
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Initializer::scale_by_axis handling for empty tensors by avoiding division by zero.
Changes:
- Computes block counts directly from tensor dimensions.
- Adds empty-tensor and invalid-scaler tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
onnxruntime/core/optimizer/initializer.cc |
Uses dimension products for scaling layout. |
onnxruntime/test/optimizer/initializer_test.cc |
Tests empty tensors and invalid scalers. |
💡 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 20, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/initializer-scale-zero-dimension
branch
August 20, 2026 17:53
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 improves the robustness and correctness of the
scale_by_axismethod in theInitializerclass and adds new tests to ensure proper handling of edge cases, especially with empty tensors and invalid scaler inputs.Improvements to
scale_by_axisimplementation:block_sizeandnum_blocksin thescale_by_axismethod of theInitializerclass to use more precise and consistent dimension handling, addressing potential bugs with axis indexing. (onnxruntime/core/optimizer/initializer.cc)Testing enhancements:
ScaleByAxisEmptyTensor) to cover scenarios where the target or scaler tensors are empty, ensuring that the method does not throw unexpectedly and returns the correct size. The test also checks for proper exception handling with invalid scaler sizes and data types. (onnxruntime/test/optimizer/initializer_test.cc)span_utils.hheader in the test file to support the new test cases using spans. (onnxruntime/test/optimizer/initializer_test.cc)