From 6fef279cefcc2eeb911dabb5d3d9e32c32d49094 Mon Sep 17 00:00:00 2001 From: emianaya <48140966+emianaya@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:27:35 -0700 Subject: [PATCH 1/3] Fix ResidualUnit padding override for explicit padding=0 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> --- monai/networks/blocks/convolutions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/networks/blocks/convolutions.py b/monai/networks/blocks/convolutions.py index 8b18614364..bbd49e509a 100644 --- a/monai/networks/blocks/convolutions.py +++ b/monai/networks/blocks/convolutions.py @@ -231,7 +231,7 @@ class ResidualUnit(nn.Module): - When dropout_dim = 2, Randomly zero out entire channels (a channel is a 2D feature map). - When dropout_dim = 3, Randomly zero out entire channels (a channel is a 3D feature map). - The value of dropout_dim should be no larger than the value of `dimensions`. + The value of dropout_dim should be no larger than the value of `spatial_dims`. dilation: dilation rate. Defaults to 1. bias: whether to have a bias term. Defaults to True. last_conv_only: for the last subunit, whether to use the convolutional layer only. @@ -269,7 +269,7 @@ def __init__( self.out_channels = out_channels self.conv = nn.Sequential() self.residual = nn.Identity() - if not padding: + if padding is None: padding = same_padding(kernel_size, dilation) schannels = in_channels sstrides = strides From 703e5685a43dd28e41f15742af8860ddeef17046 Mon Sep 17 00:00:00 2001 From: emianaya <48140966+emianaya@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:37:30 -0700 Subject: [PATCH 2/3] Add regression test for ResidualUnit padding fix 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> --- tests/networks/blocks/test_convolutions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/networks/blocks/test_convolutions.py b/tests/networks/blocks/test_convolutions.py index f882f133e9..b1fcecdca8 100644 --- a/tests/networks/blocks/test_convolutions.py +++ b/tests/networks/blocks/test_convolutions.py @@ -151,6 +151,10 @@ def test_dropout1(self): expected_shape = (1, self.output_channels, self.im_shape[0], self.im_shape[1]) self.assertEqual(out.shape, expected_shape) + def test_padding1(self): + conv = ResidualUnit(2, 1, self.output_channels, kernel_size=3, padding=0) + self.assertEqual(conv.conv.unit0.conv.padding, (0, 0)) + if __name__ == "__main__": unittest.main() From 0307f307fb37584f9d6eedb06de12efb57ee4c26 Mon Sep 17 00:00:00 2001 From: emianaya <48140966+emianaya@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:43:14 -0700 Subject: [PATCH 3/3] Use kernel_size=1 in padding test to avoid unrelated shape mismatch Signed-off-by: emianaya <48140966+emianaya@users.noreply.github.com> --- tests/networks/blocks/test_convolutions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/networks/blocks/test_convolutions.py b/tests/networks/blocks/test_convolutions.py index b1fcecdca8..0bbb8fa0ab 100644 --- a/tests/networks/blocks/test_convolutions.py +++ b/tests/networks/blocks/test_convolutions.py @@ -152,7 +152,7 @@ def test_dropout1(self): self.assertEqual(out.shape, expected_shape) def test_padding1(self): - conv = ResidualUnit(2, 1, self.output_channels, kernel_size=3, padding=0) + conv = ResidualUnit(2, 1, self.output_channels, kernel_size=1, padding=0) self.assertEqual(conv.conv.unit0.conv.padding, (0, 0))