-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
❌ The PR is not created using PR's template. You can refer to this Demo. |
paddle/phi/api/yaml/legacy_ops.yaml
Outdated
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] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原始legacy_backward.yaml
中的配置不要改动。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/phi/api/yaml/legacy_ops.yaml
Outdated
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原始legacy_ops.yaml
中的配置不要改动。
There was a problem hiding this comment.
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
这个是需要设置默认值吗还是啥, 在 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上一个写错了,应该是generated_static_op
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加:
attrs :
{kernel_size : ksize}
paddle/phi/api/yaml/op_compat.yaml
Outdated
@@ -1775,12 +1775,35 @@ | |||
|
|||
- op : pool2d | |||
backward : pool2d_grad |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 : |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pool3d
没有double_grad
只有pool2d
有
There was a problem hiding this comment.
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 : |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不删除的话编译会multiple definition
PR-CI-Inference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不删除的话编译会
multiple definition
PR-CI-Inference
pool2d增加对应的设置:
keep_signature : [pool2d, pool2d_grad, pool2d_double_grad]
…pool2d # Conflicts: # paddle/phi/api/yaml/static_backward.yaml
…il/Paddle into autogen_code_pool2d # Conflicts: # paddle/phi/api/yaml/static_backward.yaml
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 了一下目前定位是 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉no_need_buffer
paddle/phi/api/yaml/op_compat.yaml
Outdated
get_expected_kernel_type : | ||
pool3d : GetPoolExpectedKernelType | ||
pool3d_grad : GetPoolGradExpectedKernelType | ||
manual_signature : [pool3d, pool3d_grad] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除manual_signature
paddle/phi/api/yaml/op_compat.yaml
Outdated
pool2d : GetPoolExpectedKernelType | ||
pool2d_grad : GetPoolGradExpectedKernelType | ||
pool2d_double_grad : GetPoolExpectedKernelType | ||
manual_signature : [pool2d, pool2d_grad, pool2d_double_grad] |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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());
}
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除这个,逻辑跟GetPoolExpectedKernelType
重复
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/phi/api/yaml/op_compat.yaml
Outdated
get_expected_kernel_type : | ||
pool2d : GetPoolExpectedKernelType | ||
pool2d_grad : GetPoolGradExpectedKernelType | ||
pool2d_double_grad : GetPoolExpectedKernelType |
There was a problem hiding this comment.
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
…pool2d # Conflicts: # paddle/fluid/operators/generator/get_expected_kernel_func.cc
get_expected_kernel_type : | ||
pool2d : GetPoolExpectedKernelType | ||
pool2d_grad : GetPoolExpectedKernelType | ||
pool2d_double_grad : GetPoolDoubleGradExpectedKernelType | ||
extra : | ||
attrs : [bool use_mkldnn = false, bool use_quantizer = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加一个[bool use_cudnn = false]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/phi/api/yaml/op_compat.yaml
Outdated
{kernel_size : ksize} | ||
get_expected_kernel_type : | ||
pool3d : GetPoolExpectedKernelType | ||
pool3d_grad : GetPoolExpectedKernelType | ||
extra : | ||
attrs : [bool use_mkldnn = false] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加一个[bool use_cudnn = false]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rerun一下相关的CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
Others
Description
相关链接