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

[phi] Move sequence_pool to phi - Step 3 :sequence_pool_grad_op #52680

Merged
merged 29 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2356517
[phi] move sequence_pool kernel to phi
gouzil Apr 2, 2023
cc3d41f
mv kernels impl
gouzil Apr 2, 2023
38af314
fix parameter error
gouzil Apr 3, 2023
00ddd3f
Merge branch 'develop' of github.com:gouzil/Paddle into move_sequence…
gouzil Apr 3, 2023
3fd8944
clean include
gouzil Apr 3, 2023
279c02a
fix compat filename
gouzil Apr 3, 2023
314af78
[phi] move fluid sequence_pool_grad to phi
gouzil Apr 4, 2023
e1b4fe3
[phi][compat] sig rm GradVarName
gouzil Apr 4, 2023
5245e08
Merge branch 'develop' of github.com:gouzil/Paddle into move_sequence…
gouzil Apr 4, 2023
720e105
[phi] fix sequence_pool out type
gouzil Apr 4, 2023
4f5ca20
[phi] rm impl, add const string
gouzil Apr 5, 2023
55b6592
[phi] fix const str
gouzil Apr 5, 2023
b22dc4b
fix sequence_pooling cmake
gouzil Apr 7, 2023
dd0af52
[phi] mv sequence_pooling_test
gouzil Apr 8, 2023
1a4e47f
Merge branch 'develop' of github.com:gouzil/Paddle into move_sequence…
gouzil Apr 8, 2023
d2e10ac
[phi] fix grad sig
gouzil Apr 8, 2023
c51b9d3
[phi] fix sequence_pool is_test error
gouzil Apr 8, 2023
eb38862
[phi] fix sequence_pooling gpu include
gouzil Apr 8, 2023
295dbbf
[phi] mv to impl
gouzil Apr 9, 2023
554361a
[phi] fix SequencePoolFunctor cu include
gouzil Apr 9, 2023
23b560a
Merge branch 'develop' of github.com:gouzil/Paddle into move_sequence…
gouzil Apr 13, 2023
6161252
Merge branch 'develop' of github.com:gouzil/Paddle into move_sequence…
gouzil Apr 14, 2023
cee77c3
[phi] modify out max_index int32_t
gouzil Apr 15, 2023
8b1cb69
Merge branches 'move_sequence_pool' and 'develop' of github.com:gouzi…
gouzil Apr 23, 2023
f5815bb
[phi] add pooltype mapping determine
gouzil Apr 24, 2023
56fb9e8
[phi] fix sequence_pool_sig
gouzil Apr 25, 2023
8f059d7
[phi] fix sequence_pool_sig sum
gouzil Apr 25, 2023
edfafaf
[phi] try ci
gouzil Apr 25, 2023
fee21b2
[phi] fix max_index optional
gouzil Apr 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion paddle/fluid/operators/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ math_library(sample_prob)
math_library(sampler DEPS generator)

# math_library(math_function DEPS blas dense_tensor tensor)

if(WITH_XPU)
math_library(beam_search DEPS math_function beam_search_xpu)
else()
Expand Down
12 changes: 1 addition & 11 deletions paddle/fluid/operators/sequence_ops/sequence_pool_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/operators/sequence_ops/sequence_pool_op.h"

#include <memory>
#include <string>
#include "paddle/fluid/framework/op_registry.h"

namespace paddle {
namespace operators {
Expand Down Expand Up @@ -196,10 +193,3 @@ REGISTER_OPERATOR(sequence_pool,
REGISTER_OPERATOR(sequence_pool_grad,
ops::SequencePoolGradOp,
ops::SequencePoolGradOpNoNeedBufferVarsInferer);

PD_REGISTER_STRUCT_KERNEL(sequence_pool_grad,
CPU,
ALL_LAYOUT,
ops::SequencePoolGradKernel,
float,
double) {}
49 changes: 0 additions & 49 deletions paddle/fluid/operators/sequence_ops/sequence_pool_op.h

This file was deleted.

1 change: 0 additions & 1 deletion paddle/fluid/operators/sequence_ops/unity_build_rule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ register_unity_group(
sequence_expand_op.cu
sequence_mask_op.cu
sequence_pad_op.cu
sequence_pool_op.cu
sequence_expand_as_op.cu
sequence_reshape_op.cu
sequence_reverse_op.cu
Expand Down
26 changes: 26 additions & 0 deletions paddle/phi/kernels/cpu/sequence_pool_grad_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/phi/kernels/sequence_pool_grad_kernel.h"

#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/sequence_pool_grad_kernel_impl.h"

PD_REGISTER_KERNEL(sequence_pool_grad,
CPU,
ALL_LAYOUT,
phi::SequencePoolGradKernel,
float,
double) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -11,8 +11,12 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/sequence_ops/sequence_pool_op.h"

namespace ops = paddle::operators;
PD_REGISTER_STRUCT_KERNEL(
sequence_pool_grad, GPU, ALL_LAYOUT, ops::SequencePoolGradKernel, float) {}
#include "paddle/phi/kernels/sequence_pool_grad_kernel.h"
#include "paddle/phi/kernels/impl/sequence_pool_grad_kernel_impl.h"

#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(
sequence_pool_grad, GPU, ALL_LAYOUT, phi::SequencePoolGradKernel, float) {}
39 changes: 39 additions & 0 deletions paddle/phi/kernels/impl/sequence_pool_grad_kernel_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include "paddle/phi/kernels/funcs/sequence_pooling.h"

namespace phi {

template <typename T, typename Context>
void SequencePoolGradKernel(const Context& dev_ctx,
const DenseTensor& x,
const paddle::optional<DenseTensor>& max_index,
const DenseTensor& out_grad,
bool is_test,
const std::string& pooltype,
float pad_value,
DenseTensor* x_grad) {
const phi::DenseTensor* index = nullptr;
if (pooltype == "MAX") {
index = max_index.get_ptr();
}
dev_ctx.template Alloc<T>(x_grad);
phi::funcs::SequencePoolGradFunctor<Context, T> pool;
pool(dev_ctx, pooltype, out_grad, x_grad, index);
}

} // namespace phi
2 changes: 1 addition & 1 deletion paddle/phi/kernels/impl/sequence_pool_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void SequencePoolKernel(const Context& ctx,
(is_test == false || (ctx.GetPlace() == phi::CPUPlace()) == false)) {
index = max_index;
index->Resize({dims});
ctx.template Alloc<int>(index);
ctx.template Alloc<int32_t>(index);
}
phi::funcs::SequencePoolFunctor<Context, T> pool;
pool(ctx, pooltype, pad_value_, x, out, is_test, index);
Expand Down
30 changes: 30 additions & 0 deletions paddle/phi/kernels/sequence_pool_grad_kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include "paddle/phi/core/dense_tensor.h"

namespace phi {
template <typename T, typename Context>
void SequencePoolGradKernel(const Context& dev_ctx,
const DenseTensor& x,
const paddle::optional<DenseTensor>& max_index,
const DenseTensor& out_grad,
bool is_test,
const std::string& pooltype,
float pad_value,
DenseTensor* x_grad);

} // namespace phi
10 changes: 10 additions & 0 deletions paddle/phi/ops/compat/sequence_pool_sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ KernelSignature SequencePoolOpArgumentMapping(
{"Out", "MaxIndex"});
}

KernelSignature SequencePoolGradOpArgumentMapping(
const ArgumentMappingContext& ctx) {
return KernelSignature("sequence_pool_grad",
Copy link
Contributor

Choose a reason for hiding this comment

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

需要根据pooltype属性判断是否映射MaxIndex输入,可以参考下batch_norm_sig.cc

Copy link
Member Author

Choose a reason for hiding this comment

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

还是不行, 而且他是挂在pooltype = SUM的时候,而不是MAX的时候

UpdateCTestConfiguration  from :/Users/gouzi/Documents/git/Paddle/build-mac/DartConfiguration.tcl
UpdateCTestConfiguration  from :/Users/gouzi/Documents/git/Paddle/build-mac/DartConfiguration.tcl
Test project /Users/gouzi/Documents/git/Paddle/build-mac
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 773
    Start 773: test_regularizer

773: Test command: /Applications/CMake.app/Contents/bin/cmake "-E" "env" "PYTHONPATH=/Users/gouzi/Documents/git/Paddle/build-mac/python" "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/bin/python3.10" "/Users/gouzi/Documents/git/Paddle/tools/test_runner.py" "test_regularizer"
773: Working Directory: /Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests
773: Test timeout computed to be: 150
773: I0424 22:22:26.906788 137655808 interpretercore.cc:267] New Executor is Running.
773: I0424 22:22:26.986169 137655808 interpreter_util.cc:481] Standalone Executor is Used.
773: SequencePoolGradKernel start========
773: pooltype========: SUM
773: in_w: 8
773: out_pos: 0x7faf70270000
773: sizeof out_pos: 8
773: *out_pos: -0.324429
773: sizeof *out_pos: 4
773: in_pos: 0x7faf9830c000
773: sizeof in_pos: 8
773: *in_pos: 1.58627e-42
773: sizeof *in_pos: 4
773: h:10
773: start for VCOPY=====
773: (*in_pos + r * in_w)): 1.58627e-42
773: r: 0
773: (*in_pos + r * in_w)): 7.67557
773: r: 1
773: (*in_pos + r * in_w)): 15.6756
773: r: 2
773: (*in_pos + r * in_w)): 23.6756
773: r: 3
773: (*in_pos + r * in_w)): 31.6756
773: r: 4
773: (*in_pos + r * in_w)): 39.6756
773: r: 5
773: (*in_pos + r * in_w)): 47.6756
773: r: 6
773: (*in_pos + r * in_w)): 55.6756
773: r: 7
773: (*in_pos + r * in_w)): 63.6756
773: r: 8
773: (*in_pos + r * in_w)): 71.6756
773: r: 9
773: end for VCOPY=====
773: SequencePoolGradKernel end===========
773: W0424 22:22:26.994132 84086784 interpretercore.cc:1024] sequence_pool_grad raises an exception std::bad_alloc, std::bad_alloc
773: test_regularizer failed
773:  ..E.
773: ======================================================================
773: ERROR: test_l2 (test_regularizer.TestRegularizer)
773: ----------------------------------------------------------------------
773: Traceback (most recent call last):
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer.py", line 252, in test_l2
773:     framework_l2 = self.check_l2decay_regularizer(place, model)
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer.py", line 214, in check_l2decay_regularizer
773:     param_sum = self.run_program(place, [data, label])
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer.py", line 184, in run_program
773:     out = exe.run(
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1426, in run
773:     res = self._run_impl(
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1658, in _run_impl
773:     ret = new_exe.run(
773:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 654, in run
773:     tensors = self._new_exe.run(
773: RuntimeError: std::exception
773:
773: ----------------------------------------------------------------------
773: Ran 4 tests in 0.240s
773:
773: FAILED (errors=1)
773:
1/2 Test #773: test_regularizer .................***Failed    2.19 sec
test 774
    Start 774: test_regularizer_api

774: Test command: /Applications/CMake.app/Contents/bin/cmake "-E" "env" "PYTHONPATH=/Users/gouzi/Documents/git/Paddle/build-mac/python" "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/bin/python3.10" "/Users/gouzi/Documents/git/Paddle/tools/test_runner.py" "test_regularizer_api"
774: Working Directory: /Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests
774: Test timeout computed to be: 150
774: I0424 22:22:29.102022 401069568 interpretercore.cc:267] New Executor is Running.
774: I0424 22:22:29.159552 401069568 interpreter_util.cc:481] Standalone Executor is Used.
774: SequencePoolGradKernel start========
774: pooltype========: SUM
774: in_w: 8
774: out_pos: 0x7f8542415000
774: sizeof out_pos: 8
774: *out_pos: -0.260606
774: sizeof *out_pos: 4
774: in_pos: 0x7f8520b25000
774: sizeof in_pos: 8
774: *in_pos: 2.76063e+20
774: sizeof *in_pos: 4
774: h:10
773: start for VCOPY=====
774: (*in_pos + r * in_w)): 2.76063e+20
774: r: 0
774: (*in_pos + r * in_w)): 7.73939
774: r: 1
774: (*in_pos + r * in_w)): 15.7394
774: r: 2
774: (*in_pos + r * in_w)): 23.7394
774: r: 3
774: (*in_pos + r * in_w)): 31.7394
774: r: 4
774: (*in_pos + r * in_w)): 39.7394
774: r: 5
774: (*in_pos + r * in_w)): 47.7394
774: r: 6
774: (*in_pos + r * in_w)): 55.7394
774: r: 7
774: (*in_pos + r * in_w)): 63.7394
774: r: 8
774: (*in_pos + r * in_w)): 71.7394
774: r: 9
773: end for VCOPY=====
774: SequencePoolGradKernel end===========
774: W0424 22:22:29.166538 179060736 interpretercore.cc:1024] sequence_pool_grad raises an exception std::bad_alloc, std::bad_alloc
774: test_regularizer_api failed
774:  E.
774: ======================================================================
774: ERROR: test_l2 (test_regularizer_api.TestRegularizer)
774: ----------------------------------------------------------------------
774: Traceback (most recent call last):
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer_api.py", line 163, in test_l2
774:     framework_l2 = self.check_l2decay_regularizer(place, model)
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer_api.py", line 124, in check_l2decay_regularizer
774:     param_sum = self.run_program(place, [data, label])
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/tests/unittests/test_regularizer_api.py", line 93, in run_program
774:     out = exe.run(
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1426, in run
774:     res = self._run_impl(
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1658, in _run_impl
774:     ret = new_exe.run(
774:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 654, in run
774:     tensors = self._new_exe.run(
774: RuntimeError: std::exception
774:
774: ----------------------------------------------------------------------
774: Ran 2 tests in 0.184s
774:
774: FAILED (errors=1)
774:
2/2 Test #774: test_regularizer_api .............***Failed    2.17 sec

0% tests passed, 2 tests failed out of 2

Total Test time (real) =   4.64 sec

The following tests FAILED:
	773 - test_regularizer (Failed)
	774 - test_regularizer_api (Failed)
Errors while running CTest
Output from these tests are in: /Users/gouzi/Documents/git/Paddle/build-mac/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

有个问题是我在PR-CI-Mac-Python3上看到这个test_sequence_pool这个是挂的,但是我本地是不会挂的

Copy link
Contributor

Choose a reason for hiding this comment

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

sig参数映射需要与OPMaker对齐,仅在pooltypeMAX时映射MaxIndex输入,包括SUM在内的其它情况均没有MaxIndex输入。你现在的sig判断逻辑与OpMaker并不一致,且SUM被拼错成SUN

  void Apply(GradOpPtr<T> op_desc_ptr) const override {
    op_desc_ptr->SetType("sequence_pool_grad");
    op_desc_ptr->SetInput("X", this->Input("X"));
    if (PADDLE_GET_CONST(std::string, this->GetAttr("pooltype")) == "MAX") {
      op_desc_ptr->SetInput("MaxIndex", this->Output("MaxIndex"));
    }
    op_desc_ptr->SetInput(framework::GradVarName("Out"),
                          this->OutputGrad("Out"));
    op_desc_ptr->SetOutput(framework::GradVarName("X"), this->InputGrad("X"));
    op_desc_ptr->SetAttrMap(this->Attrs());
  }

Copy link
Member Author

Choose a reason for hiding this comment

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

为什么SUM也需要3个input

1593: test_sequence_pool failed
1593:  E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.......E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.
1593: ======================================================================
1593: ERROR: test_check_grad (test_sequence_pool.TestSeqAvgPool)
1593: ----------------------------------------------------------------------
1593: Traceback (most recent call last):
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/test_sequence_pool.py", line 105, in test_check_grad
1593:     self.check_grad(["X"], "Out", check_dygraph=False)
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2306, in check_grad
1593:     self.check_grad_with_place(
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2465, in check_grad_with_place
1593:     analytic_grads = self._get_gradient(
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2792, in _get_gradient
1593:     executor.run(
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1426, in run
1593:     res = self._run_impl(
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 1658, in _run_impl
1593:     ret = new_exe.run(
1593:   File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/executor.py", line 654, in run
1593:     tensors = self._new_exe.run(
1593: ValueError: In user code:
1593:
1593:     File "/Users/gouzi/Documents/git/Paddle/tools/test_runner.py", line 70, in <module>
1593:       main()
1593:     File "/Users/gouzi/Documents/git/Paddle/tools/test_runner.py", line 52, in main
1593:       res = unittest.TextTestRunner(stream=buffer).run(tests)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/runner.py", line 184, in run
1593:       test(result)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/suite.py", line 84, in __call__
1593:       return self.run(*args, **kwds)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/suite.py", line 122, in run
1593:       test(result)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/suite.py", line 84, in __call__
1593:       return self.run(*args, **kwds)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/suite.py", line 122, in run
1593:       test(result)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 650, in __call__
1593:       return self.run(*args, **kwds)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 591, in run
1593:       self._callTestMethod(testMethod)
1593:     File "/usr/local/Cellar/[email protected]/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
1593:       method()
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/test_sequence_pool.py", line 105, in test_check_grad
1593:       self.check_grad(["X"], "Out", check_dygraph=False)
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2306, in check_grad
1593:       self.check_grad_with_place(
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2465, in check_grad_with_place
1593:       analytic_grads = self._get_gradient(
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 2706, in _get_gradient
1593:       self._append_ops(block)
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/test/sequence/../../python/paddle/fluid/tests/unittests/eager_op_test.py", line 676, in _append_ops
1593:       op = block.append_op(
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/framework.py", line 4061, in append_op
1593:       op = Operator(
1593:     File "/Users/gouzi/Documents/git/Paddle/build-mac/python/paddle/fluid/framework.py", line 2829, in __init__
1593:       for frame in traceback.extract_stack():
1593:
1593:     InvalidArgumentError: The size of inputs_args names (2) must be equal to the size of kernel input_defs (3).
1593:       [Hint: Expected input_names.size() == input_defs.size(), but received input_names.size():2 != input_defs.size():3.] (at /Users/gouzi/Documents/git/Paddle/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc:681)
1593:       [operator < sequence_pool_grad > error]
1593:

Copy link
Contributor

Choose a reason for hiding this comment

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

这个case下max_index参数是根据不同情况可选的,等价于标记了AsDispensable,所以在kernel声明时应被声明成optional类型,在SUM的情况下这个input就会被跳过。

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

{"X", "MaxIndex", "Out@GRAD"},
{"is_test", "pooltype", "pad_value"},
{"X@GRAD"});
}

} // namespace phi

PD_REGISTER_ARG_MAPPING_FN(sequence_pool, phi::SequencePoolOpArgumentMapping);
PD_REGISTER_ARG_MAPPING_FN(sequence_pool_grad,
phi::SequencePoolGradOpArgumentMapping);