diff --git a/onnxscript/rewriter/rules/common/_fuse_pad_into_conv.py b/onnxscript/rewriter/rules/common/_fuse_pad_into_conv.py index 39aab00eda..f4daf5d2f2 100644 --- a/onnxscript/rewriter/rules/common/_fuse_pad_into_conv.py +++ b/onnxscript/rewriter/rules/common/_fuse_pad_into_conv.py @@ -147,6 +147,9 @@ def check(self, context, x: ir.Value, pad: ir.Value, conv: ir.Value) -> orp.Matc if np.any(self._pads_list[:2] + self._pads_list[x_rank : x_rank + 2]): self._pads_list = None return check_result.fail(f"{pads.name} must be zero in non-spatial dimensions.") + if any(p < 0 for p in self._pads_list): + self._pads_list = None + return check_result.fail(f"{pads.name} must not contain negative values.") return check_result diff --git a/onnxscript/rewriter/rules/common/_fuse_pad_into_conv_test.py b/onnxscript/rewriter/rules/common/_fuse_pad_into_conv_test.py index ded57fe023..529198fda4 100644 --- a/onnxscript/rewriter/rules/common/_fuse_pad_into_conv_test.py +++ b/onnxscript/rewriter/rules/common/_fuse_pad_into_conv_test.py @@ -193,6 +193,14 @@ def test_fuse_pad_into_conv(self, pad_pads, const_value, axes, conv_pads, conv_a "VALID", "auto_pad must be 'NOTSET'.", ), + ( + "constant", + ir.tensor([0, 0, -1, -1, -1, 0, 0, 0, 0, 0], name="pads"), + None, + None, + "NOTSET", + "must not contain negative values", + ), ] ) def test_unsupported_fuse_pad_into_conv(