Cortex-M: lower a max pool whose ceil_mode changes nothing - #22233
Draft
rascani wants to merge 1 commit into
Draft
Cortex-M: lower a max pool whose ceil_mode changes nothing#22233rascani wants to merge 1 commit into
rascani wants to merge 1 commit into
Conversation
The kernel floors, so CortexMMaxPool2DCheck refused every ceil_mode pool. Most do not need the ceiling: it adds a row or column only when the last window would hang off the end of the padded input, and all three of SqueezeNet's pools divide exactly. The checker and the lowering now compare the two sizes and accept when they agree, taking SqueezeNet from 29 lowered nodes to 32 with nothing but the concatenations and two layout no-ops left. Pools whose ceiling genuinely differs still decline. The test is one-sided on purpose. Aten also drops a last window that starts beyond the input, which can bring the ceiling back down to the floor; those configurations keep falling back rather than earn a second rule. Refusing was worse than staying in fp32. The checker annotates the node before tagging it, so the surrounding dq/q fold away and the fallback runs portable max_pool2d_with_indices over an int8 channels_last tensor -- whose index type is templated on the input dtype, so aten refuses a plane above 127 elements. Pools that lower no longer reach it. Both gates now read the pool's arguments through one helper. The lowering used to index node.args by hand and compare the results against tuple literals, which a list never matches, so no pool that spells out its dilation could lower -- and naming ceil_mode is what puts dilation in the graph. Nor did it handle stride's schema default of [], meaning "same as the kernel". Authored with Claude Code.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22233
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
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
The kernel floors, so CortexMMaxPool2DCheck refused every ceil_mode pool. Most do not need the ceiling: it adds a row or column only when the last window would hang off the end of the padded input, and all three of SqueezeNet's pools divide exactly. The checker and the lowering now compare the two sizes and accept when they agree, taking SqueezeNet from 29 lowered nodes to 32 with nothing but the concatenations and two layout no-ops left. Pools whose ceiling genuinely differs still decline.
The test is one-sided on purpose. Aten also drops a last window that starts beyond the input, which can bring the ceiling back down to the floor; those configurations keep falling back rather than earn a second rule.
Refusing was worse than staying in fp32. The checker annotates the node before tagging it, so the surrounding dq/q fold away and the fallback runs portable max_pool2d_with_indices over an int8 channels_last tensor -- whose index type is templated on the input dtype, so aten refuses a plane above 127 elements. Pools that lower no longer reach it.
Both gates now read the pool's arguments through one helper. The lowering used to index node.args by hand and compare the results against tuple literals, which a list never matches, so no pool that spells out its dilation could lower -- and naming ceil_mode is what puts dilation in the graph. Nor did it handle stride's schema default of [], meaning "same as the kernel".
Authored with Claude Code.