From 76888b0ba143d4aad18a17849fd686bb1ee2a327 Mon Sep 17 00:00:00 2001 From: SunGaofeng Date: Mon, 15 Apr 2019 04:24:56 +0000 Subject: [PATCH] modify in pad_op and pad_constant --- paddle/fluid/operators/pad_constant_like_op.cc | 10 ++++++++-- paddle/fluid/operators/pad_op.cc | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/pad_constant_like_op.cc b/paddle/fluid/operators/pad_constant_like_op.cc index 920383e6522..31ed0a686f7 100644 --- a/paddle/fluid/operators/pad_constant_like_op.cc +++ b/paddle/fluid/operators/pad_constant_like_op.cc @@ -42,7 +42,10 @@ class PadConstantLikeOp : public framework::OperatorWithKernel { if ((!ctx->IsRuntime()) && ((x_dim[i] == -1) || (y_dim[i] == -1))) { continue; } else { - PADDLE_ENFORCE_GE(x_dim[i], y_dim[i]); + PADDLE_ENFORCE_GE( + x_dim[i], y_dim[i], + "expected X_dim[i] >= Y_dim[i], but received %d < %d for dim %d", + x_dim[i], y_dim[i], i); } } @@ -171,7 +174,10 @@ class PadConstantLikeOpGrad : public framework::OperatorWithKernel { if ((!ctx->IsRuntime()) && ((dout_dim[i] == -1) || (y_dim[i] == -1))) { continue; } else { - PADDLE_ENFORCE_GE(dout_dim[i], y_dim[i]); + PADDLE_ENFORCE_GE(dout_dim[i], y_dim[i], + "expected Out_dim[i] >= Y_dim[i], but received %d " + "< %d for dim %d", + dout_dim[i], y_dim[i], i); } } } diff --git a/paddle/fluid/operators/pad_op.cc b/paddle/fluid/operators/pad_op.cc index 4b4f43344f6..36dc8b0dbb3 100644 --- a/paddle/fluid/operators/pad_op.cc +++ b/paddle/fluid/operators/pad_op.cc @@ -34,6 +34,9 @@ class PadOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_EQ(x_dim.size() * 2, int64_t(paddings.size()), "Size of paddings should be equal to 2 * dimension size " "of input tensor."); + for (size_t i = 0; i < paddings.size(); ++i) { + PADDLE_ENFORCE_GE(paddings[i], 0, "paddings should >= 0."); + } std::vector out_dims(x_dim.size()); for (int i = 0; i < x_dim.size(); ++i) { if ((!ctx->IsRuntime()) && (x_dim[i] == -1)) { -- GitLab