Skip to content

Commit ed2d224

Browse files
[opt:fuse_pad_into_conv] remove NOTSET auto_pad (#251)
#33 --------- Signed-off-by: 462630221 <[email protected]> Signed-off-by: take-cheeze <[email protected]> Co-authored-by: 462630221 <[email protected]>
1 parent d466e65 commit ed2d224

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

onnxoptimizer/passes/fuse_pad_into_conv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ struct FusePadIntoConv final : public PredicateBasedPass {
119119
return false;
120120
}
121121

122+
// Clean the auto_pad if NOTSET
123+
if (conv->hasAttribute(Symbol("auto_pad"))) {
124+
if (conv->s(Symbol("auto_pad")) != "NOTSET") {
125+
return false;
126+
}
127+
conv->removeAttribute(Symbol("auto_pad"));
128+
}
129+
122130
int conv_pads_size = pads_size - 4;
123131
std::vector<int64_t> conv_pads(conv_pads_size, 0);
124132
// Fuse into existing padding, if available

onnxoptimizer/test/optimizer_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,33 @@ def test_fuse_pad_into_conv_reflection_pad_no_fuse(self):
20112011

20122012
assert optimized_model.graph == graph
20132013

2014+
# type: () -> None
2015+
def test_fuse_pad_into_conv_with_notset_autopad(self):
2016+
pad = helper.make_node(
2017+
"Pad", ["X"], ["P"], mode="constant", pads=[0, 0, 0, 0, 0, 0, 1, 1]
2018+
)
2019+
conv = helper.make_node("Conv", ["P", "Y"], ["Z"], auto_pad="NOTSET")
2020+
graph = helper.make_graph(
2021+
[pad, conv],
2022+
"test",
2023+
[
2024+
helper.make_tensor_value_info("X", TensorProto.FLOAT, (1, 5, 2, 2)),
2025+
helper.make_tensor_value_info("Y", TensorProto.FLOAT, (16, 5, 3, 3)),
2026+
],
2027+
[helper.make_tensor_value_info("Z", TensorProto.FLOAT, (1, 16, 1, 1))],
2028+
)
2029+
optimized_model = self._optimized(
2030+
graph,
2031+
["fuse_pad_into_conv"],
2032+
False,
2033+
opset_imports=[helper.make_opsetid("", 10)],
2034+
)
2035+
2036+
assert len(list(optimized_model.graph.node)) == 1
2037+
assert optimized_model.graph.node[0].op_type == "Conv"
2038+
assert optimized_model.graph.node[0].attribute[0].name == "pads"
2039+
assert list(optimized_model.graph.node[0].attribute[0].ints) == [0, 0, 1, 1]
2040+
20142041
def test_fuse_pad_into_avgpool_no_optional_value_opset10(self):
20152042
pad = helper.make_node(
20162043
"Pad", ["X"], ["P"], mode="constant", pads=[0, 0, 0, 0, 0, 0, 1, 1]

0 commit comments

Comments
 (0)