From 9219495c02d01643ad212aa36bea82cde567123e Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Wed, 30 Mar 2022 10:33:28 +0800 Subject: [PATCH] [Phi]fix pad3d infermeta bug (#41020) * fix pad3d infermeta bug * add check for construct ScalarArray --- paddle/fluid/framework/infershape_utils.cc | 8 ++++++++ paddle/phi/infermeta/unary.cc | 1 + 2 files changed, 9 insertions(+) diff --git a/paddle/fluid/framework/infershape_utils.cc b/paddle/fluid/framework/infershape_utils.cc index 1b6f5c6535f..cb34c52e526 100644 --- a/paddle/fluid/framework/infershape_utils.cc +++ b/paddle/fluid/framework/infershape_utils.cc @@ -397,6 +397,14 @@ phi::InferMetaContext BuildInferMetaContext(InferShapeContext* ctx, for (size_t i = 0; i < tensor_dims.size(); ++i) { num_ele *= tensor_dims[i]; } + + if (num_ele <= 0) { + PADDLE_THROW(platform::errors::Unimplemented( + "Invalid number for construct phi::ScalarArray, expected " + "number > 0, but actually is %d. ", + num_ele)); + } + } else { num_ele = vars.size(); } diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index fc1554f9a6c..9761f902c70 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -1116,6 +1116,7 @@ void Pad3dInferMeta(const MetaTensor& x, out_dims[1] = x_dim[1]; out_dims[2] = x_dim[2]; out_dims[3] = x_dim[3]; + out_dims[4] = x_dim[4]; } else { auto paddings = paddings_scalar_array.GetData(); -- GitLab