From e26f80ad43cd7715efbc3f624094310b124aac21 Mon Sep 17 00:00:00 2001 From: feifei-111 Date: Tue, 16 Aug 2022 16:35:44 +0800 Subject: [PATCH] Fix problem that the shape of tensor is not inited correctly when backward in static graph (#45030) * fix_shape * code style * fix assert * fix to_tensor badreturn --- paddle/fluid/operators/controlflow/conditional_block_op.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/paddle/fluid/operators/controlflow/conditional_block_op.cc b/paddle/fluid/operators/controlflow/conditional_block_op.cc index f64f3f3935..4aa400afbf 100644 --- a/paddle/fluid/operators/controlflow/conditional_block_op.cc +++ b/paddle/fluid/operators/controlflow/conditional_block_op.cc @@ -255,6 +255,9 @@ class ConditionalBlockGradOp : public ConditionalOp { const auto &input_tensors = input_var->Get(); auto *outside_tensors = outside_var->GetMutable(); + if (outside_tensors->size() == 0U) { + outside_tensors->resize(input_tensors.size()); + } PADDLE_ENFORCE_EQ(input_tensors.size(), outside_tensors->size(), platform::errors::InvalidArgument( -- GitLab