Skip to content

Commit b07ca1d

Browse files
committed
resize before computing LoD.
1 parent 08cb472 commit b07ca1d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

paddle/operators/sequence_reshape_op.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class SequenceReshapeKernel : public framework::OpKernel<T> {
4646
} else {
4747
auto& out_lod = *out->mutable_lod();
4848
out_lod.resize(1);
49-
out_lod[0].clear();
50-
out_lod[0].push_back(0);
49+
out_lod[0].resize(seq_num + 1);
50+
out_lod[0][0] = 0;
5151
for (int i = 0; i < seq_num; ++i) {
5252
size_t seq_len = in_lod_l0[i + 1] - in_lod_l0[i];
5353
size_t offset = 0;
@@ -57,11 +57,10 @@ class SequenceReshapeKernel : public framework::OpKernel<T> {
5757
"be divided by new_dim with no remainder for each "
5858
"sequence. The %dth sequence is invalid.",
5959
i + 1);
60-
out_lod[0].push_back(out_lod[0].back() + offset);
60+
out_lod[0][i + 1] = out_lod[0][i] + offset;
6161
}
6262
}
6363

64-
out->mutable_data<T>(context.GetPlace());
6564
framework::Copy(*in, context.GetPlace(), out);
6665
out->Resize({static_cast<int64_t>(out->lod()[0].back()), out_width});
6766
}

0 commit comments

Comments
 (0)