Repository navigation
avg_pool2d: accept an unbatched [C, H, W] input - #147
Merged
Merged
Conversation
PyTorch accepts avg_pool2d on an input without a batch dim, and nn.AvgPool1d on [C, L] reaches avg_pool2d as [C, 1, L]. The lowering read x.type.shape[3] and raised IndexError on these rank-3 inputs. It now adds a batch dim of 1 before the pool and removes it after.
gokulkrishna98
self-requested a review
November 9, 2026 21:54
gokulkrishna98
approved these changes
Nov 11, 2026
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.
Summary
PyTorch accepts
avg_pool2don an input without a batch dim, andnn.AvgPool1don[C, L]reachesavg_pool2das[C, 1, L].replace_avg_pool2dassumed a rank-4 input and raisedIndexErroratx.type.shape[3].For a rank-3 input, the lowering now adds a batch dim of 1 before the composite and removes it after. Rank-4 inputs lower as before.
git merge-treeagainst the heads of #80, #81 and #123, which also change this function, reports no conflict. UnbatchedAvgPool3d,MaxPool1d/MaxPool2dandAdaptiveAvgPool1d/AdaptiveAvgPool2dstill fail to convert, on main and with this change; this PR covers only #144.Testing
test_avg_pool2d_unbatchedrunsnn.AvgPool1d(2)andnn.AvgPool1d(3, stride=2, padding=1)on[4, 8]andnn.AvgPool2d(2)on[3, 8, 8], static and with a dynamic channel dim, against PyTorch. All six raiseIndexErrorbefore the fix and pass after it.Fixes #144