Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
6373291c
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,发现更多精彩内容 >>
提交
6373291c
编写于
8月 08, 2017
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test case use_mkldnn_wgt
上级
0c951176
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
45 addition
and
38 deletion
+45
-38
paddle/gserver/layers/MkldnnBase.h
paddle/gserver/layers/MkldnnBase.h
+0
-2
paddle/gserver/layers/MkldnnFcLayer.cpp
paddle/gserver/layers/MkldnnFcLayer.cpp
+4
-0
paddle/gserver/layers/MkldnnLayer.h
paddle/gserver/layers/MkldnnLayer.h
+3
-0
paddle/gserver/tests/MkldnnTester.cpp
paddle/gserver/tests/MkldnnTester.cpp
+27
-33
paddle/gserver/tests/MkldnnTester.h
paddle/gserver/tests/MkldnnTester.h
+2
-2
paddle/gserver/tests/test_Mkldnn.cpp
paddle/gserver/tests/test_Mkldnn.cpp
+1
-0
paddle/trainer/TrainerConfigHelper.cpp
paddle/trainer/TrainerConfigHelper.cpp
+2
-0
paddle/utils/Flags.cpp
paddle/utils/Flags.cpp
+1
-0
paddle/utils/Flags.h
paddle/utils/Flags.h
+1
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+4
-1
未找到文件。
paddle/gserver/layers/MkldnnBase.h
浏览文件 @
6373291c
...
...
@@ -23,8 +23,6 @@ typedef enum {
DNN_TESTS
=
1
,
DNN_SIZES
,
DNN_FMTS
,
DNN_TESTS_DETAILS
,
DNN_TESTS_MORE
,
DNN_ALL
,
}
DNN_LOG_LEVEL
;
...
...
paddle/gserver/layers/MkldnnFcLayer.cpp
浏览文件 @
6373291c
...
...
@@ -51,6 +51,10 @@ bool MkldnnFcLayer::init(const LayerMap& layerMap,
}
void
MkldnnFcLayer
::
cvtWgtFromPaddle
()
{
if
(
FLAGS_use_mkldnn_wgt
)
{
return
;
}
if
(
hasInitedWgt_
)
{
return
;
}
...
...
paddle/gserver/layers/MkldnnLayer.h
浏览文件 @
6373291c
...
...
@@ -19,6 +19,9 @@ limitations under the License. */
#include "MkldnnBase.h"
#include "mkldnn.hpp"
DECLARE_bool
(
use_mkldnn
);
DECLARE_bool
(
use_mkldnn_wgt
);
namespace
paddle
{
class
MkldnnLayer
;
...
...
paddle/gserver/tests/MkldnnTester.cpp
浏览文件 @
6373291c
...
...
@@ -118,7 +118,7 @@ void MkldnnTester::checkForward() {
printTopDatas
();
double
delta
=
compareMatrix
(
testLayers_
[
DNN
]
->
getOutputValue
(),
testLayers_
[
REF
]
->
getOutputValue
());
VLOG
(
DNN_
TESTS_DETAILS
)
<<
"Check Forward"
;
VLOG
(
DNN_
ALL
)
<<
"Check Forward"
;
EXPECT_LE
(
fabs
(
delta
),
eps_
);
}
...
...
@@ -162,7 +162,7 @@ void MkldnnTester::checkBackwardWgts() {
EXPECT_LE
(
fabs
(
delta
),
eps_
);
}
VLOG
(
DNN_
TESTS_DETAILS
)
<<
"Restore dnn weights before comapre"
;
VLOG
(
DNN_
ALL
)
<<
"Restore dnn weights before comapre"
;
restoreWgt
(
dnnWgts
,
parameters_
[
DNN
]);
}
...
...
@@ -275,8 +275,8 @@ double MkldnnTester::getDelta(const real* d1,
EXPECT_TRUE
(
std
::
isnormal
(
sum
));
EXPECT_FALSE
(
std
::
isinf
(
sum
));
EXPECT_FALSE
(
std
::
isnan
(
delta
));
VLOG
(
DNN_
TESTS_MORE
)
<<
"reference avg data: "
<<
sum
/
len
<<
", delta: "
<<
delta
/
sum
<<
", failCnt:"
<<
failCnt
;
VLOG
(
DNN_
ALL
)
<<
"reference avg data: "
<<
sum
/
len
<<
", delta: "
<<
delta
/
sum
<<
", failCnt:"
<<
failCnt
;
return
(
failCnt
/
(
float
)
len
)
>
failRate
?
maxOut
:
delta
/
sum
;
}
...
...
@@ -330,43 +330,37 @@ void MkldnnTester::run(const TestConfig& dnn,
log_
=
log
;
lvl_
=
level
;
// Firstly always set flag false to initial from paddle weight
TestConfig
first
=
dnn
;
// Firstly test FLAGS_use_mkldnn_wgt = false
FLAGS_use_mkldnn_wgt
=
false
;
// reset and run once
reset
(
first
,
ref
,
batchSize
);
reset
(
dnn
,
ref
,
batchSize
);
randomWgtDatas
();
clearWgtDiffs
();
clearBotDiffs
();
for
(
size_t
i
=
0
;
i
<
iter_
;
++
i
)
{
VLOG
(
DNN_TESTS
)
<<
"Check Iteration "
<<
i
;
runOnce
();
}
VLOG
(
DNN_TESTS
)
<<
"Check Iteration 0"
;
runOnce
();
// firstly get the flag
bool
initWgtFromMkldnn
=
false
;
if
(
initWgtFromMkldnn
)
{
// after run once the mkldnn weight has been stored in dnnlayer
// then save the weigths and restart again
vector
<
VectorPtr
>
dnnWgts
,
refWgts
;
CHECK_EQ
(
parameters_
[
DNN
].
size
(),
parameters_
[
REF
].
size
());
saveWgt
(
parameters_
[
DNN
],
dnnWgts
);
saveWgt
(
parameters_
[
REF
],
refWgts
);
// restart again with flag true
reset
(
dnn
,
ref
,
batchSize
);
// Then test FLAGS_use_mkldnn_wgt = true
FLAGS_use_mkldnn_wgt
=
true
;
// after run once the mkldnn weight has been stored in dnnlayer
// then save the weigths and restart again
vector
<
VectorPtr
>
dnnWgts
,
refWgts
;
CHECK_EQ
(
parameters_
[
DNN
].
size
(),
parameters_
[
REF
].
size
());
saveWgt
(
parameters_
[
DNN
],
dnnWgts
);
saveWgt
(
parameters_
[
REF
],
refWgts
);
// restore wgt
restoreWgt
(
dnnWgts
,
parameters_
[
DNN
]);
restoreWgt
(
refWgts
,
parameters_
[
REF
]);
clearWgtDiffs
();
clearBotDiffs
();
// restart again with flag true
reset
(
dnn
,
ref
,
batchSize
);
// at least run once
runOnce
();
}
// restore wgt
restoreWgt
(
dnnWgts
,
parameters_
[
DNN
]);
restoreWgt
(
refWgts
,
parameters_
[
REF
]);
clearWgtDiffs
();
clearBotDiffs
();
for
(
size_t
i
=
1
;
i
<
iter_
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
iter_
;
++
i
)
{
VLOG
(
DNN_TESTS
)
<<
"Check Iteration "
<<
i
;
runOnce
();
}
...
...
paddle/gserver/tests/MkldnnTester.h
浏览文件 @
6373291c
...
...
@@ -58,7 +58,7 @@ public:
iter_
=
iter
;
eps_
=
epsilon
;
log_
=
false
;
lvl_
=
DNN_
TESTS_MORE
;
lvl_
=
DNN_
ALL
;
}
~
MkldnnTester
()
{}
...
...
@@ -72,7 +72,7 @@ public:
size_t
iter
=
3
,
float
epsilon
=
1e-4
,
bool
log
=
false
,
int
level
=
DNN_
TESTS_MORE
);
int
level
=
DNN_
ALL
);
void
setLogLevel
(
int
lvl
)
{
lvl_
=
lvl
;
}
private:
...
...
paddle/gserver/tests/test_Mkldnn.cpp
浏览文件 @
6373291c
...
...
@@ -23,6 +23,7 @@ using namespace paddle; // NOLINT
DECLARE_bool
(
thread_local_rand_use_global_seed
);
DECLARE_bool
(
use_gpu
);
DECLARE_bool
(
use_mkldnn
);
DECLARE_bool
(
use_mkldnn_wgt
);
struct
testFCDesc
{
int
bs
;
...
...
paddle/trainer/TrainerConfigHelper.cpp
浏览文件 @
6373291c
...
...
@@ -29,6 +29,7 @@ DECLARE_bool(with_gpu);
DECLARE_bool
(
parallel_nn
);
DECLARE_string
(
config_args
);
DECLARE_bool
(
use_mkldnn
);
DECLARE_bool
(
use_mkldnn_wgt
);
const
char
*
kConfigParserModuleName
=
"paddle.trainer.config_parser"
;
const
char
*
kConfigParserFuncName
=
"parse_config_and_serialize"
;
...
...
@@ -46,6 +47,7 @@ TrainerConfigHelper::TrainerConfigHelper(const std::string &configFilePath)
<<
",with_cost="
<<
FLAGS_with_cost
<<
",use_gpu="
<<
FLAGS_use_gpu
<<
",parallel_nn="
<<
FLAGS_parallel_nn
<<
",use_mkldnn="
<<
FLAGS_use_mkldnn
<<
",use_mkldnn_wgt="
<<
FLAGS_use_mkldnn_wgt
<<
",cudnn_version="
<<
hl_get_cudnn_lib_version
();
if
(
!
FLAGS_config_args
.
empty
())
{
configArgs
<<
","
<<
FLAGS_config_args
;
...
...
paddle/utils/Flags.cpp
浏览文件 @
6373291c
...
...
@@ -27,6 +27,7 @@ DEFINE_bool(use_mkldnn, false, "Default still keep use CPU training");
DEFINE_bool
(
use_mkldnn
,
false
,
"Only support CPU training"
);
#endif
DEFINE_bool
(
use_mkldnn_wgt
,
false
,
"Init weight from CPU weight"
);
DEFINE_bool
(
parallel_nn
,
false
,
"Whether to use multi-threads to calculate one neural network."
...
...
paddle/utils/Flags.h
浏览文件 @
6373291c
...
...
@@ -41,3 +41,4 @@ DECLARE_string(predict_file);
DECLARE_bool
(
prev_batch_state
);
DECLARE_string
(
init_model_path
);
DECLARE_bool
(
use_mkldnn
);
DECLARE_bool
(
use_mkldnn_wgt
);
python/paddle/trainer/config_parser.py
浏览文件 @
6373291c
...
...
@@ -1619,6 +1619,8 @@ class FCLayer(LayerBase):
config_assert
(
len
(
inputs
)
==
1
,
"MkldnnFCLayer support one and only one input!"
)
use_mkldnn_wgt
=
bool
(
int
(
g_command_config_args
.
get
(
"use_mkldnn_wgt"
,
0
)))
super
(
FCLayer
,
self
).
__init__
(
name
,
self
.
layer_type
,
size
,
inputs
=
inputs
,
**
xargs
)
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
...
...
@@ -1627,9 +1629,10 @@ class FCLayer(LayerBase):
format
=
self
.
inputs
[
input_index
].
format
sparse
=
format
==
"csr"
or
format
==
"csc"
if
use_mkldnn
:
dims
=
[
self
.
config
.
size
,
input_layer
.
size
]
config_assert
(
not
sparse
,
"MkldnnFCLayer do not support sparse format yet"
)
if
use_mkldnn
and
use_mkldnn_wgt
:
dims
=
[
self
.
config
.
size
,
input_layer
.
size
]
else
:
dims
=
[
input_layer
.
size
,
self
.
config
.
size
]
if
sparse
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录