From dc225ed2fcd54fc3dc927169e6f4f6818dc419cc Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Wed, 8 Apr 2020 22:20:30 +0800 Subject: [PATCH] OP (tensor_array_read_write) error message enhancement. test=develop (#23468) --- paddle/fluid/operators/array_operator.h | 9 +++++-- .../controlflow/tensor_array_read_write_op.cc | 24 ++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/paddle/fluid/operators/array_operator.h b/paddle/fluid/operators/array_operator.h index 4309f0a5497..1beff472eca 100644 --- a/paddle/fluid/operators/array_operator.h +++ b/paddle/fluid/operators/array_operator.h @@ -31,9 +31,14 @@ class ArrayOp : public framework::OperatorBase { size_t GetOffset(const framework::Scope &scope, const platform::Place &place) const { auto *i = scope.FindVar(Input("I")); - PADDLE_ENFORCE(i != nullptr, "I must be set"); + PADDLE_ENFORCE_NOT_NULL( + i, platform::errors::NotFound("Input(I) is not found.")); auto &i_tensor = i->Get(); - PADDLE_ENFORCE_EQ(i_tensor.numel(), 1); + PADDLE_ENFORCE_EQ(i_tensor.numel(), 1, + platform::errors::InvalidArgument( + "Input(I) must have numel 1. " + "But received %d, and it's shape is [%s].", + i_tensor.numel(), i_tensor.dims())); // get device context from pool platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); diff --git a/paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc b/paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc index fe9dacb5323..10443f45643 100644 --- a/paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc +++ b/paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc @@ -83,8 +83,7 @@ class WriteToArrayInferShape : public framework::InferShapeBase { void operator()(framework::InferShapeContext *context) const override { PADDLE_ENFORCE_EQ( context->HasInput("I"), true, - platform::errors::InvalidArgument( - "Read/Write array operation must set the subscript index.")); + platform::errors::NotFound("Input(I) of WriteToArrayOp is not found.")); // TODO(wangchaochaohu) control flow Op do not support runtime infer shape // Later we add [ontext->GetInputDim("I")) == 1] check when it's supported @@ -93,11 +92,9 @@ class WriteToArrayInferShape : public framework::InferShapeBase { return; } - PADDLE_ENFORCE_EQ( - context->HasOutput("Out"), true, - platform::errors::InvalidArgument( - "Read/Write array operation must set the output Tensor " - "to get the result.")); + PADDLE_ENFORCE_EQ(context->HasOutput("Out"), true, + platform::errors::NotFound( + "Output(Out) of WriteToArrayOp is not found.")); context->SetOutputDim("Out", context->GetInputDim("X")); // When compile time, we need to: @@ -139,15 +136,14 @@ class ReadFromArrayOp : public ArrayOp { void RunImpl(const framework::Scope &scope, const platform::Place &place) const override { auto *x = scope.FindVar(Input("X")); - PADDLE_ENFORCE_NOT_NULL( - x, - platform::errors::InvalidArgument( - "X(Input Variable) must be set when we call read array operation")); + PADDLE_ENFORCE_NOT_NULL(x, + platform::errors::NotFound( + "Input(X) of ReadFromArrayOp is not found.")); auto &x_array = x->Get(); auto *out = scope.FindVar(Output("Out")); - PADDLE_ENFORCE_NOT_NULL(out, platform::errors::InvalidArgument( - "Out(Output Varibale) must be set when we " - "call read array operation")); + PADDLE_ENFORCE_NOT_NULL( + out, platform::errors::NotFound( + "Output(Out) of ReadFromArrayOp is not found.")); size_t offset = GetOffset(scope, place); if (offset < x_array.size()) { auto *out_tensor = out->GetMutable(); -- GitLab