Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
101a9a4e
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看板
提交
101a9a4e
编写于
3月 08, 2017
作者:
H
hedaoyuan
提交者:
GitHub
3月 08, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1566 from hedaoyuan/multi-gradient-machine-error
Fix MultiGradientMachine error
上级
1fa73024
df8a5af9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
9 deletion
+32
-9
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
+27
-8
paddle/gserver/gradientmachines/MultiGradientMachine.h
paddle/gserver/gradientmachines/MultiGradientMachine.h
+5
-1
未找到文件。
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
浏览文件 @
101a9a4e
...
@@ -346,8 +346,10 @@ Evaluator* MultiGradientMachine::makeEvaluator() const {
...
@@ -346,8 +346,10 @@ Evaluator* MultiGradientMachine::makeEvaluator() const {
void
MultiGradientMachine
::
eval
(
Evaluator
*
evaluator
)
const
{
void
MultiGradientMachine
::
eval
(
Evaluator
*
evaluator
)
const
{
for
(
auto
&
thread
:
threads_
)
{
for
(
auto
&
thread
:
threads_
)
{
SetDevice
device
(
thread
->
getDeviceId
());
SetDevice
device
(
thread
->
getDeviceId
());
if
(
thread
->
hasInputData
())
{
thread
->
getGradientMachine
()
->
eval
(
evaluator
);
thread
->
getGradientMachine
()
->
eval
(
evaluator
);
}
}
}
}
}
void
MultiGradientMachine
::
getOutArgs
(
std
::
vector
<
Argument
>*
outArgs
,
void
MultiGradientMachine
::
getOutArgs
(
std
::
vector
<
Argument
>*
outArgs
,
...
@@ -356,14 +358,19 @@ void MultiGradientMachine::getOutArgs(std::vector<Argument>* outArgs,
...
@@ -356,14 +358,19 @@ void MultiGradientMachine::getOutArgs(std::vector<Argument>* outArgs,
REGISTER_TIMER
(
"waitOutArgs"
);
REGISTER_TIMER
(
"waitOutArgs"
);
thread
->
waitOutArgsReady
();
thread
->
waitOutArgsReady
();
}
}
outArgs_
.
resize
(
threads_
[
0
]
->
getOutArgs
().
size
());
outArgs_
.
resize
(
threads_
[
threads_
.
size
()
-
1
]
->
getOutArgs
().
size
());
REGISTER_TIMER
(
"copyOutArgs"
);
REGISTER_TIMER
(
"copyOutArgs"
);
for
(
size_t
i
=
0
;
i
<
outArgs_
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
outArgs_
.
size
();
++
i
)
{
std
::
vector
<
Argument
>
args
;
std
::
vector
<
Argument
>
args
;
args
.
reserve
(
threads_
.
size
());
args
.
reserve
(
threads_
.
size
());
for
(
auto
&
thread
:
threads_
)
{
for
(
auto
&
thread
:
threads_
)
{
args
.
push_back
(
thread
->
getOutArgs
()[
i
]);
// If the thread input is empty, then the output is empty.
auto
tmp
=
thread
->
getOutArgs
();
if
(
tmp
.
size
()
>
0
)
{
args
.
push_back
(
tmp
[
i
]);
}
}
}
outArgs_
[
i
].
concat
(
args
,
useGpu_
,
outArgStream_
,
passType
);
outArgs_
[
i
].
concat
(
args
,
useGpu_
,
outArgStream_
,
passType
);
}
}
...
@@ -534,7 +541,7 @@ void TrainerThread::prefetch() {
...
@@ -534,7 +541,7 @@ void TrainerThread::prefetch() {
void
TrainerThread
::
forward
()
{
void
TrainerThread
::
forward
()
{
if
(
!
inArgsCopied_
)
{
if
(
!
inArgsCopied_
)
{
REGISTER_TIMER
(
"copyInArgs"
);
REGISTER_TIMER
(
"copyInArgs"
);
copyInArgs
();
batchSize_
=
copyInArgs
();
}
else
{
}
else
{
inArgsCopied_
=
false
;
inArgsCopied_
=
false
;
}
}
...
@@ -564,7 +571,12 @@ void TrainerThread::forward() {
...
@@ -564,7 +571,12 @@ void TrainerThread::forward() {
{
{
REGISTER_TIMER
(
"thread_forward"
);
REGISTER_TIMER
(
"thread_forward"
);
gradientMachine_
->
forward
(
inArgs_
,
&
outArgs_
,
multiMachine_
->
getPassType
());
if
(
batchSize_
>
0
)
{
gradientMachine_
->
forward
(
inArgs_
,
&
outArgs_
,
multiMachine_
->
getPassType
());
}
else
{
outArgs_
.
clear
();
}
}
}
outArgsReadySem_
.
post
();
outArgsReadySem_
.
post
();
}
}
...
@@ -574,7 +586,13 @@ void TrainerThread::backward() {
...
@@ -574,7 +586,13 @@ void TrainerThread::backward() {
if
(
multiMachine_
->
isPassGrad
())
{
if
(
multiMachine_
->
isPassGrad
())
{
copyOutputGrad
();
copyOutputGrad
();
}
}
if
(
batchSize_
>
0
)
{
gradientMachine_
->
backward
(
backwardCallback_
);
gradientMachine_
->
backward
(
backwardCallback_
);
}
else
{
for
(
size_t
i
=
parameters_
.
size
();
i
>
0
;
i
--
)
{
backwardCallback
(
parameters_
[
i
-
1
].
get
());
}
}
if
(
multiMachine_
->
hasNonstaticCpuParamters
())
{
if
(
multiMachine_
->
hasNonstaticCpuParamters
())
{
mergeCpuGradients
();
mergeCpuGradients
();
}
}
...
@@ -732,7 +750,7 @@ void TrainerThread::notifyValueReady(int paramId) {
...
@@ -732,7 +750,7 @@ void TrainerThread::notifyValueReady(int paramId) {
notifyValueDispatch
(
paramId
);
notifyValueDispatch
(
paramId
);
}
}
void
TrainerThread
::
copyInArgs
()
{
int
TrainerThread
::
copyInArgs
()
{
const
std
::
vector
<
Argument
>&
fullInArgs
=
multiMachine_
->
getInArgs
();
const
std
::
vector
<
Argument
>&
fullInArgs
=
multiMachine_
->
getInArgs
();
int
numThreads
=
multiMachine_
->
getAllThreads
().
size
();
int
numThreads
=
multiMachine_
->
getAllThreads
().
size
();
int32_t
numSequences
=
fullInArgs
[
0
].
getNumSequences
();
int32_t
numSequences
=
fullInArgs
[
0
].
getNumSequences
();
...
@@ -748,7 +766,7 @@ void TrainerThread::copyInArgs() {
...
@@ -748,7 +766,7 @@ void TrainerThread::copyInArgs() {
}
}
if
(
copySize
==
0
)
{
if
(
copySize
==
0
)
{
return
;
return
0
;
}
}
for
(
size_t
i
=
0
;
i
<
fullInArgs
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
fullInArgs
.
size
();
i
++
)
{
...
@@ -758,6 +776,7 @@ void TrainerThread::copyInArgs() {
...
@@ -758,6 +776,7 @@ void TrainerThread::copyInArgs() {
copySize
,
copySize
,
FLAGS_parallel_nn
?
false
:
multiMachine_
->
useGpu
());
FLAGS_parallel_nn
?
false
:
multiMachine_
->
useGpu
());
}
}
return
copySize
;
}
}
void
TrainerThread
::
mergeCpuGradients
()
{
void
TrainerThread
::
mergeCpuGradients
()
{
...
...
paddle/gserver/gradientmachines/MultiGradientMachine.h
浏览文件 @
101a9a4e
...
@@ -387,6 +387,9 @@ public:
...
@@ -387,6 +387,9 @@ public:
/// copy the output gradient from the main GradientMachine.
/// copy the output gradient from the main GradientMachine.
void
copyOutputGrad
();
void
copyOutputGrad
();
/// Whether the thread has input data.
bool
hasInputData
()
{
return
batchSize_
!=
0
;
}
protected:
protected:
void
mergeCpuGradients
();
void
mergeCpuGradients
();
...
@@ -407,7 +410,7 @@ protected:
...
@@ -407,7 +410,7 @@ protected:
void
copyGradToBufferThread
();
void
copyGradToBufferThread
();
void
gradCollectThread
();
void
gradCollectThread
();
void
copyInArgs
();
int
copyInArgs
();
void
forward
();
void
forward
();
void
backward
();
void
backward
();
void
backwardCallback
(
Parameter
*
para
);
void
backwardCallback
(
Parameter
*
para
);
...
@@ -467,6 +470,7 @@ protected:
...
@@ -467,6 +470,7 @@ protected:
/// indicate whether inArgs is copied before forward()
/// indicate whether inArgs is copied before forward()
bool
inArgsCopied_
;
bool
inArgsCopied_
;
int
batchSize_
;
};
};
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录