Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
6de75082
P
Paddle
项目概览
机器未来
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6de75082
编写于
7月 07, 2020
作者:
Z
zhupengyang
提交者:
GitHub
7月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix test_hsigmoid windows ci (#25311)
上级
e3223ad7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
40 deletion
+47
-40
paddle/fluid/operators/math/matrix_bit_code.h
paddle/fluid/operators/math/matrix_bit_code.h
+1
-1
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+0
-1
python/paddle/fluid/tests/unittests/test_hsigmoid_op.py
python/paddle/fluid/tests/unittests/test_hsigmoid_op.py
+46
-38
未找到文件。
paddle/fluid/operators/math/matrix_bit_code.h
浏览文件 @
6de75082
...
...
@@ -98,7 +98,7 @@ inline int clz(const T& value) {
}
}
inline
size_t
FindLastSet
(
size_t
x
)
{
return
sizeof
(
size_t
)
*
8
-
clz
(
x
);
}
inline
size_t
FindLastSet
(
size_t
x
)
{
return
1
+
sizeof
(
size_t
)
*
8
-
clz
(
x
);
}
#endif // !_WIN32
class
SimpleCode
{
public:
...
...
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
6de75082
...
...
@@ -58,7 +58,6 @@ if(WIN32)
LIST
(
REMOVE_ITEM TEST_OPS test_debugger
)
list
(
REMOVE_ITEM TEST_OPS test_desc_clone
)
list
(
REMOVE_ITEM TEST_OPS test_fake_init_op
)
list
(
REMOVE_ITEM TEST_OPS test_hsigmoid_op
)
list
(
REMOVE_ITEM TEST_OPS test_merge_ids_op
)
list
(
REMOVE_ITEM TEST_OPS test_split_ids_op
)
list
(
REMOVE_ITEM TEST_OPS test_program_code
)
...
...
python/paddle/fluid/tests/unittests/test_hsigmoid_op.py
浏览文件 @
6de75082
...
...
@@ -70,9 +70,9 @@ def hsigmoid(x, w, label, bias, num_classes):
batch_size
=
x
.
shape
[
0
]
code_length
=
find_latest_set
(
num_classes
-
1
)
code_table
=
[
0
for
_
in
range
(
code_length
)]
pre_output
=
np
.
zeros
((
batch_size
,
code_length
))
pre_sum
=
np
.
zeros
((
batch_size
,
1
))
out
=
np
.
zeros
((
batch_size
,
1
))
pre_output
=
np
.
zeros
((
batch_size
,
code_length
))
.
astype
(
'float64'
)
pre_sum
=
np
.
zeros
((
batch_size
,
1
))
.
astype
(
'float64'
)
out
=
np
.
zeros
((
batch_size
,
1
))
.
astype
(
'float64'
)
for
i
in
range
(
batch_size
):
code_table
=
CodeTable
(
num_classes
,
label
[
i
])
length
=
code_table
.
get_length
()
...
...
@@ -105,9 +105,9 @@ def hsigmoid(x, w, label, bias, num_classes):
def
hsigmoid_grad
(
x
,
w
,
label
,
bias
,
num_classes
):
batch_size
=
x
.
shape
[
0
]
dx
=
np
.
zeros
(
x
.
shape
)
dw
=
np
.
zeros
(
w
.
shape
)
db
=
np
.
zeros
(
bias
.
shape
)
dx
=
np
.
zeros
(
x
.
shape
)
.
astype
(
'float64'
)
dw
=
np
.
zeros
(
w
.
shape
)
.
astype
(
'float64'
)
db
=
np
.
zeros
(
bias
.
shape
)
.
astype
(
'float64'
)
for
i
in
range
(
batch_size
):
code_table
=
CodeTable
(
num_classes
,
label
[
i
])
length
=
code_table
.
get_length
()
...
...
@@ -133,9 +133,9 @@ def hsigmoidWithCustomTree(x, w, path_table, path_code, label, bias,
code_length
=
len
(
path_table
[
0
])
code_table
=
[
0
for
_
in
range
(
code_length
)]
# init pre_out with shape [N, code_length]
pre_output
=
np
.
zeros
((
batch_size
,
code_length
))
pre_sum
=
np
.
zeros
((
batch_size
,
1
))
out
=
np
.
zeros
((
batch_size
,
1
))
pre_output
=
np
.
zeros
((
batch_size
,
code_length
))
.
astype
(
'float64'
)
pre_sum
=
np
.
zeros
((
batch_size
,
1
))
.
astype
(
'float64'
)
out
=
np
.
zeros
((
batch_size
,
1
))
.
astype
(
'float64'
)
if
isinstance
(
bias
,
np
.
ndarray
):
for
i
in
range
(
batch_size
):
code_table
=
CodeTableWithCustomTree
(
path_table
,
path_code
,
i
)
...
...
@@ -173,10 +173,13 @@ class TestHSigmoidOp(OpTest):
num_classes
=
101
feature_size
=
5
batch_size
=
20
x
=
np
.
random
.
uniform
(
-
1
,
1
,
(
batch_size
,
feature_size
))
w
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
feature_size
))
label
=
np
.
random
.
randint
(
0
,
num_classes
,
(
batch_size
,
1
))
bias
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
1
))
x
=
np
.
random
.
uniform
(
-
1
,
1
,
(
batch_size
,
feature_size
)).
astype
(
'float64'
)
w
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
feature_size
)).
astype
(
'float64'
)
label
=
np
.
random
.
randint
(
0
,
num_classes
,
(
batch_size
,
1
)).
astype
(
'int64'
)
bias
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
1
)).
astype
(
'float64'
)
self
.
attrs
=
{
'num_classes'
:
num_classes
,
'is_sparse'
:
False
}
self
.
inputs
=
{
'X'
:
x
,
'W'
:
w
,
'Label'
:
label
,
'Bias'
:
bias
}
pre_output
,
out
=
hsigmoid
(
x
,
w
,
label
,
bias
,
num_classes
)
...
...
@@ -189,7 +192,6 @@ class TestHSigmoidOp(OpTest):
def
test_check_grad
(
self
):
self
.
check_grad
(
[
'X'
,
'W'
,
'Bias'
],
[
'Out'
],
user_defined_grads
=
self
.
user_grads
)
#self.check_grad(['X', 'W', 'Bias'], ['Out'])
@
skip_check_grad_ci
(
...
...
@@ -203,13 +205,15 @@ class TestHSigmoidOpSparse(OpTest):
batch_size
=
4
x
=
np
.
random
.
random
((
batch_size
,
feature_size
))
w
=
np
.
random
.
random
((
num_classes
-
1
,
feature_size
))
label
=
np
.
array
([
0
,
1
,
4
,
5
])
path_table
=
np
.
array
(
[(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)])
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
([(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)])
#np.array to store
label
=
np
.
array
([
0
,
1
,
4
,
5
]).
astype
(
'int64'
)
path_table
=
np
.
array
([
(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)
]).
astype
(
'int64'
)
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
(
[(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)]).
astype
(
'int64'
)
#np.array to store
bias
=
np
.
random
.
random
((
num_classes
-
1
,
1
))
self
.
attrs
=
{
'num_classes'
:
num_classes
,
'is_sparse'
:
True
}
self
.
inputs
=
{
...
...
@@ -265,9 +269,9 @@ class TestHSigmoidOpWithSparseGrad(unittest.TestCase):
start_up
=
fluid
.
default_startup_program
()
start_up
.
random_seed
=
1
# Fix random seed
x
=
np
.
arange
(
6
).
reshape
(
6
)
path_table
=
np
.
array
([(
1
,
2
,
-
1
),
(
1
,
2
,
-
1
)])
path_code
=
np
.
array
([(
1
,
0
,
-
1
),
(
0
,
0
,
-
1
)])
label
=
np
.
array
([
1
,
4
])
path_table
=
np
.
array
([(
1
,
2
,
-
1
),
(
1
,
2
,
-
1
)])
.
astype
(
'int64'
)
path_code
=
np
.
array
([(
1
,
0
,
-
1
),
(
0
,
0
,
-
1
)])
.
astype
(
'int64'
)
label
=
np
.
array
([
1
,
4
])
.
astype
(
'int64'
)
loss
,
data_list
=
self
.
hs_net_conf
(
is_sparse
)
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
1e-3
)
...
...
@@ -307,13 +311,15 @@ class TestHSigmoidOpWithCostumTree(OpTest):
batch_size
=
4
x
=
np
.
random
.
uniform
(
-
1
,
1
,
(
batch_size
,
feature_size
))
w
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
feature_size
))
label
=
np
.
array
([
0
,
1
,
4
,
5
])
path_table
=
np
.
array
(
[(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)])
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
([(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)])
#np.array to store
label
=
np
.
array
([
0
,
1
,
4
,
5
]).
astype
(
'int64'
)
path_table
=
np
.
array
([
(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)
]).
astype
(
'int64'
)
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
(
[(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)]).
astype
(
'int64'
)
#np.array to store
bias
=
np
.
random
.
random
((
num_classes
-
1
,
1
))
self
.
attrs
=
{
'num_classes'
:
num_classes
,
'is_sparse'
:
False
}
self
.
inputs
=
{
...
...
@@ -346,13 +352,15 @@ class TestHSigmoidOpWithCostumTreeWithoutBias(OpTest):
batch_size
=
4
x
=
np
.
random
.
uniform
(
-
1
,
1
,
(
batch_size
,
feature_size
))
w
=
np
.
random
.
uniform
(
-
1
,
1
,
(
num_classes
-
1
,
feature_size
))
label
=
np
.
array
([
0
,
1
,
4
,
5
])
path_table
=
np
.
array
(
[(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)])
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
([(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)])
#np.array to store
label
=
np
.
array
([
0
,
1
,
4
,
5
]).
astype
(
'int64'
)
path_table
=
np
.
array
([
(
0
,
2
,
-
1
,
-
1
,
-
1
),
(
0
,
1
,
3
,
-
1
,
-
1
),
(
0
,
1
,
4
,
-
1
,
-
1
),
(
0
,
2
,
-
1
,
-
1
,
-
1
)
]).
astype
(
'int64'
)
#np.array to store 1,2,5,6s' non-leaf path(root -> leaf)
path_code
=
np
.
array
(
[(
0
,
0
,
-
1
,
-
1
,
-
1
),
(
1
,
1
,
1
,
-
1
,
-
1
),
(
1
,
0
,
0
,
-
1
,
-
1
),
(
0
,
1
,
-
1
,
-
1
,
-
1
)]).
astype
(
'int64'
)
#np.array to store
# bias = np.random.random((num_classes - 1, 1)).astype("float32")
self
.
attrs
=
{
'num_classes'
:
num_classes
,
'is_sparse'
:
False
}
self
.
inputs
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录