Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
05cadf1b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
05cadf1b
编写于
8月 14, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add FastExecutor
上级
c6eb7a89
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
47 addition
and
12 deletion
+47
-12
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+5
-1
paddle/fluid/framework/details/execution_strategy.h
paddle/fluid/framework/details/execution_strategy.h
+3
-0
paddle/fluid/framework/details/fast_threaded_ssa_graph_executor.cc
...uid/framework/details/fast_threaded_ssa_graph_executor.cc
+4
-1
paddle/fluid/framework/details/fast_threaded_ssa_graph_executor.h
...luid/framework/details/fast_threaded_ssa_graph_executor.h
+2
-0
paddle/fluid/framework/parallel_executor.cc
paddle/fluid/framework/parallel_executor.cc
+9
-2
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+11
-2
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
...ddle/fluid/tests/unittests/parallel_executor_test_base.py
+4
-1
python/paddle/fluid/tests/unittests/test_parallel_executor_mnist.py
...dle/fluid/tests/unittests/test_parallel_executor_mnist.py
+9
-5
未找到文件。
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
05cadf1b
...
@@ -100,7 +100,11 @@ else()
...
@@ -100,7 +100,11 @@ else()
endif
()
endif
()
cc_library
(
parallel_executor SRCS parallel_executor.cc DEPS threaded_ssa_graph_executor scope_buffered_ssa_graph_executor graph graph_viz_pass multi_devices_graph_pass multi_devices_graph_print_pass multi_devices_graph_check_pass
)
cc_library
(
parallel_executor SRCS parallel_executor.cc DEPS
threaded_ssa_graph_executor scope_buffered_ssa_graph_executor
graph graph_viz_pass multi_devices_graph_pass
multi_devices_graph_print_pass multi_devices_graph_check_pass
fast_threaded_ssa_graph_executor
)
cc_library
(
prune SRCS prune.cc DEPS framework_proto
)
cc_library
(
prune SRCS prune.cc DEPS framework_proto
)
cc_test
(
prune_test SRCS prune_test.cc DEPS op_info prune recurrent_op device_context
)
cc_test
(
prune_test SRCS prune_test.cc DEPS op_info prune recurrent_op device_context
)
...
...
paddle/fluid/framework/details/execution_strategy.h
浏览文件 @
05cadf1b
...
@@ -19,10 +19,13 @@ namespace framework {
...
@@ -19,10 +19,13 @@ namespace framework {
namespace
details
{
namespace
details
{
struct
ExecutionStrategy
{
struct
ExecutionStrategy
{
enum
ExecutorType
{
kDefault
=
0
,
kExperimental
=
1
};
size_t
num_threads_
{
0
};
size_t
num_threads_
{
0
};
bool
use_cuda_
{
true
};
bool
use_cuda_
{
true
};
bool
allow_op_delay_
{
false
};
bool
allow_op_delay_
{
false
};
size_t
num_iteration_per_drop_scope_
{
100
};
size_t
num_iteration_per_drop_scope_
{
100
};
ExecutorType
type_
{
kDefault
};
};
};
}
// namespace details
}
// namespace details
...
...
paddle/fluid/framework/details/fast_threaded_ssa_graph_executor.cc
浏览文件 @
05cadf1b
...
@@ -105,7 +105,7 @@ FeedFetchList FastThreadedSSAGraphExecutor::Run(
...
@@ -105,7 +105,7 @@ FeedFetchList FastThreadedSSAGraphExecutor::Run(
for
(
int
i
=
0
;
i
<
remaining
;
++
i
)
{
for
(
int
i
=
0
;
i
<
remaining
;
++
i
)
{
complete_q
.
Pop
();
complete_q
.
Pop
();
}
}
LOG
(
FATAL
)
<<
"On exception thrown, not implemented"
;
exception_
.
ReThrow
()
;
}
}
num_complete
+=
num_comp
;
num_complete
+=
num_comp
;
}
}
...
@@ -127,6 +127,7 @@ void FastThreadedSSAGraphExecutor::RunOpAsync(
...
@@ -127,6 +127,7 @@ void FastThreadedSSAGraphExecutor::RunOpAsync(
op_to_run
->
Run
(
strategy_
.
use_cuda_
);
op_to_run
->
Run
(
strategy_
.
use_cuda_
);
++
complete
;
++
complete
;
}
catch
(...)
{
}
catch
(...)
{
exception_
.
Catch
(
std
::
current_exception
());
--
remaining_
;
--
remaining_
;
complete_q
->
Push
(
-
1UL
);
complete_q
->
Push
(
-
1UL
);
return
;
return
;
...
@@ -161,6 +162,8 @@ void FastThreadedSSAGraphExecutor::PrepareAtomicOpDeps() {
...
@@ -161,6 +162,8 @@ void FastThreadedSSAGraphExecutor::PrepareAtomicOpDeps() {
std
::
unordered_map
<
OpHandleBase
*
,
std
::
atomic
<
int
>>>
(
op_deps
);
std
::
unordered_map
<
OpHandleBase
*
,
std
::
atomic
<
int
>>>
(
op_deps
);
});
});
}
}
const
ir
::
Graph
&
FastThreadedSSAGraphExecutor
::
Graph
()
const
{
return
*
graph_
;
}
}
// namespace details
}
// namespace details
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/fluid/framework/details/fast_threaded_ssa_graph_executor.h
浏览文件 @
05cadf1b
...
@@ -34,6 +34,7 @@ class FastThreadedSSAGraphExecutor : public SSAGraphExecutor {
...
@@ -34,6 +34,7 @@ class FastThreadedSSAGraphExecutor : public SSAGraphExecutor {
const
std
::
vector
<
platform
::
Place
>
&
places
,
const
std
::
vector
<
platform
::
Place
>
&
places
,
std
::
unique_ptr
<
ir
::
Graph
>
&&
graph
);
std
::
unique_ptr
<
ir
::
Graph
>
&&
graph
);
FeedFetchList
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
)
override
;
FeedFetchList
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
)
override
;
const
ir
::
Graph
&
Graph
()
const
override
;
private:
private:
ExecutionStrategy
strategy_
;
ExecutionStrategy
strategy_
;
...
@@ -56,6 +57,7 @@ class FastThreadedSSAGraphExecutor : public SSAGraphExecutor {
...
@@ -56,6 +57,7 @@ class FastThreadedSSAGraphExecutor : public SSAGraphExecutor {
std
::
future
<
std
::
future
<
std
::
unique_ptr
<
std
::
unordered_map
<
OpHandleBase
*
,
std
::
atomic
<
int
>>>>
std
::
unique_ptr
<
std
::
unordered_map
<
OpHandleBase
*
,
std
::
atomic
<
int
>>>>
atomic_op_deps_
;
atomic_op_deps_
;
ExceptionHolder
exception_
;
};
};
}
// namespace details
}
// namespace details
}
// namespace framework
}
// namespace framework
...
...
paddle/fluid/framework/parallel_executor.cc
浏览文件 @
05cadf1b
...
@@ -25,6 +25,7 @@ limitations under the License. */
...
@@ -25,6 +25,7 @@ limitations under the License. */
#include "paddle/fluid/platform/nccl_helper.h"
#include "paddle/fluid/platform/nccl_helper.h"
#endif
#endif
#include "paddle/fluid/framework/details/fast_threaded_ssa_graph_executor.h"
#include "paddle/fluid/framework/details/multi_devices_graph_check_pass.h"
#include "paddle/fluid/framework/details/multi_devices_graph_check_pass.h"
#include "paddle/fluid/framework/details/multi_devices_graph_print_pass.h"
#include "paddle/fluid/framework/details/multi_devices_graph_print_pass.h"
#include "paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.h"
#include "paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.h"
...
@@ -193,8 +194,14 @@ ParallelExecutor::ParallelExecutor(
...
@@ -193,8 +194,14 @@ ParallelExecutor::ParallelExecutor(
member_
->
local_scopes_
,
member_
->
use_cuda_
,
build_strategy
);
member_
->
local_scopes_
,
member_
->
use_cuda_
,
build_strategy
);
#endif
#endif
member_
->
executor_
.
reset
(
new
details
::
ThreadedSSAGraphExecutor
(
if
(
exec_strategy
.
type_
==
ExecutionStrategy
::
kDefault
)
{
exec_strategy
,
member_
->
local_scopes_
,
places
,
std
::
move
(
graph
)));
member_
->
executor_
.
reset
(
new
details
::
ThreadedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
places
,
std
::
move
(
graph
)));
}
else
{
member_
->
executor_
.
reset
(
new
details
::
FastThreadedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
places
,
std
::
move
(
graph
)));
}
member_
->
executor_
.
reset
(
new
details
::
ScopeBufferedSSAGraphExecutor
(
member_
->
executor_
.
reset
(
new
details
::
ScopeBufferedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
std
::
move
(
var_infos
),
exec_strategy
,
member_
->
local_scopes_
,
std
::
move
(
var_infos
),
member_
->
places_
,
std
::
move
(
member_
->
executor_
)));
member_
->
places_
,
std
::
move
(
member_
->
executor_
)));
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
05cadf1b
...
@@ -593,8 +593,8 @@ All parameter, weight, gradient are variables in Paddle.
...
@@ -593,8 +593,8 @@ All parameter, weight, gradient are variables in Paddle.
// -- python binds for parallel executor.
// -- python binds for parallel executor.
py
::
class_
<
ParallelExecutor
>
pe
(
m
,
"ParallelExecutor"
);
py
::
class_
<
ParallelExecutor
>
pe
(
m
,
"ParallelExecutor"
);
py
::
class_
<
ExecutionStrategy
>
(
pe
,
"ExecutionStrategy"
)
py
::
class_
<
ExecutionStrategy
>
exec_strategy
(
pe
,
"ExecutionStrategy"
);
.
def
(
py
::
init
())
exec_strategy
.
def
(
py
::
init
())
.
def_property
(
.
def_property
(
"num_threads"
,
"num_threads"
,
[](
const
ExecutionStrategy
&
self
)
{
return
self
.
num_threads_
;
},
[](
const
ExecutionStrategy
&
self
)
{
return
self
.
num_threads_
;
},
...
@@ -621,6 +621,15 @@ All parameter, weight, gradient are variables in Paddle.
...
@@ -621,6 +621,15 @@ All parameter, weight, gradient are variables in Paddle.
[](
ExecutionStrategy
&
self
,
size_t
num_iteration_per_drop_scope
)
{
[](
ExecutionStrategy
&
self
,
size_t
num_iteration_per_drop_scope
)
{
self
.
num_iteration_per_drop_scope_
=
num_iteration_per_drop_scope
;
self
.
num_iteration_per_drop_scope_
=
num_iteration_per_drop_scope
;
});
});
py
::
enum_
<
ExecutionStrategy
::
ExecutorType
>
(
exec_strategy
,
"ExecutorType"
)
.
value
(
"Default"
,
ExecutionStrategy
::
kDefault
)
.
value
(
"Experimental"
,
ExecutionStrategy
::
kExperimental
);
exec_strategy
.
def_property
(
"type"
,
[](
const
ExecutionStrategy
&
self
)
{
return
self
.
type_
;
},
[](
ExecutionStrategy
&
self
,
ExecutionStrategy
::
ExecutorType
type
)
{
self
.
type_
=
type
;
});
py
::
class_
<
BuildStrategy
>
build_strategy
(
pe
,
"BuildStrategy"
);
py
::
class_
<
BuildStrategy
>
build_strategy
(
pe
,
"BuildStrategy"
);
py
::
enum_
<
BuildStrategy
::
ReduceStrategy
>
(
build_strategy
,
"ReduceStrategy"
)
py
::
enum_
<
BuildStrategy
::
ReduceStrategy
>
(
build_strategy
,
"ReduceStrategy"
)
...
...
python/paddle/fluid/tests/unittests/parallel_executor_test_base.py
浏览文件 @
05cadf1b
...
@@ -36,7 +36,8 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -36,7 +36,8 @@ class TestParallelExecutorBase(unittest.TestCase):
seed
=
None
,
seed
=
None
,
use_parallel_executor
=
True
,
use_parallel_executor
=
True
,
use_reduce
=
False
,
use_reduce
=
False
,
optimizer
=
fluid
.
optimizer
.
Adam
):
optimizer
=
fluid
.
optimizer
.
Adam
,
use_fast_executor
=
False
):
def
run_executor
(
exe
,
feed
,
fetch_list
,
program
=
None
):
def
run_executor
(
exe
,
feed
,
fetch_list
,
program
=
None
):
if
isinstance
(
exe
,
fluid
.
ParallelExecutor
):
if
isinstance
(
exe
,
fluid
.
ParallelExecutor
):
res
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
feed
)
res
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
feed
)
...
@@ -69,6 +70,8 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -69,6 +70,8 @@ class TestParallelExecutorBase(unittest.TestCase):
startup_exe
.
run
(
startup
)
startup_exe
.
run
(
startup
)
exec_strategy
=
fluid
.
ExecutionStrategy
()
exec_strategy
=
fluid
.
ExecutionStrategy
()
exec_strategy
.
allow_op_delay
=
allow_op_delay
exec_strategy
.
allow_op_delay
=
allow_op_delay
if
use_fast_executor
:
exec_strategy
.
type
=
fluid
.
ExecutionStrategy
.
ExecutorType
.
Experimental
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
reduce_strategy
=
fluid
.
BuildStrategy
.
ReduceStrategy
.
Reduce
\
build_strategy
.
reduce_strategy
=
fluid
.
BuildStrategy
.
ReduceStrategy
.
Reduce
\
...
...
python/paddle/fluid/tests/unittests/test_parallel_executor_mnist.py
浏览文件 @
05cadf1b
...
@@ -181,7 +181,9 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -181,7 +181,9 @@ class TestMNIST(TestParallelExecutorBase):
use_parallel_executor
=
True
)
use_parallel_executor
=
True
)
self
.
assertAlmostEquals
(
self
.
assertAlmostEquals
(
np
.
mean
(
parallel_first_loss
),
single_first_loss
,
delta
=
1e-6
)
np
.
mean
(
parallel_first_loss
),
single_first_loss
,
delta
=
1e-6
,
)
self
.
assertAlmostEquals
(
self
.
assertAlmostEquals
(
np
.
mean
(
parallel_last_loss
),
single_last_loss
,
delta
=
1e-6
)
np
.
mean
(
parallel_last_loss
),
single_last_loss
,
delta
=
1e-6
)
...
@@ -189,7 +191,7 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -189,7 +191,7 @@ class TestMNIST(TestParallelExecutorBase):
self
.
check_simple_fc_parallel_accuracy
(
True
)
self
.
check_simple_fc_parallel_accuracy
(
True
)
self
.
check_simple_fc_parallel_accuracy
(
False
)
self
.
check_simple_fc_parallel_accuracy
(
False
)
def
check_batchnorm_fc_convergence
(
self
,
use_cuda
):
def
check_batchnorm_fc_convergence
(
self
,
use_cuda
,
use_fast_executor
):
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
return
return
...
@@ -201,11 +203,13 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -201,11 +203,13 @@ class TestMNIST(TestParallelExecutorBase):
fc_with_batchnorm
,
fc_with_batchnorm
,
feed_dict
=
{
"image"
:
img
,
feed_dict
=
{
"image"
:
img
,
"label"
:
label
},
"label"
:
label
},
use_cuda
=
use_cuda
)
use_cuda
=
use_cuda
,
use_fast_executor
=
use_fast_executor
)
def
test_batchnorm_fc
(
self
):
def
test_batchnorm_fc
(
self
):
self
.
check_batchnorm_fc_convergence
(
True
)
for
use_cuda
in
(
False
,
True
):
self
.
check_batchnorm_fc_convergence
(
False
)
for
use_fast_executor
in
(
False
,
True
):
self
.
check_batchnorm_fc_convergence
(
use_cuda
,
use_fast_executor
)
def
test_batchnorm_fc_with_new_strategy
(
self
):
def
test_batchnorm_fc_with_new_strategy
(
self
):
# FIXME(zcd): close this test temporally.
# FIXME(zcd): close this test temporally.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录