-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ops): Fix inconsistent padding calculation in PyTorch backend ops #20774
fix(ops): Fix inconsistent padding calculation in PyTorch backend ops #20774
Conversation
Was able to still reproduce the error, the PyTorch backend had inconsistent behavior between static shape inference and dynamic execution for pooling operations, particularly with 'same' padding and non-unit strides, figured that the root cause was by incorrect padding calculation logic that didn't properly handle asymmetric padding cases. Key changes: - Rewrote _compute_padding_length() to handle stride-based padding - Fixed padding calculation to properly support asymmetric padding cases - Standardize channels_first/channels_last conversion in pooling ops - Cleaned up padding application in _apply_same_padding() - Added proper handling of data_format throughout pooling pipeline This fixes the issue where MaxPooling2D with 'same' padding would produce different shapes between compute_output_shape() and actual execution (e.g. (1,5,2,2) vs (1,5,2,1)). Rebased on top of Sachin's September 2024 PR to incorporate latest keras:master changes.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #20774 +/- ##
=======================================
Coverage 81.99% 81.99%
=======================================
Files 555 555
Lines 51805 51808 +3
Branches 8012 8013 +1
=======================================
+ Hits 42475 42482 +7
+ Misses 7378 7376 -2
+ Partials 1952 1950 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix.
Was able to still reproduce the error, the PyTorch backend had inconsistent behavior between static shape inference and dynamic execution for pooling operations, particularly with 'same' padding and non-unit strides, figured that the root cause was by incorrect padding calculation logic that didn't properly handle asymmetric padding cases.
Key changes:
_compute_padding_length()
to handle stride-based paddingchannels_first
/channels_last
conversion in pooling ops_apply_same_padding()
data_format
throughout pooling pipelineThis fixes the issue where MaxPooling2D with 'same' padding would produce different shapes between compute_output_shape() and actual execution (e.g. (1,5,2,2) vs (1,5,2,1)) #20235.
Rebased on top of @sachinprasadhs's September 2024 PR to incorporate latest
keras:master
changes #20270.