Skip to content

Validate Conv bias size - #32160

Open
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
msrc/conv-bias-size-fix
Open

Validate Conv bias size#32160
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
msrc/conv-bias-size-fix

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request strengthens input validation for the Conv operator by adding explicit checks for the bias tensor shape and size, and adds a new unit test to verify this behavior. The main changes are as follows:

Input validation improvements:

  • Added a check in Conv<T>::Compute (and the float specialization) to ensure that the bias tensor B, if provided, is a 1D tensor whose size matches the number of output channels (M). If not, an informative error message is returned. [1] [2]

Testing enhancements:

  • Introduced a new test case Conv2D_InvalidBiasSize in conv_op_test.cc to verify that the Conv operator correctly fails when the bias tensor does not have the expected size, ensuring the new validation logic works as intended.

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

Adds CPU Conv bias validation to prevent invalid rank or channel counts.

Changes:

  • Validates that bias is 1-D with one value per output channel.
  • Adds a failure test for incorrect bias size.
  • Rank-validation coverage is still missing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/providers/cpu/nn/conv.cc Adds bias validation to Conv compute paths.
onnxruntime/test/providers/cpu/nn/conv_op_test.cc Tests rejection of incorrect bias size.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

OpTester test("Conv", 22);
test.AddInput<float>("X", {1, 1, 1, 1}, {1.0f});
test.AddInput<float>("W", {4, 1, 1, 1}, std::vector<float>(4, 0.0f));
test.AddInput<float>("B", {1}, {0.0f});
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