From 1458cc0c68b12996c6e23a3d804810a8b0bc0c68 Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Sun, 28 Jun 2020 21:32:32 +0800 Subject: [PATCH] Fix bug: Don't check dims if contain_unknown_dim of cross_entropy_grad_op in compile time (#25221) --- paddle/fluid/operators/cross_entropy_op.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/operators/cross_entropy_op.cc b/paddle/fluid/operators/cross_entropy_op.cc index ca24261bcc8..2ea15c85f33 100644 --- a/paddle/fluid/operators/cross_entropy_op.cc +++ b/paddle/fluid/operators/cross_entropy_op.cc @@ -145,11 +145,10 @@ class CrossEntropyGradientOpBase : public framework::OperatorWithKernel { "But received: Y@Grad's rank is [%d], Y's rank is [%d]", dy_dims.size(), label_dims.size())); - bool check = true; - if ((!ctx->IsRuntime()) && - (framework::product(x_dims) <= 0 || framework::product(dy_dims) <= 0)) { - check = false; - } + bool contain_unknown_dim = framework::contain_unknown_dim(x_dims) || + framework::contain_unknown_dim(dy_dims); + + bool check = ctx->IsRuntime() || !contain_unknown_dim; if (check) { PADDLE_ENFORCE_EQ( -- GitLab