Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b5fa9164
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看板
提交
b5fa9164
编写于
12月 18, 2018
作者:
J
JiabinYang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug after merge reyoung optimization, test=develop
上级
656040c7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
50 deletion
+15
-50
paddle/fluid/operators/hierarchical_sigmoid_op.h
paddle/fluid/operators/hierarchical_sigmoid_op.h
+0
-1
paddle/fluid/operators/math/matrix_bit_code.cc
paddle/fluid/operators/math/matrix_bit_code.cc
+0
-35
paddle/fluid/operators/math/matrix_bit_code.h
paddle/fluid/operators/math/matrix_bit_code.h
+15
-14
未找到文件。
paddle/fluid/operators/hierarchical_sigmoid_op.h
浏览文件 @
b5fa9164
...
...
@@ -71,7 +71,6 @@ class HierarchicalSigmoidOpKernel : public framework::OpKernel<T> {
// server
auto
height_sections
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"height_sections"
);
auto
table_names
=
ctx
.
Attr
<
std
::
vector
<
std
::
string
>>
(
"table_names"
);
VLOG
(
3
)
<<
"path type is "
<<
path
->
type
().
name
();
std
::
vector
<
int64_t
>
real_rows
=
PathToRows
(
*
path
);
framework
::
Scope
&
local_scope
=
ctx
.
scope
().
NewScope
();
auto
*
ids
=
local_scope
.
Var
(
"Ids@Prefetch"
);
...
...
paddle/fluid/operators/math/matrix_bit_code.cc
浏览文件 @
b5fa9164
...
...
@@ -84,41 +84,6 @@ void MatrixBitCodeFunctor<T>::AddGrad(const framework::Tensor &tmat,
code_table_
.
apply_visitor
(
func
);
}
template
<
typename
T
>
struct
MatrixBitCodeFunctorSelectedRowsAddGrad
:
public
boost
::
static_visitor
<
void
>
{
const
framework
::
Tensor
&
tmat_
;
framework
::
SelectedRows
*
vec_
;
MatrixBitCodeFunctorSelectedRowsAddGrad
(
const
framework
::
Tensor
&
tmat
,
framework
::
SelectedRows
*
vec
)
:
tmat_
(
tmat
),
vec_
(
vec
)
{}
template
<
typename
CodeTable
>
void
operator
()(
const
CodeTable
&
code_table
)
{
size_t
batch_size
=
tmat_
.
dims
()[
0
];
size_t
width
=
tmat_
.
dims
()[
1
];
auto
*
vec_data
=
vec_
->
mutable_value
()
->
template
data
<
T
>();
auto
*
tmat_data
=
tmat_
.
data
<
T
>
();
for
(
size_t
i
=
0
;
i
<
batch_size
;
++
i
)
{
auto
code
=
code_table
.
get_code
(
i
);
int
code_length
=
code
.
get_length
();
for
(
int
j
=
0
;
j
<
code_length
;
++
j
)
{
size_t
index
=
code
.
calc_index
(
j
);
int64_t
row_index
=
vec_
->
GetIndexFromId
(
static_cast
<
int64_t
>
(
index
));
vec_data
[
row_index
]
+=
tmat_data
[
i
*
width
+
j
];
}
}
}
};
template
<
typename
T
>
void
MatrixBitCodeFunctor
<
T
>::
AddGrad
(
const
framework
::
Tensor
&
tmat
,
framework
::
SelectedRows
*
vec
)
{
MatrixBitCodeFunctorSelectedRowsAddGrad
<
T
>
func
(
tmat
,
vec
);
code_table_
.
apply_visitor
(
func
);
}
template
<
typename
T
>
struct
MatrixBitCodeFunctorSum
:
public
boost
::
static_visitor
<
void
>
{
const
framework
::
Tensor
&
tmat_
;
...
...
paddle/fluid/operators/math/matrix_bit_code.h
浏览文件 @
b5fa9164
...
...
@@ -124,11 +124,12 @@ class SimpleCode {
template
<
typename
T
>
class
CustomCode
{
public:
CustomCode
(
const
framework
::
Tensor
&
ptable
,
const
framework
::
Tensor
&
pcode
,
const
int64_t
*
ids
,
int
index
)
{
seq_len_
=
ptable
.
dims
()[
1
];
ptable_data_
=
ptable
.
data
<
T
>
()
+
seq_len_
*
index
;
pcode_data_
=
pcode
.
data
<
T
>
()
+
seq_len_
*
index
;
CustomCode
(
const
framework
::
Tensor
&
path_table
,
const
framework
::
Tensor
&
path_code
,
const
int64_t
*
ids
,
int
index
)
{
seq_len_
=
path_table
.
dims
()[
1
];
path_table_data_
=
path_table
.
data
<
T
>
()
+
seq_len_
*
index
;
path_code_data_
=
path_code
.
data
<
T
>
()
+
seq_len_
*
index
;
}
/**
* Here the id of root should be 1 rather than 0, thus the encoding of class c
...
...
@@ -139,25 +140,25 @@ class CustomCode {
* Binary classification path is the suffixes of encoding, thus leave out the
* left most bit in calc_bit.
*/
size_t
calc_index
(
int
bit
)
const
{
return
ptable_data_
[
bit
];
}
bool
calc_bit
(
int
bit
)
const
{
return
pcode_data_
[
bit
];
}
size_t
calc_index
(
int
bit
)
const
{
return
p
ath_
table_data_
[
bit
];
}
bool
calc_bit
(
int
bit
)
const
{
return
p
ath_
code_data_
[
bit
];
}
// NOTE: this function is not thread-safe.
int
get_length
()
const
{
if
(
length_
<
0
)
{
auto
len
=
seq_len_
;
length_
=
st
atic_cast
<
int
>
(
std
::
find_if
(
ptable_data_
,
p
table_data_
+
len
,
[](
const
T
&
val
)
{
return
val
<
0
;
})
-
p
table_data_
);
length_
=
static_cast
<
int
>
(
st
d
::
find_if
(
path_table_data_
,
path_
table_data_
+
len
,
[](
const
T
&
val
)
{
return
val
<
0
;
})
-
path_
table_data_
);
}
return
length_
;
}
private:
int64_t
seq_len_
;
const
T
*
ptable_data_
;
const
T
*
pcode_data_
;
const
T
*
p
ath_
table_data_
;
const
T
*
p
ath_
code_data_
;
mutable
int
length_
{
-
1
};
};
...
...
@@ -214,7 +215,7 @@ class MatrixBitCodeFunctor {
const
framework
::
Tensor
&
path_code
,
const
int64_t
*
ids
)
:
num_classes_
(
static_cast
<
size_t
>
(
path_table
.
dims
()[
1
])),
ids_
(
ids
),
code_table_
(
CustomCodeTable
<
int64_t
>
(
p
table
,
p
code
,
ids
))
{}
code_table_
(
CustomCodeTable
<
int64_t
>
(
p
ath_table
,
path_
code
,
ids
))
{}
/* For j < code_length
tmat(i, j) += vec(0, index(i, j))
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录