Skip to content

Commit 983502d

Browse files
author
xuwei06
committed
Fix sequence_pool_op in debug mode
The rank of the tensor from the chip() function is changed. In release mode, eigen_assert is not enabled and the dimenstion mismatch is not detected.
1 parent 3971586 commit 983502d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

paddle/operators/sequence_pool_op.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class SequencePoolGradKernel : public framework::OpKernel<T> {
126126
int64_t h = static_cast<int64_t>(lod[i + 1] - lod[i]);
127127
auto in_g_e = EigenMatrix<T>::From(in_g_t, {h, w});
128128
auto out_g_e = EigenMatrix<T>::From(out_g_t, {1, w});
129+
auto out_g_e_v = EigenVector<T>::Flatten(out_g_t);
129130
Eigen::DSizes<int, 2> bcast(h, 1);
130131

131132
if (pooltype == "AVERAGE") {
@@ -136,9 +137,9 @@ class SequencePoolGradKernel : public framework::OpKernel<T> {
136137
in_g_e.device(place) =
137138
(out_g_e / std::sqrt(static_cast<T>(h))).broadcast(bcast);
138139
} else if (pooltype == "LAST") {
139-
in_g_e.chip(h - 1, 0).device(place) = out_g_e;
140+
in_g_e.chip(h - 1, 0).device(place) = out_g_e_v;
140141
} else if (pooltype == "FIRST") {
141-
in_g_e.chip(0, 0).device(place) = out_g_e;
142+
in_g_e.chip(0, 0).device(place) = out_g_e_v;
142143
} else {
143144
PADDLE_THROW("unsupported pooling pooltype");
144145
}

0 commit comments

Comments
 (0)