Skip to content

Fix ResidualUnit padding override for explicit padding=0#9007

Open
emianaya wants to merge 3 commits into
Project-MONAI:devfrom
emianaya:patch-1
Open

Fix ResidualUnit padding override for explicit padding=0#9007
emianaya wants to merge 3 commits into
Project-MONAI:devfrom
emianaya:patch-1

Conversation

@emianaya

@emianaya emianaya commented Jul 22, 2026

Copy link
Copy Markdown

Fix ResidualUnit padding override for explicit padding=0

Description

ResidualUnit used if not padding: to decide whether to compute default same-padding, which treats an explicitly passed padding=0 as falsy and silently overrides it with the auto-computed value. This is inconsistent with the Convolution class in the same file, which correctly checks if padding is None:.

Also fixes a stale docstring reference to a parameter named dimensions, which was renamed to spatial_dims in this class but never updated in the dropout_dim docstring.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Fix ResidualUnit padding override for explicit padding=0

ResidualUnit used `if not padding:` to decide whether to compute
default same-padding, which treats an explicitly passed `padding=0`
as falsy and silently overrides it with the auto-computed value.
This is inconsistent with the Convolution class in the same file,
which correctly checks `if padding is None:`.

Also fixes a stale docstring reference to a parameter named
`dimensions`, which was renamed to `spatial_dims` in this class but never updated in the dropout_dim docstring.

Signed-off-by: emianaya <48140966+emianaya@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 54ba9cf1-790a-4bb9-96a7-1bb94b75167c

📥 Commits

Reviewing files that changed from the base of the PR and between 703e568 and 0307f30.

📒 Files selected for processing (1)
  • tests/networks/blocks/test_convolutions.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/networks/blocks/test_convolutions.py

📝 Walkthrough

Walkthrough

ResidualUnit documentation now references spatial_dims for dropout_dim. Its initializer computes same_padding only when padding is None, preserving explicit falsy values. A regression test verifies that padding=0 produces (0, 0) convolution padding.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving explicit padding=0 in ResidualUnit.
Description check ✅ Passed The description includes a clear summary, change types, and notes the new test and docstring update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@monai/networks/blocks/convolutions.py`:
- Around line 272-273: Update the residual block initialization around the
padding calculation to reject padding=0 when the convolution path can produce a
smaller shape than the skip path, particularly the default kernel_size=3,
subunits=2, strides=1 same-channel configuration. Validate this combination up
front or ensure the skip path uses a projection matching the convolution output,
and add a forward-pass test covering padding=0.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 662c9c27-bcb0-431d-85db-4dab5409dcb1

📥 Commits

Reviewing files that changed from the base of the PR and between 8885fcb and 6fef279.

📒 Files selected for processing (1)
  • monai/networks/blocks/convolutions.py

Comment thread monai/networks/blocks/convolutions.py
Adds test_padding1 to TestResidualUnit2D, asserting that an explicit padding=0 is preserved on the underlying conv layer instead of being silently replaced by the auto-computed same-padding value.

Signed-off-by: emianaya <48140966+emianaya@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/networks/blocks/test_convolutions.py (1)

154-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Give the regression test a descriptive name and docstring.

test_padding1 does not explain the behavior being protected, and the new test definition lacks the required docstring.

As per path instructions, “routine names should be meaningful” and “docstrings should be present for all definition[s].”

Suggested revision
-    def test_padding1(self):
+    def test_preserves_explicit_zero_padding(self):
+        """Verify that ResidualUnit preserves explicitly configured zero padding."""
         conv = ResidualUnit(2, 1, self.output_channels, kernel_size=3, padding=0)
         self.assertEqual(conv.conv.unit0.conv.padding, (0, 0))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/networks/blocks/test_convolutions.py` around lines 154 - 156, Rename
test_padding1 to a descriptive name that identifies the ResidualUnit
zero-padding behavior being verified, and add a docstring explaining that the
convolution uses (0, 0) padding when padding=0. Keep the existing assertions
unchanged.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/networks/blocks/test_convolutions.py`:
- Around line 154-156: Rename test_padding1 to a descriptive name that
identifies the ResidualUnit zero-padding behavior being verified, and add a
docstring explaining that the convolution uses (0, 0) padding when padding=0.
Keep the existing assertions unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d3b6eb8-f881-4824-8fae-a9e51f7e7afd

📥 Commits

Reviewing files that changed from the base of the PR and between 6fef279 and 703e568.

📒 Files selected for processing (1)
  • tests/networks/blocks/test_convolutions.py

Signed-off-by: emianaya <48140966+emianaya@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant