From 73e97d39b422763f8c13b5678b6b976183beb064 Mon Sep 17 00:00:00 2001 From: Zhang Ting <709968123@qq.com> Date: Tue, 17 Dec 2019 12:35:10 +0800 Subject: [PATCH] add check for check_grad in Op unittests (#21383) --- .../paddle/fluid/tests/unittests/op_test.py | 14 ++- .../white_list/op_accuracy_white_list.py | 108 ++++++------------ .../white_list/op_check_grad_white_list.py | 86 ++++++++++++++ 3 files changed, 130 insertions(+), 78 deletions(-) create mode 100644 python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 818862ac80b..50f08818c67 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 +from white_list import op_accuracy_white_list, op_check_grad_white_list def _set_use_system_allocator(value=None): @@ -1362,9 +1362,9 @@ class OpTestFp16(OpTestBase): np.random.set_state(cls._np_rand_state) random.setstate(cls._py_rand_state) - if cls.__name__ not in op_accuracy_white_list.NO_NEED_FP16_CHECK_GRAD_CASES \ - and not hasattr(cls, "exist_check_grad") \ - and cls.op_type not in op_accuracy_white_list.NO_FP16_CHECK_GRAD_OP_LIST: + if not hasattr(cls, "exist_check_grad") \ + and cls.__name__ not in op_check_grad_white_list.NO_NEED_CHECK_GRAD_CASES \ + and cls.op_type not in op_check_grad_white_list.EMPTY_GRAD_OP_LIST: raise AssertionError("This test of %s op needs check_grad." % cls.op_type) @@ -1438,8 +1438,12 @@ class OpTest(OpTestBase): np.random.set_state(cls._np_rand_state) random.setstate(cls._py_rand_state) - if cls.__name__ not in op_accuracy_white_list.NO_NEED_FP64_CHECK_GRAD_CASES \ + # only for pass ci, but cases in NO_FP64_CHECK_GRAD_CASES + # and op in NO_FP64_CHECK_GRAD_OP_LIST should be fixed + if cls.__name__ not in op_accuracy_white_list.NO_FP64_CHECK_GRAD_CASES \ and not hasattr(cls, 'exist_fp64_check_grad') \ + and cls.__name__ not in op_check_grad_white_list.NO_NEED_CHECK_GRAD_CASES \ + and cls.op_type not in op_check_grad_white_list.EMPTY_GRAD_OP_LIST \ and cls.op_type not in op_accuracy_white_list.NO_FP64_CHECK_GRAD_OP_LIST: raise AssertionError("This test of %s op needs fp64 check_grad." % cls.op_type) diff --git a/python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py b/python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py index 7408c875004..4cf5d96ec77 100644 --- a/python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py +++ b/python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py @@ -24,81 +24,43 @@ FP16_CHECK_OP_LIST = [ # For op in NO_FP64_CHECK_GRAD_OP_LIST, the op test requires check_grad with fp64 precision NO_FP64_CHECK_GRAD_OP_LIST = [ - 'abs', 'accuracy', 'acos', 'adadelta', 'adagrad', 'adam', 'adamax', - 'add_position_encoding', 'affine_grid', 'anchor_generator', 'arg_max', - 'arg_min', 'argsort', 'asin', 'assign_value', 'atan', 'attention_lstm', - 'auc', 'bilinear_interp', 'bilinear_tensor_product', 'bipartite_match', - 'box_clip', 'box_coder', 'box_decoder_and_assign', 'brelu', 'cast', 'ceil', - 'center_loss', 'chunk_eval', 'clip', 'clip_by_norm', 'coalesce_tensor', - 'collect_fpn_proposals', 'concat', 'conv2d', 'conv2d_fusion', - 'conv2d_transpose', 'conv3d', 'conv3d_transpose', 'conv_shift', 'cos', - 'cos_sim', 'crf_decoding', 'crop', 'crop_tensor', 'cross_entropy', - 'cross_entropy2', 'ctc_align', 'cudnn_lstm', 'cvm', 'data_norm', - 'decayed_adagrad', 'deformable_conv', 'deformable_conv_v1', - 'deformable_psroi_pooling', 'density_prior_box', 'depthwise_conv2d', - 'depthwise_conv2d_transpose', 'dequantize', 'dequantize_abs_max', - 'detection_map', 'diag', 'distribute_fpn_proposals', 'dpsgd', 'dropout', - 'edit_distance', 'elementwise_add', 'elementwise_div', - 'elementwise_floordiv', 'elementwise_max', 'elementwise_min', - 'elementwise_mod', 'elementwise_mul', 'elementwise_pow', 'elementwise_sub', - 'elu', 'equal', 'exp', 'expand', 'eye', - 'fake_channel_wise_dequantize_max_abs', - 'fake_channel_wise_quantize_abs_max', 'fake_dequantize_max_abs', - 'fake_quantize_abs_max', 'fake_quantize_dequantize_moving_average_abs_max', - 'fake_quantize_moving_average_abs_max', 'fake_quantize_range_abs_max', 'fc', - 'fill', 'fill_any_like', 'fill_constant', 'fill_constant_batch_size_like', - 'fill_zeros_like', 'fill_zeros_like2', 'flatten', 'flatten2', 'floor', - 'ftrl', 'fused_elemwise_activation', 'fused_embedding_fc_lstm', - 'fused_embedding_seq_pool', 'fused_fc_elementwise_layernorm', 'fusion_gru', - 'fusion_lstm', 'fusion_repeated_fc_relu', 'fusion_seqconv_eltadd_relu', - 'fusion_seqexpand_concat_fc', 'fusion_seqpool_concat', - 'fusion_seqpool_cvm_concat', 'fusion_squared_mat_sub', - 'fusion_transpose_flatten_concat', 'gather', 'gather_nd', 'gather_tree', - 'gaussian_random_batch_size_like', 'gelu', 'generate_mask_labels', - 'generate_proposal_labels', 'generate_proposals', 'greater_equal', - 'greater_than', 'grid_sampler', 'group_norm', 'hard_shrink', 'hard_sigmoid', - 'hard_swish', 'hash', 'hierarchical_sigmoid', 'hinge_loss', 'huber_loss', - 'im2sequence', 'increment', 'iou_similarity', 'is_empty', 'isfinite', - 'isinf', 'isnan', 'kldiv_loss', 'l1_norm', 'lamb', 'lars_momentum', - 'leaky_relu', 'less_equal', 'less_than', 'linspace', 'locality_aware_nms', - 'lod_reset', 'log', 'log_loss', 'logical_and', 'logical_not', 'logical_or', - 'logical_xor', 'logsigmoid', 'lookup_table', 'lookup_table_v2', 'lrn', + 'abs', 'acos', 'add_position_encoding', 'affine_grid', 'asin', 'atan', + 'bilinear_interp', 'bilinear_tensor_product', 'brelu', 'center_loss', + 'clip', 'concat', 'conv2d', 'conv2d_transpose', 'conv3d', + 'conv3d_transpose', 'conv_shift', 'cos', 'cos_sim', 'crop', 'crop_tensor', + 'cross_entropy', 'cross_entropy2', 'cudnn_lstm', 'cvm', 'data_norm', + 'deformable_conv', 'deformable_conv_v1', 'deformable_psroi_pooling', + 'depthwise_conv2d', 'depthwise_conv2d_transpose', 'dropout', + 'elementwise_add', 'elementwise_div', 'elementwise_max', 'elementwise_min', + 'elementwise_mul', 'elementwise_pow', 'elementwise_sub', 'elu', 'exp', + 'expand', 'flatten', 'flatten2', 'fused_elemwise_activation', + 'fused_embedding_seq_pool', 'gather', 'gather_nd', 'gelu', 'grid_sampler', + 'group_norm', 'hard_shrink', 'hard_sigmoid', 'hard_swish', + 'hierarchical_sigmoid', 'hinge_loss', 'huber_loss', 'im2sequence', + 'increment', 'kldiv_loss', 'l1_norm', 'leaky_relu', 'lod_reset', 'log', + 'log_loss', 'logsigmoid', 'lookup_table', 'lookup_table_v2', 'lrn', 'margin_rank_loss', 'match_matrix_tensor', 'matmul', - 'max_pool2d_with_index', 'max_pool3d_with_index', 'maxout', 'mean', - 'mean_iou', 'merge_ids', 'mine_hard_examples', 'minus', - 'modified_huber_loss', 'momentum', 'moving_average_abs_max_scale', 'mul', - 'multiclass_nms', 'multiclass_nms2', 'multihead_matmul', 'multiplex', 'nce', - 'nearest_interp', 'not_equal', 'one_hot', 'one_hot_v2', 'pad', 'pad2d', - 'pad_constant_like', 'pixel_shuffle', 'polygon_box_transform', 'pool2d', - 'pool3d', 'positive_negative_pair', 'pow', 'precision_recall', 'prelu', - 'prior_box', 'proximal_adagrad', 'proximal_gd', 'prroi_pool', 'psroi_pool', - 'quantize', 'random_crop', 'range', 'rank_loss', 'reciprocal', 'reduce_all', - 'reduce_any', 'reduce_max', 'reduce_min', 'ref_by_trainer_id', 'relu', - 'relu6', 'requantize', 'reshape2', 'retinanet_detection_output', - 'retinanet_target_assign', 'reverse', 'roi_align', - 'roi_perspective_transform', 'roi_pool', 'round', 'row_conv', - 'rpn_target_assign', 'rsqrt', 'sampling_id', 'scale', 'scatter', - 'scatter_nd_add', 'seed', 'selu', 'sequence_concat', 'sequence_conv', - 'sequence_enumerate', 'sequence_erase', 'sequence_expand', - 'sequence_expand_as', 'sequence_mask', 'sequence_pad', 'sequence_pool', - 'sequence_reshape', 'sequence_reverse', 'sequence_scatter', + 'max_pool2d_with_index', 'max_pool3d_with_index', 'maxout', 'mean', 'minus', + 'modified_huber_loss', 'mul', 'multiplex', 'nce', 'nearest_interp', 'pad', + 'pad2d', 'pad_constant_like', 'pixel_shuffle', 'pool2d', 'pool3d', 'pow', + 'prelu', 'prroi_pool', 'psroi_pool', 'rank_loss', 'reciprocal', + 'reduce_max', 'reduce_min', 'relu', 'relu6', 'reshape2', 'reverse', + 'roi_align', 'roi_perspective_transform', 'roi_pool', 'row_conv', 'rsqrt', + 'scale', 'scatter', 'scatter_nd_add', 'seed', 'selu', 'sequence_concat', + 'sequence_conv', 'sequence_expand', 'sequence_expand_as', 'sequence_pad', + 'sequence_pool', 'sequence_reshape', 'sequence_reverse', 'sequence_scatter', 'sequence_slice', 'sequence_softmax', 'sequence_topk_avg_pooling', - 'sequence_unpad', 'sgd', 'shape', 'shard_index', 'shuffle_channel', - 'sigmoid', 'sigmoid_cross_entropy_with_logits', 'sigmoid_focal_loss', - 'sign', 'similarity_focus', 'sin', 'size', 'slice', 'smooth_l1_loss', - 'soft_relu', 'softmax', 'softshrink', 'softsign', 'space_to_depth', - 'spectral_norm', 'split', 'split_ids', 'spp', 'sqrt', 'square', + 'sequence_unpad', 'shuffle_channel', 'sigmoid', + 'sigmoid_cross_entropy_with_logits', 'sigmoid_focal_loss', 'sign', 'sin', + 'slice', 'smooth_l1_loss', 'soft_relu', 'softmax', 'softshrink', 'softsign', + 'space_to_depth', 'spectral_norm', 'split', 'spp', 'sqrt', 'square', 'squared_l2_distance', 'squared_l2_norm', 'squeeze', 'squeeze2', 'stack', - 'stanh', 'strided_slice', 'sum', 'swish', 'tanh', 'tanh_shrink', - 'target_assign', 'teacher_student_sigmoid_loss', 'temporal_shift', - 'thresholded_relu', 'top_k', 'transpose2', 'tree_conv', 'trilinear_interp', - 'unfold', 'uniform_random', 'uniform_random_batch_size_like', 'unique', - 'unique_with_counts', 'unpool', 'unsqueeze', 'unsqueeze2', 'unstack', - 'var_conv_2d', 'warpctc', 'where', 'yolo_box', 'yolov3_loss' + 'stanh', 'strided_slice', 'swish', 'tanh', 'tanh_shrink', + 'teacher_student_sigmoid_loss', 'temporal_shift', 'thresholded_relu', + 'transpose2', 'tree_conv', 'trilinear_interp', 'unfold', 'unpool', + 'unsqueeze', 'unsqueeze2', 'unstack', 'var_conv_2d', 'warpctc', + 'yolov3_loss' ] -NO_NEED_FP64_CHECK_GRAD_CASES = ['TestFSPOp'] - -NO_FP16_CHECK_GRAD_OP_LIST = [] - -NO_NEED_FP16_CHECK_GRAD_CASES = [] +# For cases in NO_FP64_CHECK_GRAD_CASES, the op test requires check_grad with fp64 precision +NO_FP64_CHECK_GRAD_CASES = ['TestFSPOp'] diff --git a/python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py b/python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py new file mode 100644 index 00000000000..869235eca9e --- /dev/null +++ b/python/paddle/fluid/tests/unittests/white_list/op_check_grad_white_list.py @@ -0,0 +1,86 @@ +# 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' +] + +# Special cases do not need to check grad +NO_NEED_CHECK_GRAD_CASES = [ + 'TestLookupTableOpWithPadding', + 'TestLookupTableOpWithTensorIdsAndPadding', + 'TestLookupTableOpWithPadding', + 'TestLookupTableOpWithTensorIdsAndPadding', + 'TestSeqMaxPool2DInference', + 'TestSeqMaxPool2DInferenceLen0', + 'TestSeqMaxPool2DInferenceLen0LoDLevel2', + 'TestDropoutOp4', + 'TestDropoutOp5', + 'TestDropoutOp8', + 'TestDropoutOp9', + 'TestFP16DropoutOp', + 'TestFP16DropoutOp2', + 'TestExpandOpBoolean', + 'TestFusedEmbeddingSeqPoolOp', + 'TestMKLDNNConcatOp', + 'TestMKLDNNConcatOp', + 'TestMKLDNNConcatOp3', + 'TestElementwiseMulMKLDNNOp_Integrated_With_Convs', + 'TestConv2dTransposeMKLDNNOp', + 'TestMKLDNNFuseBias', + 'TestMKLDNNWithPad', + 'TestMKLDNNWithStride', + 'TestMKLDNNWithAsymPad', + 'TestMKLDNNWithSamePad', + 'TestMKLDNNWithValidPad', + 'TestMKLDNNWithValidPad_NHWC', +] -- GitLab