From 53c16eabe42c0e499070bc0511c1d5501617d420 Mon Sep 17 00:00:00 2001 From: huzhiqiang <912790387@qq.com> Date: Tue, 24 Dec 2019 12:47:27 +0800 Subject: [PATCH] test the compatibility between execution time and compiling time (#21511) * test the equality between running-time and compiling time * add white_list for compile_vs_runtime check test=develop * add check of new-registered op on compile&runtime-lodEquality test=develop * test=develop * test=develop * update white-list test=develop * merge with new code test=develop * fix code style test=develop * test=devleop * test=develop * test=develop * test=develop * add more ops to white_list test=develop * test=develop * test=develop * test=develop * test=develop * test=develop * fix code_style: add comments test=develop * test=develop --- .../paddle/fluid/tests/unittests/op_test.py | 8 ++++-- .../compile_vs_runtime_white_list.py | 28 +++++++++++++++++++ tools/check_api_approvals.sh | 7 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 python/paddle/fluid/tests/unittests/white_list/compile_vs_runtime_white_list.py diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index cc2a54b95e2..a54c8998ef0 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -33,7 +33,7 @@ from paddle.fluid.executor import Executor from paddle.fluid.framework import Program, OpProtoHolder, Variable from testsuite import create_op, set_input, append_input_output, append_loss_ops from paddle.fluid import unique_name -from white_list import op_accuracy_white_list, op_check_grad_white_list, check_shape_white_list +from white_list import op_accuracy_white_list, op_check_grad_white_list, check_shape_white_list, compile_vs_runtime_white_list def _set_use_system_allocator(value=None): @@ -1102,7 +1102,7 @@ class OpTest(unittest.TestCase): equal_nan=False, check_dygraph=True, inplace_atol=None, - check_compile_vs_runtime=False): + check_compile_vs_runtime=True): self.__class__.op_type = self.op_type places = self._get_places() for place in places: @@ -1112,7 +1112,9 @@ class OpTest(unittest.TestCase): outs, dygraph_outs, fetch_list = res else: outs, fetch_list = res - if check_compile_vs_runtime: + if check_compile_vs_runtime and ( + self.op_type not in + compile_vs_runtime_white_list.COMPILE_RUN_OP_WHITE_LIST): self.check_compile_vs_runtime(fetch_list, outs) def check_output_customized(self, checker): diff --git a/python/paddle/fluid/tests/unittests/white_list/compile_vs_runtime_white_list.py b/python/paddle/fluid/tests/unittests/white_list/compile_vs_runtime_white_list.py new file mode 100644 index 00000000000..c7184633f1d --- /dev/null +++ b/python/paddle/fluid/tests/unittests/white_list/compile_vs_runtime_white_list.py @@ -0,0 +1,28 @@ +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve +# +# 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. + +# If the output after infershape() is a lod_tensor, commenly its lod_level +# should be equal during compile time and run time. +# For ops in this whitelist, the equality check of lod_level between +# compiletime&runtime will not be required. +COMPILE_RUN_OP_WHITE_LIST = [ + 'lod_reset', 'sequence_pool', 'sequence_slice', 'generate_mask_labels', + 'sequence_reshape', 'generate_proposals', 'mine_hard_examples', + 'retinanet_detection_output', 'ctc_align', 'fusion_seqpool_cvm_concat', + 'gru', 'sequence_erase', 'rpn_target_assign', 'retinanet_target_assign', + 'filter_by_instag', 'fusion_seqpool_concat', 'multiclass_nms', + 'multiclass_nms2', 'im2sequence', 'generate_proposal_labels', + 'distribute_fpn_proposals', 'detection_map', 'locality_aware_nms', + 'var_conv_2d' +] diff --git a/tools/check_api_approvals.sh b/tools/check_api_approvals.sh index faedc75cc76..03d93355645 100644 --- a/tools/check_api_approvals.sh +++ b/tools/check_api_approvals.sh @@ -168,6 +168,13 @@ if [ "${HAS_INPLACE_TESTS}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then check_approval 1 46782768 47554610 43953930 6836917 fi +HAS_COMPILERUNTIME_NOT_TEST=`git diff -U0 --diff-filter=A upstream/$BRANCH |grep "+" |grep -E "check_output[(]*check_compile_vs_runtime=False" || true` +if [ "${HAS_COMPILERUNTIME_NOT_TEST}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then + echo_line="If the operator's output after infershape() is a LodTensor, the output's Lod-Level during compile-time and runtime must be equal. Please set check_compile_vs_runtime=True in op_test.check_output function to enable compile&runtime lod-level check.\n +If you do not need check_compile_vs_runtime, you must have one RD (lanxianghit, phlrain, luotao1) approval.\nThe corresponding lines are as follows:\n${HAS_COMPILERUNTIME_NOT_TEST}\n" + check_approval 1 47554610 43953930 6836917 +fi + OP_FILE_CHANGED=`git diff --name-only --diff-filter=AMR upstream/$BRANCH |grep -oE ".+_op..*" || true` if [ "${OP_FILE_CHANGED}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then for OP_FILE in ${OP_FILE_CHANGED}; -- GitLab