@@ -25,10 +25,8 @@ class SeqExpandOp : public framework::OperatorWithKernel {
25
25
26
26
protected:
27
27
void InferShape (framework::InferShapeContext* ctx) const override {
28
- PADDLE_ENFORCE (ctx->HasInput (" X" ),
29
- " Input(X) of SeqExpandOp should not be null." );
30
- PADDLE_ENFORCE (ctx->HasOutput (" Out" ),
31
- " Output(Out) of SeqExpandOp should not be null." );
28
+ PADDLE_ENFORCE (ctx->HasInput (" X" ));
29
+ PADDLE_ENFORCE (ctx->HasOutput (" Out" ));
32
30
PADDLE_ENFORCE (
33
31
ctx->HasInput (" Y" ),
34
32
" Input(Y) of SeqExpandOp should not be null while repeat == 0." );
@@ -54,7 +52,7 @@ class SeqExpandOpMaker : public framework::OpProtoAndCheckerMaker {
54
52
" The element numbers of last level in input('Y') "
55
53
" must be equal to dims[0] of input('X')." );
56
54
AddOutput (" Out" ,
57
- " The output of seq_expand op."
55
+ " (LodTensor) The output of seq_expand op."
58
56
" The lod of output will be as same as input(Y)'s lod." );
59
57
AddComment (R"DOC(
60
58
Expand input(X) according to LOD of input(Y).
@@ -69,6 +67,7 @@ Given 2-level a LoDTensor input(X)
69
67
and input(Y)
70
68
Y.lod = [[0, 2, 4],
71
69
[0, 3, 6, 7, 8]]
70
+ with condition len(Y.lod[-1]) -1 == X.dims[0]
72
71
then we get 2-level LoDTensor
73
72
Out.lod = [[0, 2, 4],
74
73
[0, 3, 6, 7, 8]]
@@ -83,6 +82,7 @@ Given a 0-level LoDTensor input(X)
83
82
X.dims = [3, 1]
84
83
and input(Y)
85
84
Y.lod = [[0, 2, 3, 6]]
85
+ with condition len(Y.lod[-1]) -1 == X.dims[0]
86
86
then we get 1-level LoDTensor
87
87
Out.lod = [[0, 2, 3, 6]]
88
88
Out.data = [a, a, b, c, c, c]
@@ -96,11 +96,29 @@ Given a 0-level LoDTensor input(X)
96
96
X.dims = [3, 2]
97
97
and input(Y)
98
98
Y.lod = [[0, 2, 3, 6]]
99
+ with condition len(Y.lod[-1]) -1 == X.dims[0]
99
100
then we get 1-level LoDTensor
100
101
Out.lod = [[0, 2, 3, 6]]
101
102
Out.data = [[a,b], [a,b] [c,d], [e, f], [e, f], [e, f]]
102
103
Out.dims = [6, 2]
103
104
105
+ Case 4:
106
+
107
+ Given 2-level a LoDTensor input(X)
108
+ X.lod = [[0, 2, 3],
109
+ [0, 1, 3, 4]]
110
+ X.data = [a, b, c, d]
111
+ X.dims = [4, 1]
112
+ and input(Y)
113
+ Y.lod = [[0, 2, 4],
114
+ [0, 3, 6, 6, 8]]
115
+ with condition len(Y.lod[-1]) -1 == X.dims[0]
116
+ then we get 2-level LoDTensor
117
+ Out.lod = [[0, 2, 4],
118
+ [0, 3, 6, 6, 8]]
119
+ Out.data = [a, a, a, b, b, b, d, d]
120
+ Out.dims = [8, 1]
121
+
104
122
105
123
)DOC" );
106
124
}
@@ -112,8 +130,8 @@ class SeqExpandOpGrad : public framework::OperatorWithKernel {
112
130
113
131
protected:
114
132
void InferShape (framework::InferShapeContext* ctx) const override {
115
- PADDLE_ENFORCE (ctx->HasInput (" X" ), " Input(X) should not be null " );
116
- PADDLE_ENFORCE (ctx->HasInput (" Out" ), " Input(Out) should not be null " );
133
+ PADDLE_ENFORCE (ctx->HasInput (" X" ));
134
+ PADDLE_ENFORCE (ctx->HasInput (" Out" ));
117
135
PADDLE_ENFORCE (ctx->HasInput (framework::GradVarName (" Out" )),
118
136
" Input(Out@GRAD) should not be null" );
119
137
auto x_dims = ctx->GetInputDim (" X" );
0 commit comments