Skip to content

Commit f02b7a9

Browse files
peterbell10pytorchmergebot
authored andcommitted
Pad: don't error when unused fill value is zero
Fixes pytorch/vision#5873 In the python version of `F.pad`, checking that the fill value was left as default was done by comparing against zero: https://github.com/pytorch/pytorch/blob/bc2c6edaf163b1a1330e37a6e34caf8c553e4755/torch/nn/functional.py#L4366 So if someone does explicitly pass in a zero-value, then this `TORCH_CHECK` was an accidental BC-break. Pull Request resolved: #76307 Approved by: https://github.com/albanD, https://github.com/jbschlosser, https://github.com/datumbox
1 parent 03e85e5 commit f02b7a9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

aten/src/ATen/native/PadNd.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ Tensor _pad_enum(const Tensor &self, IntArrayRef pad, int64_t mode_int, c10::opt
163163
if (mode == at::padding_mode::constant) {
164164
return at::constant_pad_nd(self, pad, value.value_or(0.0));
165165
}
166-
TORCH_CHECK(
167-
!value.has_value(), "Padding mode \"",
168-
padding_mode_string(mode),
169-
"\" doesn't take in value argument");
166+
TORCH_CHECK(!value.has_value() || *value == 0,
167+
"Padding mode \"", padding_mode_string(mode),
168+
"\" doesn't take in value argument");
170169

171170
if (pad.size() == 2 && (input_dim == 2 || input_dim == 3)) {
172171
switch (mode) {

0 commit comments

Comments
 (0)