From f04f2b232a22c9aba3ee4538ab708acf9f77c813 Mon Sep 17 00:00:00 2001 From: Zhaolong Xing Date: Thu, 26 Sep 2019 13:03:33 +0800 Subject: [PATCH] fix if else error info (#19974) test=develop test=document_fix --- paddle/fluid/operators/merge_lod_tensor_op.cc | 18 ++++++++++++++++-- paddle/fluid/operators/split_lod_tensor_op.cc | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/merge_lod_tensor_op.cc b/paddle/fluid/operators/merge_lod_tensor_op.cc index 6a9d8222c4..67154447d1 100644 --- a/paddle/fluid/operators/merge_lod_tensor_op.cc +++ b/paddle/fluid/operators/merge_lod_tensor_op.cc @@ -190,9 +190,23 @@ class MergeLoDTensorInferShape : public framework::InferShapeBase { "MergeLoDTensorOp must has output Out"); auto mask_dim = context->GetInputDim("Mask"); - PADDLE_ENFORCE_EQ(mask_dim.size(), 2); + PADDLE_ENFORCE_EQ(mask_dim.size(), 2, + "If you are using IfElse OP:" + "\n\nie = fluid.layers.IfElse(cond=cond)\nwith " + "ie.true_block():\n out_1 = ie.input(x)\n\n" + "Please ensure that the cond should be a 2-D tensor and " + "the second dim size of cond should be 1. " + "But now the cond's shape is [", + *mask_dim.Get(), "].\n"); if (context->IsRuntime() || mask_dim[1] > 0) { - PADDLE_ENFORCE_EQ(mask_dim[1], 1); + PADDLE_ENFORCE_EQ(mask_dim[1], 1, + "If you are using IfElse OP:" + "\n\nie = fluid.layers.IfElse(cond=cond)\nwith " + "ie.true_block():\n out_1 = ie.input(x)\n\n" + "Please ensure that the cond should be a 2-D tensor " + "and the second dim size of cond should be 1. " + "But now the cond's shape is [", + *mask_dim.Get(), "].\n"); } context->SetOutputDim("Out", context->GetInputDim("InTrue")); diff --git a/paddle/fluid/operators/split_lod_tensor_op.cc b/paddle/fluid/operators/split_lod_tensor_op.cc index c89e683d76..870adfbaa7 100644 --- a/paddle/fluid/operators/split_lod_tensor_op.cc +++ b/paddle/fluid/operators/split_lod_tensor_op.cc @@ -156,9 +156,23 @@ class SplitLoDTensorInferShape : public framework::InferShapeBase { "SplitLoDTensorOp must has output OutFalse."); auto mask_dim = context->GetInputDim("Mask"); - PADDLE_ENFORCE_EQ(mask_dim.size(), 2); + PADDLE_ENFORCE_EQ(mask_dim.size(), 2, + "If you are using IfElse OP:" + "\n\nie = fluid.layers.IfElse(cond=cond)\nwith " + "ie.true_block():\n out_1 = ie.input(x)\n\n" + "Please ensure that the cond should be a 2-D tensor and " + "the second dim size of cond should be 1. " + "But now the cond's shape is [", + *mask_dim.Get(), "].\n"); if (context->IsRuntime()) { - PADDLE_ENFORCE_EQ(mask_dim[1], 1); + PADDLE_ENFORCE_EQ(mask_dim[1], 1, + "If you are using IfElse OP:" + "\n\nie = fluid.layers.IfElse(cond=cond)\nwith " + "ie.true_block():\n out_1 = ie.input(x)\n\n" + "Please ensure that the cond should be a 2-D tensor " + "and the second dim size of cond should be 1. " + "But now the cond's shape is [", + *mask_dim.Get(), "].\n"); } context->SetOutputDim("OutTrue", context->GetInputDim("X"));