Skip to content

Fix/pool negative pad validation - #32076

Open
Akshay Sonawane (apsonawane) wants to merge 2 commits into
mainfrom
fix/pool-negative-pad-validation
Open

Fix/pool negative pad validation#32076
Akshay Sonawane (apsonawane) wants to merge 2 commits into
mainfrom
fix/pool-negative-pad-validation

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request strengthens validation for padding values in pooling operations to ensure they are non-negative, preventing invalid configurations and potential runtime errors. It also adds unit tests to verify that negative padding values are correctly rejected, both at the ONNX operator level and in the underlying MLAS pooling implementation.

Validation improvements:

  • Added explicit checks in pool_attributes.h to enforce that all padding values (pads) are non-negative when auto_pad is not set, raising an error if this condition is violated.
  • Updated pooling.cpp to throw a std::invalid_argument exception if any padding value is negative, providing an additional safeguard at the MLAS pooling layer.

Testing enhancements:

  • Added new unit tests in pool_op_test.cc to verify that negative padding values cause the expected errors, both for the ONNX MaxPool operator and for the MLAS pooling backend.

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

This PR strengthens pooling padding validation across the CPU provider and MLAS to reject negative pad values (when auto_pad is not set), and adds targeted unit tests to ensure invalid configurations fail early with clear errors.

Changes:

  • Add PoolAttributes validation to enforce non-negative pads when auto_pad == NOTSET.
  • Add an MLAS-layer guard that throws std::invalid_argument when any padding value is negative.
  • Add unit tests covering both the ORT MaxPool operator path and the MLAS MlasPool backend.

Reviewed changes

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

File Description
onnxruntime/test/providers/cpu/nn/pool_op_test.cc Adds regression tests ensuring negative pads are rejected at the ORT op level and (when exceptions are enabled) at the MLAS level.
onnxruntime/core/providers/cpu/nn/pool_attributes.h Enforces non-negative pads for explicit padding to prevent invalid pooling configurations from reaching execution.
onnxruntime/core/mlas/lib/pooling.cpp Adds a low-level validation check to reject negative padding values before MLAS pooling proceeds.

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

// Graph::Resolve() and reach kernel construction where our ORT_ENFORCE checks fire.
// Exclude compiling EPs (TRT, QNN) and EPs with their own validation (DML) that produce
// different error messages.
TEST(PoolTest, MaxPool_NegativePad) {
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