Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e1692dc7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
e1692dc7
编写于
4月 08, 2023
作者:
K
kangguangli
提交者:
GitHub
4月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[StandaloneExe] add strategy force_sequential_run (#52652)
* add strategy force_sequential_run * fix * fix * fix * fix * fix
上级
2b40434e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
122 addition
and
1 deletion
+122
-1
paddle/fluid/framework/details/build_strategy.h
paddle/fluid/framework/details/build_strategy.h
+3
-0
paddle/fluid/pybind/parallel_executor.cc
paddle/fluid/pybind/parallel_executor.cc
+25
-0
python/paddle/fluid/executor.py
python/paddle/fluid/executor.py
+29
-1
test/standalone_executor/test_standalone_sequentail_run.py
test/standalone_executor/test_standalone_sequentail_run.py
+65
-0
未找到文件。
paddle/fluid/framework/details/build_strategy.h
浏览文件 @
e1692dc7
...
...
@@ -135,6 +135,7 @@ struct BuildStrategy {
bool
fuse_adamw_
{
false
};
// Fused feed forward
bool
fused_feedforward_
{
false
};
bool
force_sequential_run_
{
false
};
// mkldnn_enabled_op_types specify the operator type list to
// use MKLDNN acceleration. It is null in default, means
...
...
@@ -269,6 +270,8 @@ inline std::ostream &operator<<(std::ostream &os,
os
<<
"fuse_gemm_epilogue_: "
<<
strategy
.
fuse_gemm_epilogue_
<<
std
::
endl
;
os
<<
"fused_attention_: "
<<
strategy
.
fused_attention_
<<
std
::
endl
;
os
<<
"fused_feedforward_: "
<<
strategy
.
fused_feedforward_
<<
std
::
endl
;
os
<<
"force_sequential_run_: "
<<
strategy
.
force_sequential_run_
<<
std
::
endl
;
os
<<
"mkldnn_enabled_op_types_: "
;
for
(
auto
str
:
strategy
.
mkldnn_enabled_op_types_
)
{
os
<<
str
<<
", "
;
...
...
paddle/fluid/pybind/parallel_executor.cc
浏览文件 @
e1692dc7
...
...
@@ -760,6 +760,31 @@ void BindParallelExecutor(pybind11::module &m) { // NOLINT
build_strategy.fused_feedforward = True
)DOC"
)
.
def_property
(
"force_sequential_run"
,
[](
const
BuildStrategy
&
self
)
{
return
self
.
force_sequential_run_
;
},
[](
BuildStrategy
&
self
,
bool
b
)
{
PADDLE_ENFORCE_NE
(
self
.
IsFinalized
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"BuildStrategy has been finlaized, cannot be "
"configured again."
));
self
.
force_sequential_run_
=
b
;
},
R"DOC((bool, optional): force_sequential_run is used to let the `StandaloneExecutor` run ops by the
order of `ProgramDesc`. Default is False.
Examples:
.. code-block:: python
import paddle
import paddle.static as static
paddle.enable_static()
build_strategy = static.BuildStrategy()
build_strategy.fused_feedforward = True
)DOC"
)
.
def_property
(
"fuse_bn_act_ops"
,
[](
const
BuildStrategy
&
self
)
{
return
self
.
fuse_bn_act_ops_
;
},
[](
BuildStrategy
&
self
,
bool
b
)
{
...
...
python/paddle/fluid/executor.py
浏览文件 @
e1692dc7
...
...
@@ -1609,6 +1609,32 @@ class Executor:
)
feed
=
self
.
_update_feed
(
program
,
feed
)
stored_flag
=
{}
if
isinstance
(
program
,
compiler
.
CompiledProgram
)
or
isinstance
(
program
.
_graph
,
compiler
.
CompiledProgram
):
compiled_program
=
(
program
if
isinstance
(
program
,
compiler
.
CompiledProgram
)
else
program
.
_graph
)
build_strategy
=
compiled_program
.
_build_strategy
if
(
build_strategy
is
not
None
and
build_strategy
.
force_sequential_run
):
schedule_flag
=
[
'FLAGS_new_executor_serial_run'
,
'FLAGS_new_executor_sequential_run'
,
]
for
flag
in
schedule_flag
:
value
=
os
.
getenv
(
flag
,
False
)
if
isinstance
(
value
,
str
):
value
=
value
.
lower
()
value
=
True
if
value
==
'true'
else
False
stored_flag
[
flag
]
=
bool
(
value
)
set_flags
({
f
:
True
for
f
in
schedule_flag
})
program
,
new_exe
=
self
.
_executor_cache
.
get_program_and_executor
(
program
,
feed
,
...
...
@@ -1644,9 +1670,11 @@ class Executor:
else
:
tensor
.
_copy_from
(
cpu_tensor
,
self
.
place
)
ret
urn
new_exe
.
run
(
ret
=
new_exe
.
run
(
scope
,
list
(
feed
.
keys
()),
fetch_list
,
return_numpy
)
set_flags
(
stored_flag
)
return
ret
compiled
=
isinstance
(
program
,
compiler
.
CompiledProgram
)
...
...
test/standalone_executor/test_standalone_sequentail_run.py
0 → 100644
浏览文件 @
e1692dc7
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
numpy
as
np
import
paddle
class
TestStandaloneExecutor
(
unittest
.
TestCase
):
def
build_program
(
self
):
main_program
=
paddle
.
static
.
Program
()
startup_program
=
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
main_program
,
startup_program
):
a
=
paddle
.
static
.
data
(
name
=
"data"
,
shape
=
[
2
,
2
],
dtype
=
'float32'
)
b
=
paddle
.
ones
([
2
,
2
])
*
2
t
=
paddle
.
static
.
nn
.
fc
(
a
,
2
)
c
=
t
+
b
return
main_program
,
startup_program
,
[
c
]
def
run_program
(
self
,
force_sequential_run
=
False
):
seed
=
100
paddle
.
seed
(
seed
)
np
.
random
.
seed
(
seed
)
main
,
startup
,
outs
=
self
.
build_program
()
build_strategy
=
paddle
.
static
.
BuildStrategy
()
build_strategy
.
force_sequential_run
=
force_sequential_run
compiled_program
=
paddle
.
static
.
CompiledProgram
(
main
,
build_strategy
=
build_strategy
)
exe
=
paddle
.
static
.
Executor
()
scope
=
paddle
.
static
.
Scope
()
with
paddle
.
static
.
scope_guard
(
scope
):
exe
.
run
(
startup
)
data
=
np
.
ones
([
2
,
2
],
dtype
=
"float32"
)
ret
=
exe
.
run
(
compiled_program
,
feed
=
{
"data"
:
data
},
fetch_list
=
[
v
.
name
for
v
in
outs
],
)
return
ret
def
test_result
(
self
):
paddle
.
enable_static
()
ret1
=
self
.
run_program
(
True
)
ret2
=
self
.
run_program
(
False
)
np
.
testing
.
assert_array_equal
(
ret1
,
ret2
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录