Fix ResidualUnit padding override for explicit padding=0#9007
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
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>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/networks/blocks/test_convolutions.py (1)
154-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGive the regression test a descriptive name and docstring.
test_padding1does 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
📒 Files selected for processing (1)
tests/networks/blocks/test_convolutions.py
Signed-off-by: emianaya <48140966+emianaya@users.noreply.github.com>
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 passedpadding=0as falsy and silently overrides it with the auto-computed value. This is inconsistent with the Convolution class in the same file, which correctly checksif padding is None:.Also fixes a stale docstring reference to a parameter named
dimensions, which was renamed tospatial_dimsin this class but never updated in the dropout_dim docstring.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.