未验证 提交 835ba4ec 编写于 作者: Z Zhang Ting 提交者: GitHub

add is_empty_grad_op for OpTest (#22022)

* add is_empty_grad_op for OpTest, test=develop
上级 34e26c9a
...@@ -33,7 +33,7 @@ from paddle.fluid.executor import Executor ...@@ -33,7 +33,7 @@ from paddle.fluid.executor import Executor
from paddle.fluid.framework import Program, OpProtoHolder, Variable from paddle.fluid.framework import Program, OpProtoHolder, Variable
from testsuite import create_op, set_input, append_input_output, append_loss_ops from testsuite import create_op, set_input, append_input_output, append_loss_ops
from paddle.fluid import unique_name from paddle.fluid import unique_name
from white_list import op_accuracy_white_list, op_check_grad_white_list, check_shape_white_list, compile_vs_runtime_white_list from white_list import op_accuracy_white_list, check_shape_white_list, compile_vs_runtime_white_list
def _set_use_system_allocator(value=None): def _set_use_system_allocator(value=None):
...@@ -193,6 +193,19 @@ class OpTest(unittest.TestCase): ...@@ -193,6 +193,19 @@ class OpTest(unittest.TestCase):
_set_use_system_allocator(cls._use_system_allocator) _set_use_system_allocator(cls._use_system_allocator)
def is_empty_grad_op(op_type):
all_op_kernels = core._get_all_register_op_kernels()
grad_op = op_type + '_grad'
if grad_op in all_op_kernels.keys():
if hasattr(cls, "use_mkldnn") and cls.use_mkldnn == True:
grad_op_kernels = all_op_kernels[grad_op]
for grad_op_kernel in grad_op_kernels:
if 'MKLDNN' in grad_op_kernel:
return False
else:
return False
return True
if not hasattr(cls, "op_type"): if not hasattr(cls, "op_type"):
raise AssertionError( raise AssertionError(
"This test do not have op_type in class attrs," "This test do not have op_type in class attrs,"
...@@ -200,7 +213,7 @@ class OpTest(unittest.TestCase): ...@@ -200,7 +213,7 @@ class OpTest(unittest.TestCase):
# case in NO_FP64_CHECK_GRAD_CASES and op in NO_FP64_CHECK_GRAD_OP_LIST should be fixed # case in NO_FP64_CHECK_GRAD_CASES and op in NO_FP64_CHECK_GRAD_OP_LIST should be fixed
if not hasattr(cls, "no_need_check_grad") \ if not hasattr(cls, "no_need_check_grad") \
and cls.op_type not in op_check_grad_white_list.EMPTY_GRAD_OP_LIST: and not is_empty_grad_op(cls.op_type):
if cls.dtype is None or \ if cls.dtype is None or \
(cls.dtype == np.float16 \ (cls.dtype == np.float16 \
and cls.op_type not in op_accuracy_white_list.NO_FP16_CHECK_GRAD_OP_LIST \ and cls.op_type not in op_accuracy_white_list.NO_FP16_CHECK_GRAD_OP_LIST \
...@@ -299,6 +312,8 @@ class OpTest(unittest.TestCase): ...@@ -299,6 +312,8 @@ class OpTest(unittest.TestCase):
def _append_ops(self, block): def _append_ops(self, block):
self.__class__.op_type = self.op_type # for ci check, please not delete it for now self.__class__.op_type = self.op_type # for ci check, please not delete it for now
if hasattr(self, "use_mkldnn"):
self.__class__.use_mkldnn = self.use_mkldnn
op_proto = OpProtoHolder.instance().get_op_proto(self.op_type) op_proto = OpProtoHolder.instance().get_op_proto(self.op_type)
"infer datatype from inputs and outputs for this test case" "infer datatype from inputs and outputs for this test case"
self.infer_dtype_from_inputs_outputs(self.inputs, self.outputs) self.infer_dtype_from_inputs_outputs(self.inputs, self.outputs)
...@@ -1102,6 +1117,8 @@ class OpTest(unittest.TestCase): ...@@ -1102,6 +1117,8 @@ class OpTest(unittest.TestCase):
inplace_atol=None, inplace_atol=None,
check_compile_vs_runtime=True): check_compile_vs_runtime=True):
self.__class__.op_type = self.op_type self.__class__.op_type = self.op_type
if hasattr(self, "use_mkldnn"):
self.__class__.use_mkldnn = self.use_mkldnn
places = self._get_places() places = self._get_places()
for place in places: for place in places:
res = self.check_output_with_place(place, atol, no_check_set, res = self.check_output_with_place(place, atol, no_check_set,
......
# Copyright (c) 2019 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.
# Grad op is not registered for Ops in EMPTY_GRAD_OP_LIST, so check grad
# will not be required.
EMPTY_GRAD_OP_LIST = [
'fill_zeros_like2', 'gaussian_random_batch_size_like',
'fill_constant_batch_size_like', 'iou_similarity', 'where',
'uniform_random_batch_size_like', 'box_coder', 'equal', 'greater_equal',
'greater_than', 'less_equal', 'sequence_enumerate', 'logical_and',
'logical_not', 'logical_or', 'logical_xor', 'unique',
'fusion_seqconv_eltadd_relu', 'prior_box', 'decayed_adagrad',
'crf_decoding', 'mine_hard_examples', 'fusion_seqpool_concat',
'fused_embedding_fc_lstm', 'top_k', 'uniform_random', 'multihead_matmul',
'edit_distance', 'shard_index', 'generate_proposals', 'density_prior_box',
'round', 'floor', 'ceil', 'precision_recall', 'proximal_adagrad', 'cast',
'isinf', 'isfinite', 'isnan', 'fill_constant', 'fusion_seqpool_cvm_concat',
'accuracy', 'fc', 'sgd', 'anchor_generator',
'fake_channel_wise_quantize_abs_max',
'fake_quantize_dequantize_moving_average_abs_max', 'fake_quantize_abs_max',
'fake_quantize_range_abs_max', 'moving_average_abs_max_scale',
'fake_quantize_moving_average_abs_max', 'fill_any_like', 'one_hot',
'gather_tree', 'lookup_sparse_table', 'lamb', 'fusion_squared_mat_sub',
'range', 'box_decoder_and_assign', 'one_hot_v2', 'shape',
'fusion_transpose_flatten_concat', 'lars_momentum', 'momentum',
'fusion_lstm', 'assign_value', 'polygon_box_transform',
'retinanet_detection_output', 'generate_proposal_labels', 'ctc_align',
'sequence_erase', 'fake_channel_wise_dequantize_max_abs',
'fake_dequantize_max_abs', 'generate_mask_labels', 'elementwise_floordiv',
'sum', 'ftrl', 'fusion_repeated_fc_relu', 'size', 'bipartite_match',
'elementwise_mod', 'multiclass_nms2', 'multiclass_nms', 'fill_zeros_like',
'adadelta', 'conv2d_fusion', 'adamax', 'sampling_id', 'dpsgd',
'target_assign', 'random_crop', 'mean_iou', 'reduce_all', 'reduce_any',
'attention_lstm', 'fusion_seqexpand_concat_fc', 'dequantize_abs_max',
'clip_by_norm', 'diag', 'yolo_box', 'adam', 'fusion_gru',
'locality_aware_nms', 'ref_by_trainer_id', 'linspace', 'box_clip',
'similarity_focus', 'detection_map', 'sequence_mask', 'coalesce_tensor',
'arg_min', 'arg_max', 'split_ids', 'adagrad', 'fill', 'argsort',
'dequantize', 'merge_ids', 'fused_fc_elementwise_layernorm',
'retinanet_target_assign', 'rpn_target_assign', 'requantize',
'distribute_fpn_proposals', 'auc', 'quantize', 'positive_negative_pair',
'hash', 'less_than', 'not_equal', 'eye', 'chunk_eval', 'is_empty',
'proximal_gd', 'collect_fpn_proposals', 'unique_with_counts', 'seed'
]
...@@ -28,7 +28,6 @@ API_FILES=("CMakeLists.txt" ...@@ -28,7 +28,6 @@ API_FILES=("CMakeLists.txt"
"paddle/fluid/operators/distributed/send_recv.proto.in" "paddle/fluid/operators/distributed/send_recv.proto.in"
"paddle/fluid/framework/unused_var_check.cc" "paddle/fluid/framework/unused_var_check.cc"
"python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py" "python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py"
"python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py"
"python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py" "python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py"
) )
...@@ -112,9 +111,6 @@ for API_FILE in ${API_FILES[*]}; do ...@@ -112,9 +111,6 @@ for API_FILE in ${API_FILES[*]}; do
elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py" ];then elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py" ];then
echo_line="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="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"
check_approval 1 9973393 6836917 43953930 check_approval 1 9973393 6836917 43953930
elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py" ];then
echo_line="You must have one RD (zhangting2020 (Recommend), luotao1 or phlrain) approval for the python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py, which manages the white list of operators without gradient. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Gradient-Check-Is-Required-for-Op-Test. \n"
check_approval 1 26615455 6836917 43953930
elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py" ];then elif [ "${API_FILE}" == "python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py" ];then
echo_line="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" echo_line="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"
check_approval 1 52520497 26615455 6836917 check_approval 1 52520497 26615455 6836917
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册