Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[static op generation] pool2d, pool3d #54070

Merged
merged 30 commits into from
Jun 5, 2023

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented May 23, 2023

PR types

Others

PR changes

Others

Description

相关链接

@paddle-bot
Copy link

paddle-bot bot commented May 23, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels May 23, 2023
@paddle-bot
Copy link

paddle-bot bot commented May 23, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

@gouzil gouzil changed the title [static op generation] pool2d [static op generation] pool2d, pool3d May 23, 2023
output : Tensor(out)
infer_meta :
func : Pool2DInferMeta
param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacy中的配置保留

args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
output : Tensor(grad_out_grad)
infer_meta :
func : Pool2DInferMeta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacy中的配置保留

@@ -639,17 +639,6 @@
param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm]
backward : pool2d_double_grad

- backward_op : pool3d_grad
forward : pool3d(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out)
args : (Tensor x, Tensor out, Tensor out_grad, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原始legacy_backward.yaml中的配置不要改动。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

output : Tensor(out)
infer_meta :
func : PoolInferMeta
param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原始legacy_ops.yaml中的配置不要改动。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/cpp/fluid/mkldnn/CMakeLists.txt中的pool_op修改为static_generated_op

@gouzil
Copy link
Member Author

gouzil commented May 25, 2023

这个是需要设置默认值吗还是啥, 在Make里面其实应该是ksize

45: ======================================================================
45: ERROR: test_static (test_adaptive_avg_pool2d.TestOutputSizeTensor)
45: ----------------------------------------------------------------------
45: Traceback (most recent call last):
45:   File "/home/aistudio/git/paddle/build/python/paddle/fluid/tests/unittests/test_adaptive_avg_pool2d.py", line 327, in test_static
45:     out1, out2 = self.call_func(feat)
45:   File "/home/aistudio/git/paddle/build/python/paddle/fluid/tests/unittests/test_adaptive_avg_pool2d.py", line 354, in call_func
45:     out1 = paddle.nn.functional.adaptive_avg_pool2d(x=x, output_size=[3, 3])
45:   File "/home/aistudio/git/paddle/build/python/paddle/nn/functional/pooling.py", line 1653, in adaptive_avg_pool2d
45:     helper.append_op(
45:   File "/home/aistudio/git/paddle/build/python/paddle/fluid/layer_helper.py", line 45, in append_op
45:     return self.main_program.current_block().append_op(*args, **kwargs)
45:   File "/home/aistudio/git/paddle/build/python/paddle/fluid/framework.py", line 4013, in append_op
45:     op = Operator(
45:   File "/home/aistudio/git/paddle/build/python/paddle/fluid/framework.py", line 2988, in __init__
45:     self.desc.check_attrs()
45: ValueError: (InvalidArgument) Attribute (kernel_size) is not set correctly.
45:   [Hint: Expected default_value_setter_.empty() == false, but received default_value_setter_.empty():1 != false:0.] (at /home/aistudio/git/paddle/paddle/fluid/framework/attribute_checker.h:273)
45: 
45: 
45: ----------------------------------------------------------------------
45: Ran 7 tests in 0.031s
45: 
45: FAILED (errors=5)
45: 
45: size : [2, 5]
1/1 Test #45: test_adaptive_avg_pool2d .........***Failed    2.89 sec

@@ -39,7 +39,7 @@ cc_test_old(
test_mkldnn_op_nhwc.cc
DEPS
op_registry
pool_op
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上一个写错了,应该是generated_static_op

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

kernel_size :
data_type : int
tensor_name : Ksize
support_tensor : true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int_array:
    kernel_size :
      data_type : int
      tensor_name : Ksize
      support_tensor : true

--->

int_array:
    kernel_size :
      data_type : int
      support_tensor : true

{x : X}
outputs :
{out : Out}
int_array:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加:

attrs :
  {kernel_size : ksize}

@@ -1775,12 +1775,35 @@

- op : pool2d
backward : pool2d_grad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward : pool2d_grad, pool2d_double_grad

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

get_expected_kernel_type :
pool2d : GetPoolExpectedKernelType
pool2d_grad : GetPoolGradExpectedKernelType
pool2d_double_grad : GetPoolExpectedKernelType
extra :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sig文件不要删除,这里配置

keep_signature : [pool2d, pool2d_grad, pool2d_double_grad]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

get_expected_kernel_type :
pool2d : GetPoolExpectedKernelType
pool2d_grad : GetPoolGradExpectedKernelType
pool2d_double_grad : GetPoolExpectedKernelType
extra :
attrs : [bool use_mkldnn = false, bool use_quantizer = false,
str mkldnn_data_type = "float32", bool is_test = false]

- op : pool3d
backward : pool3d_grad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward : pool3d_grad--> backward : pool3d_grad, pool3d_double_grad

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pool3d没有double_grad只有pool2d

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pool3d没有double_grad只有pool2d

好的,按实际需求配置。

{kernel_size : ksize}
get_expected_kernel_type :
pool3d : GetPoolExpectedKernelType
pool3d_grad : GetPoolGradExpectedKernelType
extra :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sig文件不要删除,这里配置

keep_signature : [pool3d, pool3d_grad, pool3d_double_grad]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不删除的话编译会multiple definitionPR-CI-Inference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不删除的话编译会multiple definitionPR-CI-Inference

pool2d增加对应的设置:

keep_signature : [pool2d, pool2d_grad, pool2d_double_grad]

@gouzil
Copy link
Member Author

gouzil commented May 31, 2023

672: --------------------------------------
672: C++ Traceback (most recent call last):
672: --------------------------------------
672: 0   paddle::framework::OpDesc::InferShape(paddle::framework::BlockDesc const&)
672: 1   std::_Function_handler<void (paddle::framework::InferShapeContext*), paddle::framework::details::OpInfoFiller<paddle::operators::Pool2dDoubleGradInferShapeFunctor, (paddle::framework::details::OpInfoFillType)4>::operator()(char const*, paddle::framework::OpInfo*) const::{lambda(paddle::framework::InferShapeContext*)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::InferShapeContext*&&)
672: 2   paddle::operators::Pool2dDoubleGradInferShapeFunctor::operator()(paddle::framework::InferShapeContext*) const
672: 3   phi::Pool2DInferMeta(phi::MetaTensor const&, paddle::experimental::IntArrayBase<phi::DenseTensor> const&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&, bool, bool, std::string const&, std::string const&, bool, bool, std::string const&, phi::MetaTensor*, phi::MetaConfig)
672: 4   phi::PoolInferMeta(phi::MetaTensor const&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&, bool, bool, std::string const&, std::string const&, bool, bool, std::string const&, phi::MetaTensor*, phi::MetaConfig)
672: 
672: ----------------------
672: Error Message Summary:
672: ----------------------
672: FatalError: `Segmentation fault` is detected by the operating system.
672:   [TimeInfo: *** Aborted at 1685514034 (unix time) try "date -d @1685514034" if you are using GNU date ***]
672:   [SignalInfo: *** SIGSEGV (@0x0) received by PID 28270 (TID 0x7f63da252740) from PID 0 ***]
672: 
672: Segmentation fault
1/1 Test #672: test_nn_grad .....................***Failed    2.90 sec

我 debug 了一下目前定位是paddle/phi/infermeta/unary.cc

void PoolInferMeta(const MetaTensor& x,
......

  out->set_dims(make_ddim(output_shape));   <----- 这里触发的
  out->share_lod(x);
  out->set_dtype(x.dtype());

@@ -55,6 +55,41 @@
param : [x, out_grad]
inplace : (out_grad -> x_grad)

- backward_op : pool2d_double_grad
forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x)
args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是参数问题,这里去掉args中的Tensor x

kernel :
func : pool2d_double_grad
param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm]
no_need_buffer : x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉no_need_buffer

get_expected_kernel_type :
pool3d : GetPoolExpectedKernelType
pool3d_grad : GetPoolGradExpectedKernelType
manual_signature : [pool3d, pool3d_grad]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除manual_signature

pool2d : GetPoolExpectedKernelType
pool2d_grad : GetPoolGradExpectedKernelType
pool2d_double_grad : GetPoolExpectedKernelType
manual_signature : [pool2d, pool2d_grad, pool2d_double_grad]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除manual_signature

@@ -117,6 +131,31 @@ phi::KernelKey GetAssignExpectedKernelType(
ctx.device_context().GetPlace());
}

phi::KernelKey GetPoolExpectedKernelType(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加

phi::KernelKey GetPoolDoubleGradExpectedKernelType(
    const framework::ExecutionContext& ctx,
    const framework::OperatorWithKernel* op_ptr) {
  auto data_type = op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "grad_x@GRAD");

  // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN
  op_ptr->SetDnnFallback(!CanMKLDNNSupportPool(ctx));
  // NOTE(jiahongyu) END: Above codes originally enclosed by PADDLE_WITH_MKLDNN

  return phi::KernelKey(data_type, ctx.GetPlace());
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

phi::KernelKey GetPoolGradExpectedKernelType(
const framework::ExecutionContext& ctx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除这个,逻辑跟GetPoolExpectedKernelType重复

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

get_expected_kernel_type :
pool2d : GetPoolExpectedKernelType
pool2d_grad : GetPoolGradExpectedKernelType
pool2d_double_grad : GetPoolExpectedKernelType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对应修改:

    pool2d : GetPoolExpectedKernelType
    pool2d_grad : GetPoolExpectedKernelType
    pool2d_double_grad : GetPoolDoubleGradExpectedKernelType

get_expected_kernel_type :
pool2d : GetPoolExpectedKernelType
pool2d_grad : GetPoolExpectedKernelType
pool2d_double_grad : GetPoolDoubleGradExpectedKernelType
extra :
attrs : [bool use_mkldnn = false, bool use_quantizer = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加一个[bool use_cudnn = false]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{kernel_size : ksize}
get_expected_kernel_type :
pool3d : GetPoolExpectedKernelType
pool3d_grad : GetPoolExpectedKernelType
extra :
attrs : [bool use_mkldnn = false]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加一个[bool use_cudnn = false]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

…pool2d

# Conflicts:
#	test/cpp/fluid/mkldnn/CMakeLists.txt
…pool2d

# Conflicts:
#	paddle/phi/api/yaml/op_compat.yaml
#	paddle/phi/api/yaml/static_backward.yaml
Copy link
Contributor

@heavyrain-lzy heavyrain-lzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rerun一下相关的CI

Copy link
Contributor

@heavyrain-lzy heavyrain-lzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit 3088164 into PaddlePaddle:develop Jun 5, 2023
@heavyrain-lzy heavyrain-lzy mentioned this pull request Jun 27, 2023
@gouzil gouzil deleted the autogen_code_pool2d branch August 1, 2023 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants