Skip to content

Validate NCHWc convolution layouts - #32557

Open
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
fix/nchwc-conv-layout-validation
Open

Validate NCHWc convolution layouts#32557
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
fix/nchwc-conv-layout-validation

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request strengthens input validation for the NCHWc convolution operator and adds comprehensive unit tests to ensure invalid configurations are properly rejected. The main changes are improved error checking in the operator implementation and a new test suite covering various invalid input scenarios.

Input validation improvements:

  • Enhanced validation in NchwcConv::Compute to check for valid group count, input/filter tensor ranks, positive channel sizes, channel size overflow, and correct blocked layout alignment. Also checks that the bias tensor (if present) is 1D and matches the number of output channels.
  • Added #include <limits> to support overflow checks in the validation logic.

Testing:

  • Introduced a new test file, nchwc_ops_test.cc, with unit tests that verify the operator correctly rejects various invalid input and filter shapes, group values, and bias tensor configurations.

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.

🟡 Changes recommended

Newly added rank, channel, and overflow validation paths lack test coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Strengthens NCHWc convolution validation and adds failure-path tests.

Changes:

  • Validates ranks, groups, channels, blocked layouts, overflow, and bias shape.
  • Adds tests for invalid groups, layouts, and biases.
File summaries
File Description
onnxruntime/contrib_ops/cpu/nchwc_ops.cc Adds runtime validation.
onnxruntime/test/contrib_ops/nchwc_ops_test.cc Tests selected invalid configurations.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +164 to +165
ORT_RETURN_IF_NOT(X_shape.NumDimensions() == 4 && W_shape.NumDimensions() == 4,
"NCHWc Conv input and filter must be rank 4.");
Comment on lines +169 to +172
ORT_RETURN_IF_NOT(input_channels_per_group > 0 && output_channels > 0,
"NCHWc Conv input and output channels must be greater than 0.");
ORT_RETURN_IF_NOT(input_channels_per_group <= std::numeric_limits<int64_t>::max() / conv_attrs_.group,
"NCHWc Conv input channels per group is too large.");
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.

2 participants