From 7ab44afbcc0c41dcc35ff2fa2cb0960312ff8044 Mon Sep 17 00:00:00 2001 From: zhupengyang <1165938320@qq.com> Date: Thu, 16 Jan 2020 09:59:13 +0800 Subject: [PATCH] check op tests' shape should be 100+ (#22047) --- .../paddle/fluid/tests/unittests/op_test.py | 20 +++++------ .../unittests/test_match_matrix_tensor_op.py | 2 +- .../white_list/check_shape_white_list.py | 33 +++++++++++++++++-- tools/check_api_approvals.sh | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 9503a919a94..e5154e0c595 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -70,10 +70,8 @@ def get_numeric_gradient(place, tensor_to_check = scope.find_var(input_to_check).get_tensor() tensor_size = product(tensor_to_check.shape()) - if not hasattr(get_numeric_gradient, 'check_shape_time'): - get_numeric_gradient.check_shape_time = 0 - if tensor_size >= 100: - get_numeric_gradient.check_shape_time += 1 + if tensor_size < 100: + get_numeric_gradient.is_large_shape = False tensor_to_check_dtype = tensor_to_check._dtype() if tensor_to_check_dtype == core.VarDesc.VarType.FP32: tensor_to_check_dtype = np.float32 @@ -186,6 +184,8 @@ class OpTest(unittest.TestCase): cls._use_system_allocator = _set_use_system_allocator(True) + get_numeric_gradient.is_large_shape = True + @classmethod def tearDownClass(cls): """Restore random seeds""" @@ -231,13 +231,12 @@ class OpTest(unittest.TestCase): "This test of %s op needs check_grad with fp64 precision." % cls.op_type) - if hasattr(get_numeric_gradient, 'check_shape_time') \ - and get_numeric_gradient.check_shape_time == 0 \ - and OpTest.op_type not in check_shape_white_list.NOT_CHECK_OP_LIST \ - and OpTest.op_type not in check_shape_white_list.NEED_TO_FIX_OP_LIST: + if not get_numeric_gradient.is_large_shape \ + and cls.op_type not in check_shape_white_list.NOT_CHECK_OP_LIST \ + and cls.op_type not in check_shape_white_list.NEED_TO_FIX_OP_LIST: raise AssertionError( - "At least one input's shape should be large than or equal to 100 for " - + OpTest.op_type + " Op.") + "Input's shape should be large than or equal to 100 for " + + cls.op_type + " Op.") def try_call_once(self, data_type): if not self.call_once: @@ -1269,7 +1268,6 @@ class OpTest(unittest.TestCase): max_relative_error=0.005, user_defined_grads=None, check_dygraph=True): - OpTest.op_type = self.op_type self.scope = core.Scope() op_inputs = self.inputs if hasattr(self, "inputs") else dict() op_outputs = self.outputs if hasattr(self, "outputs") else dict() diff --git a/python/paddle/fluid/tests/unittests/test_match_matrix_tensor_op.py b/python/paddle/fluid/tests/unittests/test_match_matrix_tensor_op.py index fb1b62aa580..5784d3b5d74 100644 --- a/python/paddle/fluid/tests/unittests/test_match_matrix_tensor_op.py +++ b/python/paddle/fluid/tests/unittests/test_match_matrix_tensor_op.py @@ -79,7 +79,7 @@ class TestMatchMatrixTensorOp(OpTest): class TestMatchMatrixTensorOpCase1(TestMatchMatrixTensorOp): def set_data(self): - ix, iy, h, dim_t = [5, 8, 16, 4] + ix, iy, h, dim_t = [5, 8, 25, 4] x_lod = [[5]] y_lod = [[8]] self.init_data(ix, x_lod, iy, y_lod, h, dim_t) diff --git a/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py b/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py index c79e7358e7d..f00c9e811d7 100644 --- a/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py +++ b/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py @@ -14,10 +14,37 @@ NOT_CHECK_OP_LIST = [ # The increment's input must be 1-d and only has one data - 'increment' + 'increment', + # elementwise ops have cases(y_shape: (1) or (1,1)) to test broadcast + 'elementwise_add', + 'elementwise_sub', + 'elementwise_mul', + 'elementwise_div', + 'elementwise_max', + 'elementwise_min', + 'elementwise_pow', + 'fused_elemwise_activation', + # prelu op's input alpha must be 1-d and only has one data in 'all' mode + 'prelu' ] NEED_TO_FIX_OP_LIST = [ - 'sequence_topk_avg_pooling', 'matmul', 'add_position_encoding', - 'margin_rank_loss', 'elementwise_pow', 'fused_elemwise_activation', 'mul' + 'bilinear_tensor_product', + 'conv2d_transpose', + 'deformable_conv', + 'depthwise_conv2d_transpose', + 'grid_sampler', + 'hierarchical_sigmoid', + 'lstmp', + 'margin_rank_loss', + 'matmul', + 'mul', + 'row_conv', + 'scatter', + 'smooth_l1_loss', + 'soft_relu', + 'spp', + 'squared_l2_distance', + 'tree_conv', + 'var_conv_2d', ] diff --git a/tools/check_api_approvals.sh b/tools/check_api_approvals.sh index 92df022cf4d..a2e706602c9 100644 --- a/tools/check_api_approvals.sh +++ b/tools/check_api_approvals.sh @@ -110,7 +110,7 @@ for API_FILE in ${API_FILES[*]}; do echo_line="You must have one RD (zhiqiu (Recommend) , sneaxiy or luotao1) approval for the paddle/fluid/framework/unused_var_check.cc, which manages the white list of operators that have unused input variables. Before change the white list, please read the specification [https://github.com/PaddlePaddle/Paddle/wiki/OP-Should-Not-Have-Unused-Input] and try to refine code first. \n" check_approval 1 6888866 32832641 6836917 elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py" ];then - echo_line="It is an Op accuracy problem, please take care of it. You must have one RD (hong19860320 (Recommend), luotao1, phlrain) approval for the changes of check_shape_white_list.py, which manages the white list of operators with limited input size. The op test must have at least one test case with input size greater than or equal to 100. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/OP-Test-Input-Shape-Requirements. \n" + echo_line="It is an Op accuracy problem, please take care of it. You must have one RD (hong19860320 (Recommend), luotao1, phlrain) approval for the changes of check_shape_white_list.py, which manages the white list of operators with limited input size. Inputs size of all cases in the op test must be greater than or equal to 100. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/OP-Test-Input-Shape-Requirements. \n" check_approval 1 9973393 6836917 43953930 elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py" ];then echo_line="It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 (Recommend) or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py, which manages the white list of upgrading the precision of op test to float64. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. \n" -- GitLab