Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
9074a60c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9074a60c
编写于
10月 31, 2017
作者:
F
fengjiayi
提交者:
GitHub
10月 31, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine lookup_table_op (#5257)
1. Change some `auto` to `auto*` 2. Change `Tensor` to `LoDTensor`
上级
db3b9438
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
28 deletion
+28
-28
paddle/operators/lookup_table_op.cc
paddle/operators/lookup_table_op.cc
+2
-2
paddle/operators/lookup_table_op.cu
paddle/operators/lookup_table_op.cu
+12
-12
paddle/operators/lookup_table_op.h
paddle/operators/lookup_table_op.h
+14
-14
未找到文件。
paddle/operators/lookup_table_op.cc
浏览文件 @
9074a60c
...
...
@@ -43,7 +43,7 @@ class LookupTableOp : public framework::OperatorWithKernel {
protected:
framework
::
DataType
IndicateDataType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
ToDataType
(
ctx
.
Input
<
Tensor
>
(
"W"
)
->
type
());
return
framework
::
ToDataType
(
ctx
.
Input
<
LoD
Tensor
>
(
"W"
)
->
type
());
}
};
...
...
@@ -93,7 +93,7 @@ class LookupTableOpGrad : public framework::OperatorWithKernel {
protected:
framework
::
DataType
IndicateDataType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
ToDataType
(
ctx
.
Input
<
Tensor
>
(
"W"
)
->
type
());
return
framework
::
ToDataType
(
ctx
.
Input
<
LoD
Tensor
>
(
"W"
)
->
type
());
}
};
...
...
paddle/operators/lookup_table_op.cu
浏览文件 @
9074a60c
...
...
@@ -61,16 +61,16 @@ template <typename T>
class
LookupTableCUDAKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
table_t
=
context
.
Input
<
Tensor
>
(
"W"
);
auto
ids_t
=
context
.
Input
<
Tensor
>
(
"Ids"
);
auto
output_t
=
context
.
Output
<
Tensor
>
(
"Out"
);
auto
*
table_t
=
context
.
Input
<
LoD
Tensor
>
(
"W"
);
auto
*
ids_t
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
auto
*
output_t
=
context
.
Output
<
LoD
Tensor
>
(
"Out"
);
size_t
N
=
table_t
->
dims
()[
0
];
size_t
D
=
table_t
->
dims
()[
1
];
size_t
K
=
ids_t
->
numel
();
auto
ids
=
ids_t
->
data
<
int64_t
>
();
auto
table
=
table_t
->
data
<
T
>
();
auto
output
=
output_t
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
ids
=
ids_t
->
data
<
int64_t
>
();
auto
*
table
=
table_t
->
data
<
T
>
();
auto
*
output
=
output_t
->
mutable_data
<
T
>
(
context
.
GetPlace
());
dim3
threads
(
128
,
8
);
dim3
grids
(
8
,
1
);
...
...
@@ -87,9 +87,9 @@ class LookupTableGradCUDAKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
bool
is_sparse
=
context
.
Attr
<
bool
>
(
"is_sparse"
);
if
(
is_sparse
)
{
auto
*
ids
=
context
.
Input
<
Tensor
>
(
"Ids"
);
auto
*
table
=
context
.
Input
<
Tensor
>
(
"W"
);
auto
*
d_output
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
ids
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
auto
*
table
=
context
.
Input
<
LoD
Tensor
>
(
"W"
);
auto
*
d_output
=
context
.
Input
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_table
=
context
.
Output
<
SelectedRows
>
(
framework
::
GradVarName
(
"W"
));
auto
*
ids_data
=
ids
->
data
<
int64_t
>
();
...
...
@@ -119,9 +119,9 @@ class LookupTableGradCUDAKernel : public framework::OpKernel<T> {
d_output
->
numel
(),
stream
);
}
else
{
auto
ids_t
=
context
.
Input
<
Tensor
>
(
"Ids"
);
auto
d_output_t
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
d_table_t
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"W"
));
auto
ids_t
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
auto
d_output_t
=
context
.
Input
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
d_table_t
=
context
.
Output
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"W"
));
int
N
=
d_table_t
->
dims
()[
0
];
int
D
=
d_table_t
->
dims
()[
1
];
...
...
paddle/operators/lookup_table_op.h
浏览文件 @
9074a60c
...
...
@@ -19,22 +19,22 @@
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
using
LoDTensor
=
framework
::
LoD
Tensor
;
using
SelectedRows
=
framework
::
SelectedRows
;
template
<
typename
T
>
class
LookupTableKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
table_t
=
context
.
Input
<
Tensor
>
(
"W"
);
// float tensor
auto
ids_t
=
context
.
Input
<
Tensor
>
(
"Ids"
);
// int tensor
auto
output_t
=
context
.
Output
<
Tensor
>
(
"Out"
);
// float tensor
auto
*
table_t
=
context
.
Input
<
LoD
Tensor
>
(
"W"
);
// float tensor
auto
*
ids_t
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
// int tensor
auto
*
output_t
=
context
.
Output
<
LoD
Tensor
>
(
"Out"
);
// float tensor
int
N
=
table_t
->
dims
()[
0
];
int
D
=
table_t
->
dims
()[
1
];
auto
ids
=
ids_t
->
data
<
int64_t
>
();
auto
table
=
table_t
->
data
<
T
>
();
auto
output
=
output_t
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
ids
=
ids_t
->
data
<
int64_t
>
();
auto
*
table
=
table_t
->
data
<
T
>
();
auto
*
output
=
output_t
->
mutable_data
<
T
>
(
context
.
GetPlace
());
for
(
int64_t
i
=
0
;
i
<
ids_t
->
numel
();
++
i
)
{
PADDLE_ENFORCE_LT
(
ids
[
i
],
N
);
PADDLE_ENFORCE_GE
(
ids
[
i
],
0
);
...
...
@@ -49,9 +49,9 @@ class LookupTableGradKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
bool
is_sparse
=
context
.
Attr
<
bool
>
(
"is_sparse"
);
if
(
is_sparse
)
{
auto
*
ids
=
context
.
Input
<
Tensor
>
(
"Ids"
);
auto
*
table
=
context
.
Input
<
Tensor
>
(
"W"
);
auto
*
d_output
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
ids
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
auto
*
table
=
context
.
Input
<
LoD
Tensor
>
(
"W"
);
auto
*
d_output
=
context
.
Input
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_table
=
context
.
Output
<
SelectedRows
>
(
framework
::
GradVarName
(
"W"
));
auto
*
ids_data
=
ids
->
data
<
int64_t
>
();
...
...
@@ -76,10 +76,10 @@ class LookupTableGradKernel : public framework::OpKernel<T> {
PADDLE_ENFORCE_EQ
(
d_table_value
->
dims
(),
d_output
->
dims
());
memcpy
(
d_table_data
,
d_output_data
,
sizeof
(
T
)
*
d_output
->
numel
());
}
else
{
auto
*
ids
=
context
.
Input
<
Tensor
>
(
"Ids"
);
auto
*
d_output
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_table
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"W"
));
auto
*
table
=
context
.
Input
<
Tensor
>
(
"W"
);
auto
*
ids
=
context
.
Input
<
LoD
Tensor
>
(
"Ids"
);
auto
*
d_output
=
context
.
Input
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_table
=
context
.
Output
<
LoD
Tensor
>
(
framework
::
GradVarName
(
"W"
));
auto
*
table
=
context
.
Input
<
LoD
Tensor
>
(
"W"
);
auto
*
ids_data
=
ids
->
data
<
int64_t
>
();
auto
ids_dim
=
ids
->
dims
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录