diff --git a/paddle/fluid/operators/scatter_nd_add_op.cc b/paddle/fluid/operators/scatter_nd_add_op.cc index 144e7ceae20c1665e5ebd80a8e090f14faf70321..2d23e81717abb8653dff0ec78942676339dc52e7 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 3fc40d41c308177b6bd6f4355f23870d38257fd4..f0faa0c57983393fbfed4dc5e21b2a9742f51668 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 35bb4487c6aaee84c9e5c6691b4e3d5ec2f5ae07..59d1ede5a0b534fa726722ccf021bafeb2a313f8 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