Skip to content

Commit 74a28f5

Browse files
authored
fix fill_constant shape with -1 and enhance cross_entropy test=develop (#20722)
1 parent 48a774c commit 74a28f5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

paddle/fluid/operators/cross_entropy_op.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class CrossEntropyGradientOpBase : public framework::OperatorWithKernel {
136136
"Input(Y@Grad) and Input(Y) should have the same rank.");
137137

138138
bool check = true;
139-
if ((!ctx->IsRuntime()) && (framework::product(x_dims) <= 0 ||
140-
framework::product(label_dims) <= 0)) {
139+
if ((!ctx->IsRuntime()) &&
140+
(framework::product(x_dims) <= 0 || framework::product(dy_dims) <= 0)) {
141141
check = false;
142142
}
143143

python/paddle/fluid/backward.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ def calc_gradient(targets, inputs, target_gradients=None, no_grad_set=None):
12511251
op_desc = _create_op_desc_("fill_constant",
12521252
{"ShapeTensor": [target_shape.name]},
12531253
{"Out": [grad_name]}, {
1254-
"shape": [],
1254+
"shape": target.shape,
12551255
"value": 1.0,
12561256
"dtype": target.dtype,
12571257
})

0 commit comments

Comments
 (0)