From 9e29d3ebed59a62366a6197821dd9e39b3255a94 Mon Sep 17 00:00:00 2001 From: huzhiqiang <912790387@qq.com> Date: Tue, 11 Feb 2020 17:38:42 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90OpPorting=20Example=E3=80=91DEMO=20OF?= =?UTF-8?q?=20FIX=20COMPILE&RUNTIME=20LOD=5FEQUALITY=20(#22460)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sequence_ops/sequence_erase_op.cc | 9 ++++++ .../sequence_ops/sequence_reshape_op.cc | 3 ++ .../compile_vs_runtime_white_list.py | 28 ++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc b/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc index ddda80ee082..4343a76b484 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc @@ -32,6 +32,15 @@ class SequenceEraseOp : public framework::OperatorWithKernel { "Input(X) of SequenceEraseOp should be a 2-D LoDTensor " "with the 2nd dimension equal to 1."); ctx->SetOutputDim("Out", x_dims); + // The output LoDTensor's lod_level should be input X's lod_level. + // For compile-time, we call SetLoDLevel to set output's lod_level. + // For runtime, output LoDTensor's lod is determined by input X's lod and + // the level specified by input RandTable. + // We cannot get X's detail lod and RankTable's level in this function, so + // leave this work to the detail kernel implementation. + if (!ctx->IsRuntime()) { + ctx->SetLoDLevel("Out", ctx->GetLoDLevel("X")); + } } }; diff --git a/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc b/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc index e1d8911c32f..60350bd96d1 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc @@ -37,6 +37,9 @@ class SequenceReshapeOp : public framework::OperatorWithKernel { } else { // when compiling, the batch size is undetermined, just set to -1 ctx->SetOutputDim("Out", {-1, static_cast(new_dim)}); + // when compiling, the LodLevel of Out is set to be 1, which is consistent + // with that in running time. + ctx->SetLoDLevel("Out", 1); } } }; 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 index 9aabfb40827..ed7788443a6 100644 --- 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 @@ -19,11 +19,25 @@ # reasons for skipping compile_vs_runtime test or be fixed later. 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', 'multiclass_nms', 'multiclass_nms2', 'im2sequence', - 'generate_proposal_labels', 'distribute_fpn_proposals', 'detection_map', - 'locality_aware_nms', 'var_conv_2d' + 'lod_reset', \ + 'sequence_pool', \ + 'sequence_slice', \ + 'generate_mask_labels', \ + 'generate_proposals', \ + 'mine_hard_examples', \ + 'retinanet_detection_output', \ + 'ctc_align', \ + 'fusion_seqpool_cvm_concat', \ + 'gru', \ + 'rpn_target_assign', \ + 'retinanet_target_assign', \ + 'filter_by_instag', \ + 'multiclass_nms', \ + 'multiclass_nms2', \ + 'im2sequence', \ + 'generate_proposal_labels', \ + 'distribute_fpn_proposals', \ + 'detection_map', \ + 'locality_aware_nms', \ + 'var_conv_2d' ] -- GitLab