Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
7526ac14
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7526ac14
编写于
1月 04, 2019
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add comments
test=develop
上级
cb1891f9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
15 deletion
+57
-15
python/paddle/fluid/compiler.py
python/paddle/fluid/compiler.py
+50
-7
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
...ddle/fluid/tests/unittests/parallel_executor_test_base.py
+1
-1
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
+5
-6
未找到文件。
python/paddle/fluid/compiler.py
浏览文件 @
7526ac14
...
@@ -34,6 +34,10 @@ class CompiledProgram(object):
...
@@ -34,6 +34,10 @@ class CompiledProgram(object):
"""
"""
Compiles a Program for execution.
Compiles a Program for execution.
1. Users first create the program with layers.
2. Optionally, users use CompiledProgram to optimize the program before run.
3. The original program or CompiledProgram is run by executor.
The CompiledProgram is used to transform a program for various
The CompiledProgram is used to transform a program for various
optimizations, for example.
optimizations, for example.
* Pre-compute some logic once so that each run is faster.
* Pre-compute some logic once so that each run is faster.
...
@@ -42,11 +46,19 @@ class CompiledProgram(object):
...
@@ -42,11 +46,19 @@ class CompiledProgram(object):
training.
training.
Example:
Example:
.. code-block:: python
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(startup)
compiled_prog = compiler.CompiledProgram(main).with_data_parallel(
loss_name=loss.name)
for i in range(5):
test_loss, = exe.run(compiled_prog,
feed=feed_dict,
fetch_list=[loss.name])
Args:
Args:
program: Program instance that contains the model logic.
program: Program instance that contains the model logic.
"""
"""
def
__init__
(
self
,
program
):
def
__init__
(
self
,
program
):
...
@@ -57,11 +69,32 @@ class CompiledProgram(object):
...
@@ -57,11 +69,32 @@ class CompiledProgram(object):
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
):
share_vars_from
=
None
):
"""Configs the program to run in data parallel way.
Args:
loss_name (str): The loss name must set in training. Default None.
build_strategy(BuildStrategy): build_strategy is used to
build the graph so it can run on multiple devices/cores with
optimized topology.
For more information, please refer to fluid.BuildStrategy.
Default None.
exec_strategy(ExecutionStrategy): exec_strategy is used to
to select the a way to execute the graph, for example how many
threads are used, how many iterations to clean up the temp
variables. For more information, please refer
to fluid.ExecutionStrategy. Default None.
share_vars_from(CompiledProgram): If provide, this CompiledProgram
will share variables from `share_vars_from`. `share_vars_from`
must be run by the executor before this CompiledProgram so that
vars are ready.
Returns:
self
"""
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
...
@@ -145,6 +178,16 @@ class CompiledProgram(object):
...
@@ -145,6 +178,16 @@ class CompiledProgram(object):
self
.
_exec_strategy
,
self
.
_build_strategy
)
self
.
_exec_strategy
,
self
.
_build_strategy
)
def
_compile
(
self
,
scope
,
place
):
def
_compile
(
self
,
scope
,
place
):
"""Compile the program based on the configs.
Args:
scope: The variables (resources) that are associated with
this compiled program.
place: The location that the compiled program will be run on.
Returns:
self
"""
if
self
.
_compiled
:
if
self
.
_compiled
:
if
scope
and
self
.
_scope
!=
scope
:
if
scope
and
self
.
_scope
!=
scope
:
raise
ValueError
(
"Cannot compile with different scope"
)
raise
ValueError
(
"Cannot compile with different scope"
)
...
...
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
浏览文件 @
7526ac14
...
@@ -81,7 +81,7 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -81,7 +81,7 @@ 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
.
CompiledProgram
(
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
)
...
...
python/paddle/fluid/tests/unittests/test_dist_base.py
浏览文件 @
7526ac14
...
@@ -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
.
CompiledProgram
(
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
浏览文件 @
7526ac14
...
@@ -62,13 +62,12 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
...
@@ -62,13 +62,12 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
exe
.
run
(
startup
)
exe
.
run
(
startup
)
feed_dict
=
{
'image'
:
image
,
'label'
:
label
}
feed_dict
=
{
'image'
:
image
,
'label'
:
label
}
train_cp
=
compiler
.
CompiledProgram
(
main
).
_
with_data_parallel
(
train_cp
=
compiler
.
CompiledProgram
(
main
).
with_data_parallel
(
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
)
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
)
test_cp
=
compiler
.
CompiledProgram
(
test_cp
=
compiler
.
CompiledProgram
(
test_program
).
with_data_parallel
(
test_program
).
_with_data_parallel
(
loss_name
=
loss
.
name
,
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
,
build_strategy
=
build_strategy
,
share_vars_from
=
train_cp
)
share_vars_from
=
train_cp
)
for
i
in
range
(
5
):
for
i
in
range
(
5
):
exe
.
run
(
train_cp
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
exe
.
run
(
train_cp
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录