diff --git a/test/onnx/gen_onnx.py b/test/onnx/gen_onnx.py index dbffdc28873..df1f530a13b 100644 --- a/test/onnx/gen_onnx.py +++ b/test/onnx/gen_onnx.py @@ -4880,6 +4880,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]) @@ -4953,6 +4966,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]) @@ -5017,6 +5071,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 e8aba965b8e..742272d668a 100644 --- a/test/onnx/onnx_test.cpp +++ b/test/onnx/onnx_test.cpp @@ -4672,6 +4672,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; @@ -4708,6 +4713,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; @@ -4786,6 +4796,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 00000000000..3e2deaaf7ff Binary files /dev/null and b/test/onnx/pad_4arg_invalid_axes_error_test.onnx differ 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 00000000000..0aaaedae187 Binary files /dev/null and b/test/onnx/pad_asym_invalid_pads_error_test.onnx differ 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