diff --git a/lite/tests/unittest_py/op/test_greater_op.py b/lite/tests/unittest_py/op/test_greater_op.py new file mode 100644 index 00000000000..f3644877cc7 --- /dev/null +++ b/lite/tests/unittest_py/op/test_greater_op.py @@ -0,0 +1,120 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +from numpy.lib.function_base import place +sys.path.append('../') + +from auto_scan_test import AutoScanTest, IgnoreReasons +from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place +import unittest + +import hypothesis +from hypothesis import given, settings, seed, example, assume +import hypothesis.strategies as st +import argparse +import numpy as np +from functools import partial + + +class TestAssignOp(AutoScanTest): + def __init__(self, *args, **kwargs): + AutoScanTest.__init__(self, *args, **kwargs) + host_op_config = [ + Place(TargetType.Host, PrecisionType.Any, DataLayoutType.NCHW), + Place(TargetType.Host, PrecisionType.FP32, DataLayoutType.Any) + ] + self.enable_testing_on_place(places=host_op_config) + + def is_program_valid(self, + program_config: ProgramConfig, + predictor_config: CxxConfig) -> bool: + in_dtype = program_config.inputs["data_x"].dtype + + if "int32" == in_dtype: + return False + return True + + def sample_program_configs(self, draw): + in_shape_x = draw( + st.lists( + st.integers( + min_value=3, max_value=10), min_size=3, max_size=4)) + axis = draw(st.sampled_from([-1, 0, 1, 2])) + op_type_str = draw(st.sampled_from(["greater_equal", "greater_than"])) + process_type = draw( + st.sampled_from(["type_int64", "type_float", "type_int32"])) + + if axis == -1: + in_shape_y = in_shape_x + else: + in_shape_y = in_shape_x[axis:] + + def generate_data(type, size_list): + if type == "type_int32": + return np.random.randint( + low=0, high=100, size=size_list).astype(np.int32) + elif type == "type_int64": + return np.random.randint( + low=0, high=100, size=size_list).astype(np.int64) + elif type == "type_float": + return np.random.random(size=size_list).astype(np.float32) + + def generate_input_x(): + return generate_data(process_type, in_shape_x) + + def generate_input_y(): + return generate_data(process_type, in_shape_y) + + build_ops = OpConfig( + type=op_type_str, + inputs={"X": ["data_x"], + "Y": ["data_y"]}, + outputs={"Out": ["output_data"], }, + attrs={"axis": axis, + "force_cpu": True}, + outputs_dtype={"output_data": np.bool_}) + + cast_out = OpConfig( + type="cast", + inputs={"X": ["output_data"], }, + outputs={"Out": ["cast_data_out"], }, + attrs={"in_dtype": int(0), + "out_dtype": int(2)}, + outputs_dtype={"cast_data_out": np.int32}) + + program_config = ProgramConfig( + ops=[build_ops, cast_out], + weights={}, + inputs={ + "data_x": TensorConfig(data_gen=partial(generate_input_x)), + "data_y": TensorConfig(data_gen=partial(generate_input_y)), + }, + outputs=["cast_data_out"]) + return program_config + + def sample_predictor_configs(self): + return self.get_predictor_configs(), ["greater_equal_and_than"], (1e-5, + 1e-5) + + def add_ignore_pass_case(self): + pass + + def test(self, *args, **kwargs): + self.run_and_statis(quant=False, max_examples=300) + + +if __name__ == "__main__": + unittest.main(argv=['']) diff --git a/lite/tests/unittest_py/op/test_grid_sampler_op.py b/lite/tests/unittest_py/op/test_grid_sampler_op.py new file mode 100644 index 00000000000..6e56d3e0602 --- /dev/null +++ b/lite/tests/unittest_py/op/test_grid_sampler_op.py @@ -0,0 +1,123 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +sys.path.append('../') + +from auto_scan_test import AutoScanTest, IgnoreReasons +from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place +import unittest + +import hypothesis +from hypothesis import given, settings, seed, example, assume + +import numpy as np +from functools import partial +import hypothesis.strategies as st + + +class TestGridSamplerOp(AutoScanTest): + def __init__(self, *args, **kwargs): + AutoScanTest.__init__(self, *args, **kwargs) + self.enable_testing_on_place( + TargetType.X86, + PrecisionType.FP32, + DataLayoutType.NCHW, + thread=[1, 4]) + self.enable_testing_on_place( + TargetType.ARM, + PrecisionType.FP32, + DataLayoutType.NCHW, + thread=[1, 4]) + opencl_places = [ + Place(TargetType.OpenCL, PrecisionType.FP16, + DataLayoutType.ImageDefault), Place( + TargetType.OpenCL, PrecisionType.FP16, + DataLayoutType.ImageFolder), + Place(TargetType.OpenCL, PrecisionType.FP32, DataLayoutType.NCHW), + Place(TargetType.OpenCL, PrecisionType.Any, + DataLayoutType.ImageDefault), Place( + TargetType.OpenCL, PrecisionType.Any, + DataLayoutType.ImageFolder), + Place(TargetType.OpenCL, PrecisionType.Any, DataLayoutType.NCHW), + Place(TargetType.Host, PrecisionType.FP32) + ] + self.enable_testing_on_place(places=opencl_places) + + def is_program_valid(self, + program_config: ProgramConfig, + predictor_config: CxxConfig) -> bool: + if predictor_config.target() == TargetType.OpenCL: + if program_config.ops[0].attrs[ + "align_corners"] != True or program_config.ops[0].attrs[ + "padding_mode"] != "zeros" or program_config.ops[ + 0].attrs["mode"] != "bilinear": + return False + return True + + def sample_program_configs(self, draw): + in_shape1 = draw( + st.lists( + st.integers( + min_value=3, max_value=10), min_size=4, max_size=4)) + + in_shape2 = [] + in_shape2.append(in_shape1[0]) + in_shape2.append(in_shape1[2]) + in_shape2.append(in_shape1[3]) + in_shape2.append(2) + + align_corners = draw(st.booleans()) + mode = draw(st.sampled_from(["bilinear", "nearest"])) + padding_mode = draw(st.sampled_from(["zeros", "reflection", "border"])) + grid_sampler_op = OpConfig( + type="grid_sampler", + inputs={"X": ["input_data"], + "Grid": ["grid_data"]}, + outputs={"Output": ["output_data"]}, + attrs={ + "align_corners": align_corners, + "mode": mode, + "padding_mode": padding_mode + }) + + program_config = ProgramConfig( + ops=[grid_sampler_op], + weights={"grid_data": TensorConfig(shape=in_shape2)}, + inputs={"input_data": TensorConfig(shape=in_shape1)}, + outputs=["output_data"]) + + return program_config + + def sample_predictor_configs(self): + return self.get_predictor_configs(), ["grid_sampler"], (1e-5, 1e-5) + + def add_ignore_pass_case(self): + def teller1(program_config, predictor_config): + return True + + self.add_ignore_check_case( + # IgnoreReasonsBase.PADDLE_NOT_IMPLEMENTED + # IgnoreReasonsBase.PADDLELITE_NOT_SUPPORT + # IgnoreReasonsBase.ACCURACY_ERROR + teller1, + IgnoreReasons.ACCURACY_ERROR, + "The op output has diff. We need to fix it as soon as possible.") + + def test(self, *args, **kwargs): + self.run_and_statis(quant=False, max_examples=300) + + +if __name__ == "__main__": + unittest.main(argv=[''])