Fix incorrect pad indices in AveragePool count_include_pad computation#27375
Merged
titaiwangms merged 3 commits intomicrosoft:mainfrom Feb 19, 2026
Merged
Conversation
Regression test for microsoft#26708 AveragePool with count_include_pad=1 and asymmetric pads (only bottom/right) was using incorrect pad index for hend, producing wrong results.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect padding-index usage in the CPU AveragePool functor implementations so count_include_pad=1 correctly includes asymmetric tail padding in the divisor calculation (aligning results with ONNX).
Changes:
- Correct pad tail index usage for
hendinAveragePool2DTask. - Correct pad tail index usage for
hend/wendinAveragePool3DTask. - Add a 2D regression test covering asymmetric pads with
count_include_pad=1.
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/pool_functors.h |
Fixes incorrect pad tail indices used when clamping window ends for count_include_pad divisor computation in 2D/3D AveragePool tasks. |
onnxruntime/test/providers/cpu/nn/pool_op_test.cc |
Adds a regression test validating correct output for 2D asymmetric pads with count_include_pad=1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…sues for count_include_pad
Contributor
|
/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
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.
Description
Fixes #26708
AveragePool2DTaskandAveragePool3DTaskinpool_functors.hused incorrectpad indices when computing
hend(andwendin 3D) for thecount_include_paddivisor calculation.
ONNX pads format for 2D is
[h_begin, w_begin, h_end, w_end].The code was using
pads[1](w_begin) instead ofpads[2](h_end) to clamphend,causing the padding region to be excluded from the divisor when
count_include_pad=1with asymmetric pads (e.g. bottom/right only).The same issue existed in
AveragePool3DTaskwhere pads format is[h_begin, w_begin, d_begin, h_end, w_end, d_end]:hendusedpads[1]instead ofpads[3]wendusedpads[3]instead ofpads[4]Example
Input
[[1,1],[1,1]]withpads=[0,0,1,1],kernel_shape=[2,2],count_include_pad=1:[[1.0, 0.5], [1.0, 0.5]][[1.0, 0.5], [0.5, 0.25]]Verified against ONNX ReferenceEvaluator.
Changes
pool_functors.h: Fix pad indices inAveragePool2DTaskandAveragePool3DTaskpool_op_test.cc: Add regression testAveragePool_CountIncludePad_AsymmetricPadsMotivation and Context
When using
AveragePoolwithcount_include_pad=1and asymmetric padding(e.g. only bottom and right), the average was computed with the wrong divisor,
producing results inconsistent with the ONNX spec.