Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
beaae61a
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
beaae61a
编写于
1月 04, 2019
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish
test=develop
上级
5e928e57
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
56 addition
and
27 deletion
+56
-27
python/paddle/fluid/compiler.py
python/paddle/fluid/compiler.py
+32
-6
python/paddle/fluid/executor.py
python/paddle/fluid/executor.py
+6
-4
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
...ddle/fluid/tests/unittests/parallel_executor_test_base.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_base.py
python/paddle/fluid/tests/unittests/test_dist_base.py
+1
-1
python/paddle/fluid/tests/unittests/test_parallel_executor_test_while_train.py
...ests/unittests/test_parallel_executor_test_while_train.py
+15
-14
未找到文件。
python/paddle/fluid/compiler.py
浏览文件 @
beaae61a
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
multiprocessing
import
multiprocessing
import
os
import
os
import
six
import
six
import
sys
from
..
import
compat
as
cpt
from
..
import
compat
as
cpt
from
.
import
core
from
.
import
core
...
@@ -29,27 +30,50 @@ def _place_obj(place):
...
@@ -29,27 +30,50 @@ def _place_obj(place):
return
p
return
p
class
_ProgramCompiler
(
object
):
class
CompiledProgram
(
object
):
def
__init__
(
self
,
program
):
def
__init__
(
self
,
program
):
self
.
_program
=
program
self
.
_program
=
program
self
.
_scope
=
None
self
.
_place
=
None
self
.
_executor
=
None
self
.
_compiled
=
False
self
.
_compiled
=
False
self
.
_is_data_parallel
=
False
self
.
_is_data_parallel
=
False
def
_with_data_parallel
(
self
,
def
_with_data_parallel
(
self
,
loss_name
=
None
,
loss_name
=
None
,
build_strategy
=
None
,
build_strategy
=
None
,
exec_strategy
=
None
):
exec_strategy
=
None
,
share_vars_from
=
None
):
assert
not
self
.
_is_data_parallel
,
"Already compiled with parallel."
assert
not
self
.
_is_data_parallel
,
"Already compiled with parallel."
self
.
_is_data_parallel
=
True
self
.
_is_data_parallel
=
True
self
.
_build_strategy
=
build_strategy
self
.
_build_strategy
=
build_strategy
self
.
_exec_strategy
=
exec_strategy
self
.
_exec_strategy
=
exec_strategy
self
.
_loss_name
=
loss_name
self
.
_loss_name
=
loss_name
self
.
_share_vars_from
=
share_vars_from
return
self
return
self
def
_with_distributed
(
self
):
raise
NotImplementedError
()
def
_with_inference_optimize
(
self
):
raise
NotImplementedError
()
def
_compile_data_parallel
(
self
):
def
_compile_data_parallel
(
self
):
self
.
_places
=
[]
if
self
.
_share_vars_from
:
if
self
.
_scope
:
sys
.
stderr
.
write
(
"share_vars_from is set, scope is ignored.
\n
"
)
if
not
self
.
_share_vars_from
.
_is_data_parallel
:
raise
ValueError
(
"share_vars_from is not data parallel. Cannot "
"share vars from it."
)
if
self
.
_share_vars_from
.
_executor
is
None
:
raise
ValueError
(
"share_vars_from is not compiled and run, so there is no "
"var to share."
)
self
.
_local_scopes
=
self
.
_share_vars_from
.
_executor
.
local_scopes
()
else
:
self
.
_local_scopes
=
[]
self
.
_local_scopes
=
[]
self
.
_places
=
[]
if
self
.
_exec_strategy
is
None
:
if
self
.
_exec_strategy
is
None
:
self
.
_exec_strategy
=
ExecutionStrategy
()
self
.
_exec_strategy
=
ExecutionStrategy
()
if
self
.
_build_strategy
is
None
:
if
self
.
_build_strategy
is
None
:
...
@@ -104,12 +128,14 @@ class _ProgramCompiler(object):
...
@@ -104,12 +128,14 @@ class _ProgramCompiler(object):
def
_compile
(
self
,
scope
,
place
):
def
_compile
(
self
,
scope
,
place
):
if
self
.
_compiled
:
if
self
.
_compiled
:
if
scope
and
self
.
_scope
!=
scope
:
raise
ValueError
(
"Cannot compile with different scope"
)
if
place
and
self
.
_place
!=
place
:
raise
ValueError
(
"Cannot compile with different place"
)
return
self
return
self
self
.
_compiled
=
True
self
.
_scope
=
scope
self
.
_scope
=
scope
self
.
_place
=
place
self
.
_place
=
place
if
self
.
_is_data_parallel
:
if
self
.
_is_data_parallel
:
self
.
_executor
=
self
.
_compile_data_parallel
()
self
.
_executor
=
self
.
_compile_data_parallel
()
else
:
else
:
...
...
python/paddle/fluid/executor.py
浏览文件 @
beaae61a
...
@@ -481,8 +481,10 @@ class Executor(object):
...
@@ -481,8 +481,10 @@ class Executor(object):
if
scope
is
None
:
if
scope
is
None
:
scope
=
global_scope
()
scope
=
global_scope
()
compiled
=
isinstance
(
program
,
compiler
.
_ProgramCompiler
)
compiled
=
isinstance
(
program
,
compiler
.
CompiledProgram
)
# For backward compatibility, run directly.
if
not
compiled
:
if
not
compiled
:
if
not
self
.
executor
:
p
=
core
.
Place
()
p
=
core
.
Place
()
p
.
set_place
(
self
.
place
)
p
.
set_place
(
self
.
place
)
self
.
executor
=
core
.
Executor
(
p
)
self
.
executor
=
core
.
Executor
(
p
)
...
...
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
浏览文件 @
beaae61a
...
@@ -81,12 +81,12 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -81,12 +81,12 @@ class TestParallelExecutorBase(unittest.TestCase):
if
use_cuda
and
core
.
is_compiled_with_cuda
():
if
use_cuda
and
core
.
is_compiled_with_cuda
():
build_strategy
.
remove_unnecessary_lock
=
True
build_strategy
.
remove_unnecessary_lock
=
True
if
use_parallel_executor
:
if
use_parallel_executor
:
binary
=
compiler
.
_ProgramCompiler
(
main
).
_with_data_parallel
(
binary
=
compiler
.
CompiledProgram
(
main
).
_with_data_parallel
(
loss_name
=
loss
.
name
,
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
,
build_strategy
=
build_strategy
,
exec_strategy
=
exec_strategy
)
exec_strategy
=
exec_strategy
)
else
:
else
:
binary
=
compiler
.
_ProgramCompiler
(
main
)
binary
=
compiler
.
CompiledProgram
(
main
)
if
batch_size
is
not
None
:
if
batch_size
is
not
None
:
batch_size
*=
fluid
.
core
.
get_cuda_device_count
(
batch_size
*=
fluid
.
core
.
get_cuda_device_count
(
...
...
python/paddle/fluid/tests/unittests/test_dist_base.py
浏览文件 @
beaae61a
...
@@ -132,7 +132,7 @@ class TestDistRunnerBase(object):
...
@@ -132,7 +132,7 @@ class TestDistRunnerBase(object):
build_stra
.
num_trainers
=
1
build_stra
.
num_trainers
=
1
build_stra
.
trainer_id
=
0
build_stra
.
trainer_id
=
0
binary
=
compiler
.
_ProgramCompiler
(
trainer_prog
).
_with_data_parallel
(
binary
=
compiler
.
CompiledProgram
(
trainer_prog
).
_with_data_parallel
(
loss_name
=
avg_cost
.
name
,
loss_name
=
avg_cost
.
name
,
build_strategy
=
build_stra
,
build_strategy
=
build_stra
,
exec_strategy
=
strategy
)
exec_strategy
=
strategy
)
...
...
python/paddle/fluid/tests/unittests/test_parallel_executor_test_while_train.py
浏览文件 @
beaae61a
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
from
__future__
import
print_function
from
__future__
import
print_function
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
import
numpy
as
np
import
numpy
as
np
import
unittest
import
unittest
...
@@ -61,22 +62,22 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
...
@@ -61,22 +62,22 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
exe
.
run
(
startup
)
exe
.
run
(
startup
)
feed_dict
=
{
'image'
:
image
,
'label'
:
label
}
feed_dict
=
{
'image'
:
image
,
'label'
:
label
}
train_exe
=
fluid
.
ParallelExecutor
(
train_cp
=
compiler
.
CompiledProgram
(
main
).
_with_data_parallel
(
use_cuda
=
use_cuda
,
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
)
test_cp
=
compiler
.
CompiledProgram
(
test_program
).
_with_data_parallel
(
loss_name
=
loss
.
name
,
loss_name
=
loss
.
name
,
main_program
=
main
,
build_strategy
=
build_strategy
,
build_strategy
=
build_strategy
)
share_vars_from
=
train_cp
)
test_exe
=
fluid
.
ParallelExecutor
(
use_cuda
=
use_cuda
,
main_program
=
test_program
,
share_vars_from
=
train_exe
,
build_strategy
=
build_strategy
)
for
i
in
range
(
5
):
for
i
in
range
(
5
):
test_loss
,
=
test_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
exe
.
run
(
train_cp
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
test_loss
,
=
exe
.
run
(
test_cp
,
train_loss
,
=
train_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
train_loss
,
=
exe
.
run
(
train_cp
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
avg_test_loss_val
=
np
.
array
(
test_loss
).
mean
()
avg_test_loss_val
=
np
.
array
(
test_loss
).
mean
()
if
math
.
isnan
(
float
(
avg_test_loss_val
)):
if
math
.
isnan
(
float
(
avg_test_loss_val
)):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录