From 7c17ed57e0e3fcd0fce224a8136d58c40b0df9c0 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Wed, 13 May 2020 11:30:37 +0800 Subject: [PATCH] Refine `squared_l2_distance_grad` error message (#24409) test=develop --- .../fluid/operators/squared_l2_distance_op.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/squared_l2_distance_op.h b/paddle/fluid/operators/squared_l2_distance_op.h index 12a8f05b5a6..b8735a69c4b 100644 --- a/paddle/fluid/operators/squared_l2_distance_op.h +++ b/paddle/fluid/operators/squared_l2_distance_op.h @@ -77,8 +77,16 @@ class SquaredL2DistanceGradKernel : public framework::OpKernel { auto* x_g = context.Output(framework::GradVarName("X")); auto* y_g = context.Output(framework::GradVarName("Y")); - PADDLE_ENFORCE_NOT_NULL(x_g); - PADDLE_ENFORCE_NOT_NULL(y_g); + PADDLE_ENFORCE_NOT_NULL( + x_g, platform::errors::NotFound( + "variable(%s) cannot be found " + "in scope for operator 'squared_l2_distance_grad'.", + framework::GradVarName("X"))); + PADDLE_ENFORCE_NOT_NULL( + y_g, platform::errors::NotFound( + "variable(%s) cannot be found " + "in scope for operator 'squared_l2_distance_grad'.", + framework::GradVarName("Y"))); auto sub_result = EigenMatrix::From(*in0); auto out_grad = EigenMatrix::From(*in1); @@ -106,8 +114,11 @@ class SquaredL2DistanceGradKernel : public framework::OpKernel { y_g->mutable_data(context.GetPlace()); PADDLE_ENFORCE_GE(sub_result.dimensions()[0], y_dims[0], - "First dimension of gradient must be greater or " - "equal than first dimension of target."); + platform::errors::InvalidArgument( + "First dimension of gradient must be greater or " + "equal than first dimension of target. But received " + "gradient dimension = %d and target dimension is %d.", + sub_result.dimensions()[0], y_dims[0])); if (sub_result.dimensions()[0] == y_dims[0]) { auto y_grad = -- GitLab