Skip to content

Fix incorrect static shape in depthwise_conv and separable_conv when strides > 1 and dilation_rate > 1#22598

Open
ssam18 wants to merge 2 commits intokeras-team:masterfrom
ssam18:fix/depthwise-separable-conv-strides-dilation-validation
Open

Fix incorrect static shape in depthwise_conv and separable_conv when strides > 1 and dilation_rate > 1#22598
ssam18 wants to merge 2 commits intokeras-team:masterfrom
ssam18:fix/depthwise-separable-conv-strides-dilation-validation

Conversation

@ssam18
Copy link
Copy Markdown
Contributor

@ssam18 ssam18 commented Apr 1, 2026

The low-level keras.ops.depthwise_conv and keras.ops.separable_conv ops were missing a validation that already exists in the high-level DepthwiseConv2D and SeparableConv2D layers: using strides > 1 together with dilation_rate > 1 is not supported. Without it, the static shape returned during tracing was computed using the standard convolution formula, which disagrees with what the underlying TF ops actually produce, leading to a silent shape mismatch. The fix raises a clear ValueError at call time (both eager and symbolic) and updates the tests to assert on the error instead of silently skipping the case on the TF backend.

…le_conv ops

The low-level keras.ops.depthwise_conv and keras.ops.separable_conv functions lacked the same strides > 1 + dilation_rate > 1 validation that already exists in the high-level DepthwiseConv2D and SeparableConv2D layers. This caused the symbolic (static) shape inference to return incorrect shapes when both strides > 1 and dilation_rate > 1 are used together, since the formula-based shape computation
disagrees with what TF's depthwise/separable conv ops actually produce.

Also added the validation to both ops and updated the tests to assert a ValueError instead of silently skipping the unsupported combination on the TF backend.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces validation in depthwise_conv and separable_conv to prevent the simultaneous use of strides and dilation rates greater than one, which is not supported. The implementation raises a ValueError when these conditions are met, and the tests have been updated to assert this behavior. Feedback focuses on improving maintainability by extracting the duplicated max-value calculation logic into a helper function and ensuring that the type-checking in tests is consistent with the implementation by supporting both lists and tuples.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.29%. Comparing base (b0ec1b6) to head (999010e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22598   +/-   ##
=======================================
  Coverage   83.28%   83.29%           
=======================================
  Files         596      596           
  Lines       68089    68095    +6     
  Branches    10607    10609    +2     
=======================================
+ Hits        56711    56717    +6     
  Misses       8634     8634           
  Partials     2744     2744           
Flag Coverage Δ
keras 83.10% <100.00%> (+<0.01%) ⬆️
keras-jax 59.67% <100.00%> (+<0.01%) ⬆️
keras-numpy 55.35% <100.00%> (+<0.01%) ⬆️
keras-openvino 53.34% <100.00%> (+<0.01%) ⬆️
keras-tensorflow 61.04% <100.00%> (+<0.01%) ⬆️
keras-torch 59.85% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…s+dilation

The static and dynamic shape tests were asserting on output shapes for strides=2 + dilation_rate=2 combinations, which are now correctly rejected
with a ValueError. Also extract _get_seq_max helper to avoid duplicated logic in depthwise_conv and separable_conv, and use (list, tuple) consistently
in the test isinstance checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants