Validate LayerNormalization axis bounds - #32555
Open
Akshay Sonawane (apsonawane) wants to merge 1 commit into
Open
Validate LayerNormalization axis bounds#32555Akshay Sonawane (apsonawane) wants to merge 1 commit into
Akshay Sonawane (apsonawane) wants to merge 1 commit into
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
September 10, 2026 22:17
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
September 10, 2026 22:18
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test does not cover the exact axis == rank boundary introduced by the new condition.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds LayerNormalization shape-inference validation for axes at or above the input rank.
Changes:
- Updates both ONNX dependency patches with the bounds check.
- Adds an invalid-axis unit test.
File summaries
| File | Description |
|---|---|
onnxruntime/test/contrib_ops/layer_norm_op_test.cc |
Tests rejection of an oversized axis. |
cmake/vcpkg-ports/onnx/binskim.patch |
Applies validation to the vcpkg ONNX source. |
cmake/patches/onnx/onnx.patch |
Applies validation to the standard ONNX dependency. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+858
to
+867
| TEST(LayerNormTest, LayerNorm_AxisExceedsRank) { | ||
| OpTester test("LayerNormalization", 17); | ||
| test.AddAttribute<int64_t>("axis", 0xFFFFFFFFLL); | ||
| test.AddInput<float>("X", {1, 2}, {1.0f, 2.0f}); | ||
| test.AddInput<float>("Scale", {2}, {1.0f, 1.0f}); | ||
| test.AddOutput<float>("Y", {1, 2}, {0.0f, 0.0f}); | ||
| test.AddOutput<float>("Mean", {1, 1}, {0.0f}); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectFailure, "Unexpected axis value"); | ||
| } |
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 addresses validation and testing improvements for the
LayerNormalizationoperator, specifically handling invalid axis values. The main change ensures that the operator correctly detects and reports an error when theaxisattribute exceeds the input tensor's rank. Additionally, a new unit test is added to verify this behavior.Validation logic update:
onnx/defs/nn/defs.ccto check ifaxisis less than 0 or greater than or equal to the input tensor rank, and to fail shape inference with an appropriate error message if so.Unit testing:
LayerNorm_AxisExceedsRankinonnxruntime/test/contrib_ops/layer_norm_op_test.ccto ensure that providing an out-of-bounds axis value results in a failure with the expected error message.