From ed57237ea9b18c56f3792c9e51f9c27c6c856bc2 Mon Sep 17 00:00:00 2001 From: shangliang Xu Date: Mon, 22 Aug 2022 15:51:39 +0800 Subject: [PATCH] fix infershape in compile time (#45156) --- paddle/phi/infermeta/unary.cc | 5 ++++- paddle/phi/kernels/funcs/unfold_functor.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index f8798982581..c0b6c2b0e22 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -3872,6 +3872,7 @@ void UnfoldInferMeta(const MetaTensor& x, paddings[1], paddings[3], strides[1]); + int output_col_length = output_height * output_width; if (config.is_runtime) { // only check output height and width in runtime PADDLE_ENFORCE_GT( @@ -3910,8 +3911,10 @@ void UnfoldInferMeta(const MetaTensor& x, dilations[1], output_height, output_width)); + } else { + output_col_length = + output_height == -1 || output_width == -1 ? -1 : output_col_length; } - int output_col_length = output_height * output_width; out_dims.push_back(output_col_length); out->set_dims(phi::make_ddim(out_dims)); } diff --git a/paddle/phi/kernels/funcs/unfold_functor.h b/paddle/phi/kernels/funcs/unfold_functor.h index 2bd5437a7f1..5a32bf4a343 100644 --- a/paddle/phi/kernels/funcs/unfold_functor.h +++ b/paddle/phi/kernels/funcs/unfold_functor.h @@ -26,7 +26,7 @@ inline int CalcOutputSize(int input_size, int stride) { const int dkernel = dilation * (filter_size - 1) + 1; int output_size = (input_size + padding1 + padding2 - dkernel) / stride + 1; - return output_size; + return input_size == -1 ? -1 : output_size; } } // namespace funcs -- GitLab