diff --git a/paddle/fluid/operators/sum_mkldnn_op.cc b/paddle/fluid/operators/sum_mkldnn_op.cc index 148366a72ac3bbcbe49776477d8f1b66f9b664c3..f9a16ef35ecb9eeb6c8eda9d124ecb17e7f9d5ce 100644 --- a/paddle/fluid/operators/sum_mkldnn_op.cc +++ b/paddle/fluid/operators/sum_mkldnn_op.cc @@ -187,6 +187,9 @@ class SumMKLDNNOpKernel : public paddle::framework::OpKernel { if (in_dim.empty()) { VLOG(3) << "WARNING: all the inputs are empty"; + in_dim = framework::vectorize(get_selected_row(N - 1).value().dims()); + } else { + in_dim[0] = static_cast(first_dim); } in_dim[0] = static_cast(first_dim); diff --git a/paddle/fluid/operators/sum_op.h b/paddle/fluid/operators/sum_op.h index f1d885b7fd62d07fb3f61000e438c7b6a0f19fab..6dffe527c1072ee97fcde1725bfc1a47ed1ad74a 100644 --- a/paddle/fluid/operators/sum_op.h +++ b/paddle/fluid/operators/sum_op.h @@ -116,10 +116,11 @@ class SumKernel : public framework::OpKernel { } if (in_dim.empty()) { VLOG(3) << "WARNING: all the inputs are empty"; + in_dim = framework::vectorize(get_selected_row(N - 1).value().dims()); + } else { + in_dim[0] = static_cast(first_dim); } - in_dim[0] = static_cast(first_dim); - out_value->Resize(framework::make_ddim(in_dim)); out_value->mutable_data(context.GetPlace());