Skip to content

Commit 92f4a52

Browse files
authored
【cherry-pick】 fix fill_constant shape with -1 and enhance cross_entropy test=release/1.6 (#20722) (#20728)
1 parent 9e55291 commit 92f4a52

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

paddle/fluid/operators/cross_entropy_op.cc

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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)