Skip to content

Handle empty initializer axis scaling - #32138

Merged
Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
fix/initializer-scale-zero-dimension
Aug 20, 2026
Merged

Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
fix/initializer-scale-zero-dimension

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request improves the robustness and correctness of the scale_by_axis method in the Initializer class and adds new tests to ensure proper handling of edge cases, especially with empty tensors and invalid scaler inputs.

Improvements to scale_by_axis implementation:

  • Updated the calculation of block_size and num_blocks in the scale_by_axis method of the Initializer class to use more precise and consistent dimension handling, addressing potential bugs with axis indexing. (onnxruntime/core/optimizer/initializer.cc)

Testing enhancements:

  • Added a new test case (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)
  • Included the span_utils.h header in the test file to support the new test cases using spans. (onnxruntime/test/optimizer/initializer_test.cc)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@apsonawane
Akshay Sonawane (apsonawane) merged commit 597e4a6 into main Aug 20, 2026
88 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/initializer-scale-zero-dimension branch August 20, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants