From f72e7ba36eca70910161144f24212b60b4b5b4c1 Mon Sep 17 00:00:00 2001 From: Attila Dusnoki Date: Tue, 19 Sep 2023 08:57:46 +0000 Subject: [PATCH] Add more tests --- test/onnx/gen_onnx.py | 87 ++++++++++++++++++ test/onnx/onnx_test.cpp | 31 +++++++ .../pad_4arg_invalid_axes_error_test.onnx | Bin 0 -> 334 bytes .../pad_asym_invalid_pads_error_test.onnx | Bin 0 -> 171 bytes test/onnx/pad_reflect_with_axes_test.onnx | 18 ++++ 5 files changed, 136 insertions(+) create mode 100644 test/onnx/pad_4arg_invalid_axes_error_test.onnx create mode 100644 test/onnx/pad_asym_invalid_pads_error_test.onnx create mode 100644 test/onnx/pad_reflect_with_axes_test.onnx diff --git a/test/onnx/gen_onnx.py b/test/onnx/gen_onnx.py index 01dbae73524..facf5c361b5 100644 --- a/test/onnx/gen_onnx.py +++ b/test/onnx/gen_onnx.py @@ -4754,6 +4754,19 @@ def pad_asym_test(): return ([node], [x], [y]) +@onnx_test() +def pad_asym_invalid_pads_error_test(): + x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 4, 5]) + y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 6, 4, 12]) + + node = onnx.helper.make_node('Pad', + inputs=['0'], + pads=[0, 1, 0, 3, 0, 2], + outputs=['1']) + + return ([node], [x], [y]) + + @onnx_test() def pad_3arg_test(): values = np.array([1]) @@ -4827,6 +4840,47 @@ def pad_4arg_axes_test(): return ([arg_axes, arg_val, arg_pad, node], [x], [y]) +@onnx_test() +def pad_4arg_invalid_axes_error_test(): + values = np.array([1]) + val_tensor = helper.make_tensor(name='val', + data_type=TensorProto.FLOAT, + dims=values.reshape(()).shape, + vals=values.astype(float)) + arg_val = onnx.helper.make_node('Constant', + inputs=[], + outputs=['arg_val'], + value=val_tensor) + + sizes = np.array([1, 3, 2, 4]) + pad_tensor = helper.make_tensor(name='pad_size', + data_type=TensorProto.INT32, + dims=sizes.shape, + vals=sizes.astype(int)) + arg_pad = onnx.helper.make_node('Constant', + inputs=[], + outputs=['arg_pad'], + value=pad_tensor) + + axes = np.array([1, 2, 3]) + axes_tensor = helper.make_tensor(name='pad_axes', + data_type=TensorProto.INT32, + dims=axes.shape, + vals=axes.astype(int)) + arg_axes = onnx.helper.make_node('Constant', + inputs=[], + outputs=['arg_axes'], + value=axes_tensor) + + x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 4, 5]) + y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 6, 4, 12]) + + node = onnx.helper.make_node( + 'Pad', inputs=['0', 'arg_pad', 'arg_val', 'arg_axes'], outputs=['1']) + + return ([arg_axes, arg_val, arg_pad, node], [x], [y]) + + @onnx_test() def pad_4arg_neg_axes_test(): values = np.array([1]) @@ -4891,6 +4945,39 @@ def pad_reflect_test(): return ([arg_pad, node], [x], [y]) +@onnx_test() +def pad_reflect_with_axes_test(): + x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2]) + y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 5]) + + sizes = np.array([2, 1]) + pad_tensor = helper.make_tensor(name='pad_size', + data_type=TensorProto.INT32, + dims=sizes.shape, + vals=sizes.astype(int)) + arg_pad = onnx.helper.make_node('Constant', + inputs=[], + outputs=['arg_pad'], + value=pad_tensor) + + axes = np.array([1]) + axes_tensor = helper.make_tensor(name='pad_axes', + data_type=TensorProto.INT32, + dims=axes.shape, + vals=axes.astype(int)) + arg_axes = onnx.helper.make_node('Constant', + inputs=[], + outputs=['arg_axes'], + value=axes_tensor) + + node = onnx.helper.make_node('Pad', + mode='reflect', + inputs=['0', 'arg_pad', 'arg_axes'], + outputs=['1']) + + return ([arg_axes, arg_pad, node], [x], [y]) + + @onnx_test() def pad_reflect_multiaxis_test(): x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3]) diff --git a/test/onnx/onnx_test.cpp b/test/onnx/onnx_test.cpp index 311e1785161..6fe7e49cb08 100644 --- a/test/onnx/onnx_test.cpp +++ b/test/onnx/onnx_test.cpp @@ -4568,6 +4568,11 @@ TEST_CASE(pad_asym_test) EXPECT(p == prog); } +TEST_CASE(pad_asym_invalid_pads_error_test) +{ + EXPECT(test::throws([&] { migraphx::parse_onnx("pad_asym_invalid_pads_error_test.onnx"); })); +} + TEST_CASE(pad_3arg_test) { migraphx::program p; @@ -4604,6 +4609,11 @@ TEST_CASE(pad_4arg_axes_test) EXPECT(p == prog); } +TEST_CASE(pad_4arg_invalid_axes_error_test) +{ + EXPECT(test::throws([&] { migraphx::parse_onnx("pad_4arg_invalid_axes_error_test.onnx"); })); +} + TEST_CASE(pad_4arg_neg_axes_test) { migraphx::program p; @@ -4682,6 +4692,27 @@ TEST_CASE(pad_reflect_test) EXPECT(p == prog); } +TEST_CASE(pad_reflect_with_axes_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 2}}); + mm->add_literal({migraphx::shape{migraphx::shape::int32_type, {1}}, {1}}); + mm->add_literal({migraphx::shape{migraphx::shape::int32_type, {2}}, {2, 1}}); + auto l1 = mm->add_instruction( + migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 1}}, {"ends", {2, 2}}}), l0); + auto l2 = mm->add_instruction( + migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 0}}, {"ends", {2, 1}}}), l0); + auto l3 = mm->add_instruction( + migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 0}}, {"ends", {2, 1}}}), l0); + auto r = mm->add_instruction(migraphx::make_op("concat", {{"axis", 1}}), l2, l1, l0, l3); + mm->add_return({r}); + + auto prog = migraphx::parse_onnx("pad_reflect_with_axes_test.onnx"); + + EXPECT(p == prog); +} + TEST_CASE(pad_reflect_multiaxis_test) { migraphx::program p; diff --git a/test/onnx/pad_4arg_invalid_axes_error_test.onnx b/test/onnx/pad_4arg_invalid_axes_error_test.onnx new file mode 100644 index 0000000000000000000000000000000000000000..3e2deaaf7fffdc6166b470ba6e8d51703d221565 GIT binary patch literal 334 zcmaivzY4-I7{tvVH3o%{iXaY37ome#(8WclFW~GFA`McIDoGV_@=*j|)GyYGxHudH z?ss=zSWAwMI#n}mcPh)zdY`3AUyM`6+JjYvamC_+`CKwjcqe45L+%Ql7txT{A#pNM zz=&u>1YwdeU+1|yqI@EoJ_gWNs$Zo#0)@0zyDbv}gy-ia4;5ehsN%bf!U{zM({jdT zSL0)2j;8#z1j+INh5U1}L~%&gI{p9G%>b%ok9Qf8f@6k21VlmgEtv6-*?61n1dHGa DY&KGU literal 0 HcmV?d00001 diff --git a/test/onnx/pad_asym_invalid_pads_error_test.onnx b/test/onnx/pad_asym_invalid_pads_error_test.onnx new file mode 100644 index 0000000000000000000000000000000000000000..0aaaedae187d4f05776a004db7883818bf5c62ef GIT binary patch literal 171 zcmdk{uFQ?k%qvUG$xMj{3KYku78T_e#h0WOmsmA0aw%~!8VE5ODlrEn zrf7+Bv4E5~FgP#*F*6V|Ens9PY*3Um$P_Uy5e`Nn0WKyEMj&PeViq7~O#(_9qDitr KC3&2f1cU*tDJ3-k literal 0 HcmV?d00001 diff --git a/test/onnx/pad_reflect_with_axes_test.onnx b/test/onnx/pad_reflect_with_axes_test.onnx new file mode 100644 index 00000000000..1556ed708f9 --- /dev/null +++ b/test/onnx/pad_reflect_with_axes_test.onnx @@ -0,0 +1,18 @@ + pad_reflect_with_axes_test:ä +3arg_axes"Constant* +value**Bpad_axes  +3arg_pad"Constant* +value**Bpad_size  +2 +0 +arg_pad +arg_axes1"Pad* +mode"reflect pad_reflect_with_axes_testZ +0 +  + +b +1 +  + +B \ No newline at end of file