Skip to content

Commit 49a5942

Browse files
author
wanghaox
committed
fix some typos
2 parents 352c5a9 + 4579bd4 commit 49a5942

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

paddle/operators/sequence_slice_op.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class SequenceSliceOpMaker : public framework::OpProtoAndCheckerMaker {
9090
"a vector<int> to describe the length of every input sequence for "
9191
"sub sequence item.");
9292
AddOutput("Out",
93-
"(LoDTensor), The output of SequenceSliceOp.");
93+
"(LoDTensor), the output of SequenceSliceOp.");
9494
AddComment(R"DOC(
9595
Sequence slice operator
9696
97-
The operator crop a subsequence from given sequence with given start offset and subsequence length.
97+
The operator crops a subsequence from given sequence with given start offset and subsequence length.
9898
It only supports sequence (LoD Tensor with level number is 1).
9999
- Case:
100100
X = [[a1, a2;
@@ -109,7 +109,7 @@ It only supports sequence (LoD Tensor with level number is 1).
109109
b1, b2]
110110
[e1, e2]]
111111
LoD(Out) = {{0, 2, 3}}; Dims(Out) = (3, 2)
112-
NOTE: The length of the input, offset and length should be the same. The offset start from 0.
112+
NOTE: The first dimension size of input, the size of offset and Length, should be equal. The offset start from 0.
113113
)DOC");
114114
}
115115
};

paddle/operators/sequence_slice_op.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class SequenceSliceOpKernel : public framework::OpKernel<T> {
8383
PADDLE_ENFORCE_LT(
8484
lod[0][i] + offset_data[i] + length_data[i],
8585
lod[0][i + 1],
86-
"The target tensor's length overflow")}
86+
"The target tensor's length overflow")
87+
}
8788

8889
out->mutable_data<T>(ctx.GetPlace());
8990
auto out_lod = SequenceSliceLoD(*in, offset_data, length_data);
@@ -140,27 +141,29 @@ class SequenceSliceGradOpKernel : public framework::OpKernel<T> {
140141
auto lod = in->lod();
141142
auto out_lod = out_grad->lod();
142143

143-
x_grad->mutable_data<T>(ctx.GetPlace());
144-
math::SetConstant<Place, T> set_zero;
145-
set_zero(ctx.device_context(), x_grad, static_cast<T>(0));
144+
if (x_grad) {
145+
x_grad->mutable_data<T>(ctx.GetPlace());
146+
math::SetConstant<Place, T> set_zero;
147+
set_zero(ctx.device_context(), x_grad, static_cast<T>(0));
146148

147-
auto out_grad_stride = framework::stride(out_grad->dims());
149+
auto out_grad_stride = framework::stride(out_grad->dims());
148150

149-
for (size_t i = 0; i < out_lod[0].size() - 1; ++i) {
150-
Tensor out_grad_t =
151-
out_grad->Slice(static_cast<int>(out_lod[0][i]),
152-
static_cast<int>(out_lod[0][i + 1]));
153-
auto out_grad_stride = framework::stride(out_grad_t.dims());
151+
for (size_t i = 0; i < out_lod[0].size() - 1; ++i) {
152+
Tensor out_grad_t =
153+
out_grad->Slice(static_cast<int>(out_lod[0][i]),
154+
static_cast<int>(out_lod[0][i + 1]));
155+
auto out_grad_stride = framework::stride(out_grad_t.dims());
154156

155-
auto x_grad_stride = framework::stride(x_grad->dims());
157+
auto x_grad_stride = framework::stride(x_grad->dims());
156158

157-
Tensor x_grad_t = x_grad->Slice(
158-
static_cast<int>(lod[0][i] + offset_data[i]),
159-
static_cast<int>(lod[0][i] + offset_data[i] + length_data[i]));
159+
Tensor x_grad_t = x_grad->Slice(
160+
static_cast<int>(lod[0][i] + offset_data[i]),
161+
static_cast<int>(lod[0][i] + offset_data[i] + length_data[i]));
160162

161-
StridedMemcpy<T>(ctx.device_context(), out_grad_t.data<T>(),
162-
out_grad_stride, out_grad_t.dims(), x_grad_stride,
163-
x_grad_t.data<T>());
163+
StridedMemcpy<T>(ctx.device_context(), out_grad_t.data<T>(),
164+
out_grad_stride, out_grad_t.dims(), x_grad_stride,
165+
x_grad_t.data<T>());
166+
}
164167
}
165168
}
166169
};

0 commit comments

Comments
 (0)