Repository navigation
[torchlib] Support divisor_override in avg_pool2d and avg_pool3d - #3070
Open
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Open
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Conversation
divisor_override was ignored, so the exported model divided by the window size instead. Compute the window sums with LpPool (p=1) over the positive and negative parts and divide by divisor_override, which also handles padding and ceil_mode.
This branch has not been deployed
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.
aten_avg_pool2dandaten_avg_pool3daccepteddivisor_overridebut ignored it (there was a TODO for it), so the exported model silently divided by the window size instead:AveragePoolcan't take a custom divisor, so withdivisor_overridethe window sums are computed withLpPool(p=1)on the positive and negative parts (sum = LpPool(relu(x)) - LpPool(relu(-x))) and divided bydivisor_override. Padding contributes zeros andLpPoolsupportsceil_mode, so this matches PyTorch, which divides the sum of the in-bounds values bydivisor_overrideregardless ofcount_include_pad. Withoutdivisor_overridethe graph is unchanged.Testing:
divisor_overridexfails fornn.functional.avg_pool2d/avg_pool3d, and excludeddivisor_overridesamples from the avg_pool3dceil_modexfail, since they no longer go throughAveragePool.pytest tests/function_libs/torch_lib/ops_test.py -k avg_poolpasses with onnxruntime 1.23.0 (the version in noxfile.py): 5 passed, 33 subtests passed, 7 xfailed.LpPool-based sums withF.avg_pool2d(..., divisor_override=3)over 96 combinations of input size, kernel, stride, padding,ceil_modeandcount_include_padon onnxruntime 1.23.0 and 1.30.0. All match. Exportingnn.AvgPool2d(..., divisor_override=...)and 3d/unbatched cases withtorch.onnx.export(dynamo=True)also matches eager.