@@ -40,7 +40,8 @@ class SequencePadOp : public framework::OperatorWithKernel {
40
40
" The Input(PadValue) must be a scalar or a tensor whose "
41
41
" shape equals to time steps in sequences" );
42
42
43
- int batch_dim_size = -1 ;
43
+ int out_dim_0 = -1 ;
44
+ int out_dim_1 = -1 ;
44
45
45
46
if (ctx->IsRuntime ()) {
46
47
// run time
@@ -64,17 +65,20 @@ class SequencePadOp : public framework::OperatorWithKernel {
64
65
PADDLE_ENFORCE_GE (padded_length, max_seq_len,
65
66
" The Attr(padded_length) must be -1 or an int greater "
66
67
" than the length of the longest original sequence." );
67
- batch_dim_size = padded_length * seq_num;
68
+ out_dim_0 = seq_num;
69
+ out_dim_1 = padded_length;
68
70
} else {
69
71
// compile time
70
72
framework::VarDesc* x_desc =
71
73
boost::get<framework::VarDesc*>(ctx->GetInputVarPtrs (" X" )[0 ]);
72
74
PADDLE_ENFORCE_GE (x_desc->GetLoDLevel (), 1 );
73
75
}
74
76
75
- auto out_dims = x_dims;
76
- out_dims[0 ] = batch_dim_size;
77
- ctx->SetOutputDim (" Out" , out_dims);
77
+ std::vector<int > out_dims_vec{out_dim_0, out_dim_1};
78
+ auto time_step_dims_vec = framework::vectorize2int (time_step_dims);
79
+ out_dims_vec.insert (out_dims_vec.end (), time_step_dims_vec.begin (),
80
+ time_step_dims_vec.end ());
81
+ ctx->SetOutputDim (" Out" , framework::make_ddim (out_dims_vec));
78
82
}
79
83
};
80
84
@@ -118,9 +122,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
118
122
and Input(PadValue):
119
123
PadValue.data = [0]
120
124
and attribite 'padded_length' = 4,
121
- then we get 1-level LoDTensor:
122
- Out.lod = [[0, 4, 8]]
123
- Out.data = [a, b, 0, 0, c, d, e, 0]
125
+ then we get LoDTensor:
126
+ Out.data = [[a, b, 0, 0],
127
+ [ c, d, e, 0] ]
124
128
125
129
Case 2:
126
130
@@ -131,9 +135,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
131
135
PadValue.data = [0]
132
136
and attribite 'padded_length' = -1, which mean using the length
133
137
of longest input sequence(3 in this case),
134
- then we get 1-level LoDTensor:
135
- Out.lod = [[0, 3, 6]]
136
- Out.data = [[a1, a2], [b1, b2], [0, 0], [ c1, c2], [d1, d2], [e1, e2]]
138
+ then we get LoDTensor:
139
+ Out.data = [[[a1, a2], [b1, b2], [0, 0]],
140
+ [[ c1, c2], [d1, d2], [e1, e2] ]]
137
141
138
142
Case 3:
139
143
@@ -144,9 +148,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
144
148
PadValue.data = [p1, p2]
145
149
and attribite 'padded_length' = -1, which mean using the length
146
150
of longest input sequence(3 in this case),
147
- then we get 1-level LoDTensor:
148
- Out.lod = [[0, 3, 6]]
149
- Out.data = [[a1, a2], [b1, b2], [p1, p2], [ c1, c2], [d1, d2], [e1, e2]]
151
+ then we get LoDTensor:
152
+ Out.data = [[[a1, a2], [b1, b2], [p1, p2]],
153
+ [[ c1, c2], [d1, d2], [e1, e2] ]]
150
154
151
155
)DOC" );
152
156
}
0 commit comments