Support divisor_override for avg_pool2d and avg_pool3d (fixes #2745)#2748
Open
ArsalanShakil wants to merge 1 commit into
Open
Support divisor_override for avg_pool2d and avg_pool3d (fixes #2745)#2748ArsalanShakil wants to merge 1 commit into
ArsalanShakil wants to merge 1 commit into
Conversation
) The PyTorch frontend previously raised a ValueError whenever avg_pool2d or avg_pool3d was given a divisor_override. Implement support by averaging over the full kernel (counting padding as zeros, so the divisor is the constant kernel volume) and rescaling the result by num_kernel_elements / divisor_override, which reproduces PyTorch's window_sum / divisor_override semantics. Add converter tests covering 2D/3D across the TorchScript, TorchExport and ExecuTorch frontends.
Collaborator
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
Fixes #2745.
The PyTorch frontend previously rejected
avg_pool2dandavg_pool3dwheneverdivisor_overridewas provided, raising:This PR adds support for a static, positive
divisor_override.Approach
MIL's
avg_poolhas nodivisor_overrideoption, so the value is reconstructed:exclude_padding_from_average=False), which makes the divisor a known constant equal to the kernel volume. The window sum is thereforeavg_pool_result * num_kernel_elements.num_kernel_elements / divisor_override, reproducing PyTorch'swindow_sum / divisor_overridesemantics.A non-positive
divisor_overrideraises a clearValueError.Tests
Added
test_avg_pool2d_divisor_overrideandtest_avg_pool3d_divisor_override, parametrized over kernel/stride/padding combinations and divisor values, across the TorchScript, TorchExport, and ExecuTorch frontends and the fp16/fp32 backends. All new and existingTestAvgPoolcases pass and numerically match PyTorch.