Handle empty CPU LpNormalization inputs - #32020
Merged
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 07:47
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 07:48
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the CPU implementation of the LpNormalization operator to correctly handle empty inputs (zero total elements due to a zero-extent dimension), avoiding invalid normalization math (e.g., division by zero) and adding a regression test to ensure the behavior remains correct.
Changes:
- Added an early return in
LpNorm<T>::Computewheninput_shape.Size() == 0to safely bypass normalization work for empty tensors. - Added a CPU-only unit test covering a zero-extent normalization axis for
p = 1andp = 2, for bothfloatanddouble.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/nn/lp_norm.cc | Early-return for empty tensors to prevent invalid normalization computations and unnecessary work. |
| onnxruntime/test/providers/cpu/nn/lp_norm_op_test.cc | Adds a regression test ensuring LpNormalization succeeds with a zero-extent axis (empty tensor) on CPU. |
💡 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
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 adds handling and tests for cases where the
LpNormalizationoperator receives input tensors with zero elements along the normalization axis. The main changes include an early return in the implementation to avoid unnecessary computation and a new test to verify correct behavior for zero-extent axes.LpNormalization operator improvements:
LpNorm<T>::Computeto immediately return success when the input tensor has zero elements, preventing unnecessary computation for empty inputs.Testing enhancements:
LpNormalizationZeroExtentAxistest, which checks that the operator correctly handles input tensors with a zero-extent axis for bothp=1andp=2, and for bothfloatanddoubletypes.