Repository navigation
[Fix][Relax][PyTorch] Emit squeeze for unbatched AdaptiveAvgPool1d/2d/3d - #21129
Open
GoyalIshaan wants to merge 1 commit into
Open
GoyalIshaan wants to merge 1 commit into
GoyalIshaan wants to merge 1 commit into
Conversation
Wrap the post-pool relax.op.squeeze(result, axis=[0]) in
self.block_builder.emit(...) across _adaptive_avg_pool{1,2,3}d and
_adaptive_avg_pool{1,2,3}d_module so unbatched AdaptiveAvgPool returns a
typed relax.Var instead of an un-emitted relax.Call.
Closes apache#20943
Note: The same un-emitted squeeze exists in _avg_pool*_impl and
_max_pool*_impl; I'll send a follow-up PR.
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.
Fixes #20943.
When translating an unbatched
AdaptiveAvgPool1d/2d/3dinput, the PyTorch Relax frontend adds a temporary batch dimension, emits the pooling op, and then removes the batch dimension withrelax.op.squeeze(result, axis=[0])without callingself.block_builder.emit(...). Returning that un-emittedrelax.Callinstead of a typedrelax.Varcauses downstream ops such as_binary_opto miss theVar/TensorTypecheck and fall through tointrinsic_op, failing on expressions likepool(x) * 2.0(TypeError: Please convert 2.0 with const first) ortorch.maximum(pool(x), pool(y))(must be Tensor, not Call).This PR wraps
relax.op.squeeze(result, axis=[0])inself.block_builder.emit(...)across all six_adaptive_avg_pool{1,2,3}dand_adaptive_avg_pool{1,2,3}d_moduletranslators so bothfrom_exported_programandfrom_fxalways return a typedrelax.Var, and adds unbatched 1D/2D/3D regression tests (with batched controls) for scalar multiplication and elementwise max.Note: The same un-emitted
squeezeexists in_avg_pool*_impland_max_pool*_impl; I'll send a follow-up PR.Tests:
mainfor unbatched 2D/3D (from_exported_program) and unbatched 1D/2D/3D (from_fx), with batched controls passing.pytest tests/python/relax/test_frontend_from_exported_program.py tests/python/relax/test_frontend_from_fx.py -k "adaptive_avgpool" -v(15 passed, including numerical LLVM CPU verification against PyTorch eager).pre-commit run --files python/tvm/relax/frontend/torch/base_fx_graph_translator.py python/tvm/relax/frontend/torch/fx_translator.py tests/python/relax/test_frontend_from_exported_program.py tests/python/relax/test_frontend_from_fx.py(all hooks passed).