From 203ac4f38e1e32e75a1977ca4e9c2ed78165fbc8 Mon Sep 17 00:00:00 2001 From: Kqnonrime <36952116+Kqnonrime@users.noreply.github.com> Date: Fri, 23 Apr 2021 10:35:23 +0800 Subject: [PATCH] Fix seven error message (#32397) * fix two error message * fix two error message * fix error * fix error * fix error * fix error * fix some error message * fix some error * fix error * fix some error * fix some error * fix some error * fix one error * fix some error * fix seven error message * fix error * fix error * fix error * fix error --- paddle/fluid/operators/scatter_nd_add_op.cc | 22 +++++++++++++++---- paddle/fluid/operators/scatter_op.cc | 21 +++++++++++++----- .../tests/unittests/test_scatter_nd_op.py | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/operators/scatter_nd_add_op.cc b/paddle/fluid/operators/scatter_nd_add_op.cc index 144e7ceae20..2d23e81717a 100644 --- a/paddle/fluid/operators/scatter_nd_add_op.cc +++ b/paddle/fluid/operators/scatter_nd_add_op.cc @@ -50,10 +50,15 @@ class ScatterNdAddOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_LE( index_dims[index_dims_size - 1], ref_dims_size, platform::errors::InvalidArgument( - "Input(Index).shape[-1] should be no greater than Input(X).rank")); + "The last dimension of Input(Index)'s shape should be no greater " + "than the rank of Input(X), but received the last dimension of " + "Input(Index)'s shape is %d, the rank of Input(X) is %d.", + index_dims[index_dims_size - 1], ref_dims_size)); PADDLE_ENFORCE_GE(index_dims_size, 2UL, platform::errors::InvalidArgument( - "The rank of Input(Index) should be greater than 1")); + "The rank of Input(Index) should be greater than 1, " + "but received the rank of Input(Index) is %d.", + index_dims_size)); // update.shape = index.shape[:-1] + output.shape[index.shape[-1]:] std::vector r_updates_dims; @@ -66,12 +71,21 @@ class ScatterNdAddOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_EQ( r_updates_dims.size(), updates_dims_size, - platform::errors::InvalidArgument("Updates has wrong shape")); + platform::errors::InvalidArgument( + "Updates has wrong shape. The shape of Updates and Input(Updates) " + "should be same, but received the shape of Updates is %d, " + "the shape of Input(Updates) is %d.", + r_updates_dims.size(), updates_dims_size)); for (int64_t i = 0; i < updates_dims_size; ++i) { PADDLE_ENFORCE_EQ( r_updates_dims[i], updates_dims[i], - platform::errors::InvalidArgument("Updates has wrong shape")); + platform::errors::InvalidArgument( + "Updates has wrong shape. The dimensions of Updates and " + "Input(Updates) should match, but received Updates's" + "%d-th dimension is %d, Input(Updates)'s %d-th " + "dimension is %d.", + i, r_updates_dims[i], i, updates_dims[i])); } ctx->SetOutputDim("Out", ref_dims); ctx->ShareLoD("X", /*->*/ "Out"); diff --git a/paddle/fluid/operators/scatter_op.cc b/paddle/fluid/operators/scatter_op.cc index 3fc40d41c30..f0faa0c5798 100644 --- a/paddle/fluid/operators/scatter_op.cc +++ b/paddle/fluid/operators/scatter_op.cc @@ -41,15 +41,24 @@ class ScatterOp : public framework::OperatorWithKernel { auto ref_dims = ctx->GetInputDim("X"); PADDLE_ENFORCE_EQ( ctx->GetInputDim("Ids").size(), 1, - platform::errors::InvalidArgument("Update Ids should be 1-D.")); + platform::errors::InvalidArgument( + "The size of Input(Ids)'s shape should be equal to 1, but " + "received the rank of Input(Ids) is %d.", + ctx->GetInputDim("Ids").size())); PADDLE_ENFORCE_EQ( ref_dims.size(), updates_dims.size(), platform::errors::InvalidArgument( - "Rerence and Updates should have the same shape size.")); - PADDLE_ENFORCE_EQ(ctx->GetInputDim("Updates")[0], - ctx->GetInputDim("Ids")[0], - platform::errors::InvalidArgument( - "Updates and Ids should have same batch-size.")); + "Input(X) and Input(Updates) should have the same shape size, " + "but received the size of Input(x)'s shape is %d, the size of " + "Input(Updates)'s shape is %d.", + ref_dims.size(), updates_dims.size())); + PADDLE_ENFORCE_EQ( + ctx->GetInputDim("Updates")[0], ctx->GetInputDim("Ids")[0], + platform::errors::InvalidArgument( + "Input(Updates) and Input(Ids) should have same batch-size, but" + " received Input(Updates)'s batch-size is %d, Input(Ids)'s " + "batch-size is %d.", + ctx->GetInputDim("Updates")[0], ctx->GetInputDim("Ids")[0])); ctx->SetOutputDim("Out", ref_dims); ctx->ShareLoD("X", /*->*/ "Out"); } diff --git a/python/paddle/fluid/tests/unittests/test_scatter_nd_op.py b/python/paddle/fluid/tests/unittests/test_scatter_nd_op.py index 35bb4487c6a..59d1ede5a0b 100644 --- a/python/paddle/fluid/tests/unittests/test_scatter_nd_op.py +++ b/python/paddle/fluid/tests/unittests/test_scatter_nd_op.py @@ -242,7 +242,7 @@ class TestScatterNdOpRaise(unittest.TestCase): output5 = fluid.layers.scatter_nd_add(ref5, index5, updates5) except Exception as e: t = \ - "Input(Index).shape[-1] should be no greater than Input(X).rank" + "The last dimension of Input(Index)'s shape should be no greater " if t in str(e): raise IndexError -- GitLab