Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
49a59421
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
49a59421
编写于
11月 16, 2017
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
差异文件
fix some typos
上级
352c5a96
4579bd44
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
20 deletion
+23
-20
paddle/operators/sequence_slice_op.cc
paddle/operators/sequence_slice_op.cc
+3
-3
paddle/operators/sequence_slice_op.h
paddle/operators/sequence_slice_op.h
+20
-17
未找到文件。
paddle/operators/sequence_slice_op.cc
浏览文件 @
49a59421
...
...
@@ -90,11 +90,11 @@ class SequenceSliceOpMaker : public framework::OpProtoAndCheckerMaker {
"a vector<int> to describe the length of every input sequence for "
"sub sequence item."
);
AddOutput
(
"Out"
,
"(LoDTensor),
T
he output of SequenceSliceOp."
);
"(LoDTensor),
t
he output of SequenceSliceOp."
);
AddComment
(
R"DOC(
Sequence slice operator
The operator crop a subsequence from given sequence with given start offset and subsequence length.
The operator crop
s
a subsequence from given sequence with given start offset and subsequence length.
It only supports sequence (LoD Tensor with level number is 1).
- Case:
X = [[a1, a2;
...
...
@@ -109,7 +109,7 @@ It only supports sequence (LoD Tensor with level number is 1).
b1, b2]
[e1, e2]]
LoD(Out) = {{0, 2, 3}}; Dims(Out) = (3, 2)
NOTE: The
length of the input, offset and length should be the same
. The offset start from 0.
NOTE: The
first dimension size of input, the size of offset and Length, should be equal
. The offset start from 0.
)DOC"
);
}
};
...
...
paddle/operators/sequence_slice_op.h
浏览文件 @
49a59421
...
...
@@ -83,7 +83,8 @@ class SequenceSliceOpKernel : public framework::OpKernel<T> {
PADDLE_ENFORCE_LT
(
lod
[
0
][
i
]
+
offset_data
[
i
]
+
length_data
[
i
],
lod
[
0
][
i
+
1
],
"The target tensor's length overflow"
)}
"The target tensor's length overflow"
)
}
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
out_lod
=
SequenceSliceLoD
(
*
in
,
offset_data
,
length_data
);
...
...
@@ -140,27 +141,29 @@ class SequenceSliceGradOpKernel : public framework::OpKernel<T> {
auto
lod
=
in
->
lod
();
auto
out_lod
=
out_grad
->
lod
();
x_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
math
::
SetConstant
<
Place
,
T
>
set_zero
;
set_zero
(
ctx
.
device_context
(),
x_grad
,
static_cast
<
T
>
(
0
));
if
(
x_grad
)
{
x_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
math
::
SetConstant
<
Place
,
T
>
set_zero
;
set_zero
(
ctx
.
device_context
(),
x_grad
,
static_cast
<
T
>
(
0
));
auto
out_grad_stride
=
framework
::
stride
(
out_grad
->
dims
());
auto
out_grad_stride
=
framework
::
stride
(
out_grad
->
dims
());
for
(
size_t
i
=
0
;
i
<
out_lod
[
0
].
size
()
-
1
;
++
i
)
{
Tensor
out_grad_t
=
out_grad
->
Slice
(
static_cast
<
int
>
(
out_lod
[
0
][
i
]),
static_cast
<
int
>
(
out_lod
[
0
][
i
+
1
]));
auto
out_grad_stride
=
framework
::
stride
(
out_grad_t
.
dims
());
for
(
size_t
i
=
0
;
i
<
out_lod
[
0
].
size
()
-
1
;
++
i
)
{
Tensor
out_grad_t
=
out_grad
->
Slice
(
static_cast
<
int
>
(
out_lod
[
0
][
i
]),
static_cast
<
int
>
(
out_lod
[
0
][
i
+
1
]));
auto
out_grad_stride
=
framework
::
stride
(
out_grad_t
.
dims
());
auto
x_grad_stride
=
framework
::
stride
(
x_grad
->
dims
());
auto
x_grad_stride
=
framework
::
stride
(
x_grad
->
dims
());
Tensor
x_grad_t
=
x_grad
->
Slice
(
static_cast
<
int
>
(
lod
[
0
][
i
]
+
offset_data
[
i
]),
static_cast
<
int
>
(
lod
[
0
][
i
]
+
offset_data
[
i
]
+
length_data
[
i
]));
Tensor
x_grad_t
=
x_grad
->
Slice
(
static_cast
<
int
>
(
lod
[
0
][
i
]
+
offset_data
[
i
]),
static_cast
<
int
>
(
lod
[
0
][
i
]
+
offset_data
[
i
]
+
length_data
[
i
]));
StridedMemcpy
<
T
>
(
ctx
.
device_context
(),
out_grad_t
.
data
<
T
>
(),
out_grad_stride
,
out_grad_t
.
dims
(),
x_grad_stride
,
x_grad_t
.
data
<
T
>
());
StridedMemcpy
<
T
>
(
ctx
.
device_context
(),
out_grad_t
.
data
<
T
>
(),
out_grad_stride
,
out_grad_t
.
dims
(),
x_grad_stride
,
x_grad_t
.
data
<
T
>
());
}
}
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录