Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f827665a
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看板
未验证
提交
f827665a
编写于
9月 15, 2020
作者:
W
Wilber
提交者:
GitHub
9月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Pass Compatible] Bind python compatible. (#27262)
上级
bd77a425
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
105 addition
and
0 deletion
+105
-0
paddle/fluid/framework/ir/transpose_flatten_concat_fuse_pass.cc
.../fluid/framework/ir/transpose_flatten_concat_fuse_pass.cc
+9
-0
paddle/fluid/pybind/CMakeLists.txt
paddle/fluid/pybind/CMakeLists.txt
+1
-0
paddle/fluid/pybind/compatible.cc
paddle/fluid/pybind/compatible.cc
+38
-0
paddle/fluid/pybind/compatible.h
paddle/fluid/pybind/compatible.h
+23
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+2
-0
python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py
...s/ir/inference/test_transpose_flatten_concat_fuse_pass.py
+32
-0
未找到文件。
paddle/fluid/framework/ir/transpose_flatten_concat_fuse_pass.cc
浏览文件 @
f827665a
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "paddle/fluid/framework/ir/graph_viz_pass.h"
#include "paddle/fluid/framework/ir/graph_viz_pass.h"
#include "paddle/fluid/framework/ir/node.h"
#include "paddle/fluid/framework/ir/node.h"
#include "paddle/fluid/framework/ir/transpose_flatten_concat_fuse_pass.h"
#include "paddle/fluid/framework/ir/transpose_flatten_concat_fuse_pass.h"
#include "paddle/fluid/framework/op_version_registry.h"
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
...
@@ -145,3 +146,11 @@ void TransposeFlattenConcatFusePass::ApplyImpl(ir::Graph *graph) const {
...
@@ -145,3 +146,11 @@ void TransposeFlattenConcatFusePass::ApplyImpl(ir::Graph *graph) const {
REGISTER_PASS
(
transpose_flatten_concat_fuse_pass
,
REGISTER_PASS
(
transpose_flatten_concat_fuse_pass
,
paddle
::
framework
::
ir
::
TransposeFlattenConcatFusePass
);
paddle
::
framework
::
ir
::
TransposeFlattenConcatFusePass
);
REGISTER_PASS_CAPABILITY
(
transpose_flatten_concat_fuse_pass
)
.
AddCombination
(
paddle
::
framework
::
compatible
::
OpVersionComparatorCombination
()
.
EQ
(
"transpose"
,
0
)
.
EQ
(
"transpose2"
,
0
)
.
EQ
(
"flatten"
,
0
)
.
EQ
(
"concat"
,
0
)
.
EQ
(
"fusion_transpose_flatten_concat"
,
0
));
paddle/fluid/pybind/CMakeLists.txt
浏览文件 @
f827665a
...
@@ -38,6 +38,7 @@ set(PYBIND_SRCS
...
@@ -38,6 +38,7 @@ set(PYBIND_SRCS
imperative.cc
imperative.cc
ir.cc
ir.cc
inference_api.cc
inference_api.cc
compatible.cc
generator_py.cc
)
generator_py.cc
)
if
(
WITH_GLOO
)
if
(
WITH_GLOO
)
...
...
paddle/fluid/pybind/compatible.cc
0 → 100644
浏览文件 @
f827665a
// Copyright (c) 2018 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.
#include "paddle/fluid/pybind/compatible.h"
#include <memory>
#include <string>
#include "paddle/fluid/framework/op_version_registry.h"
namespace
py
=
pybind11
;
using
paddle
::
framework
::
compatible
::
PassVersionCheckerRegistrar
;
namespace
paddle
{
namespace
pybind
{
void
BindCompatible
(
py
::
module
*
m
)
{
py
::
class_
<
PassVersionCheckerRegistrar
>
(
*
m
,
"PassVersionChecker"
)
.
def_static
(
"IsCompatible"
,
[](
const
std
::
string
&
name
)
->
bool
{
auto
instance
=
PassVersionCheckerRegistrar
::
GetInstance
();
return
instance
.
IsPassCompatible
(
name
);
});
}
}
// namespace pybind
}
// namespace paddle
paddle/fluid/pybind/compatible.h
0 → 100644
浏览文件 @
f827665a
// Copyright (c) 2018 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.
#pragma once
#include <pybind11/pybind11.h>
namespace
paddle
{
namespace
pybind
{
void
BindCompatible
(
pybind11
::
module
*
m
);
}
// namespace pybind
}
// namespace paddle
paddle/fluid/pybind/pybind.cc
浏览文件 @
f827665a
...
@@ -60,6 +60,7 @@ limitations under the License. */
...
@@ -60,6 +60,7 @@ limitations under the License. */
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/pybind/box_helper_py.h"
#include "paddle/fluid/pybind/box_helper_py.h"
#include "paddle/fluid/pybind/compatible.h"
#include "paddle/fluid/pybind/const_value.h"
#include "paddle/fluid/pybind/const_value.h"
#include "paddle/fluid/pybind/data_set_py.h"
#include "paddle/fluid/pybind/data_set_py.h"
#include "paddle/fluid/pybind/exception.h"
#include "paddle/fluid/pybind/exception.h"
...
@@ -2619,6 +2620,7 @@ All parameter, weight, gradient are variables in Paddle.
...
@@ -2619,6 +2620,7 @@ All parameter, weight, gradient are variables in Paddle.
BindGraph
(
&
m
);
BindGraph
(
&
m
);
BindNode
(
&
m
);
BindNode
(
&
m
);
BindInferenceApi
(
&
m
);
BindInferenceApi
(
&
m
);
BindCompatible
(
&
m
);
BindDataset
(
&
m
);
BindDataset
(
&
m
);
BindGenerator
(
&
m
);
BindGenerator
(
&
m
);
#ifdef PADDLE_WITH_CRYPTO
#ifdef PADDLE_WITH_CRYPTO
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py
浏览文件 @
f827665a
...
@@ -17,6 +17,7 @@ import numpy as np
...
@@ -17,6 +17,7 @@ import numpy as np
from
inference_pass_test
import
InferencePassTest
from
inference_pass_test
import
InferencePassTest
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
from
paddle.fluid.core
import
PassVersionChecker
class
TransposeFlattenConcatFusePassTest
(
InferencePassTest
):
class
TransposeFlattenConcatFusePassTest
(
InferencePassTest
):
...
@@ -45,6 +46,37 @@ class TransposeFlattenConcatFusePassTest(InferencePassTest):
...
@@ -45,6 +46,37 @@ class TransposeFlattenConcatFusePassTest(InferencePassTest):
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
PassVersionChecker
.
IsCompatible
(
'transpose_flatten_concat_fuse_pass'
)
class
TransposeFlattenConcatFusePassWithAxisTest
(
InferencePassTest
):
def
setUp
(
self
):
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data1
=
fluid
.
data
(
name
=
"data1"
,
shape
=
[
5
,
5
,
5
],
dtype
=
"float32"
)
data2
=
fluid
.
data
(
name
=
"data2"
,
shape
=
[
5
,
5
,
5
],
dtype
=
"float32"
)
trans1
=
fluid
.
layers
.
transpose
(
data1
,
perm
=
[
2
,
1
,
0
])
trans2
=
fluid
.
layers
.
transpose
(
data2
,
perm
=
[
2
,
1
,
0
])
flatt1
=
fluid
.
layers
.
flatten
(
trans1
,
axis
=
2
)
flatt2
=
fluid
.
layers
.
flatten
(
trans2
,
axis
=
2
)
concat_out
=
fluid
.
layers
.
concat
([
flatt1
,
flatt2
],
axis
=
1
)
# There is no parameters for above structure.
# Hence, append a batch_norm to avoid failure caused by load_combined.
out
=
fluid
.
layers
.
batch_norm
(
concat_out
,
is_test
=
True
)
self
.
feeds
=
{
"data1"
:
np
.
random
.
random
([
5
,
5
,
5
]).
astype
(
"float32"
),
"data2"
:
np
.
random
.
random
([
5
,
5
,
5
]).
astype
(
"float32"
)
}
self
.
fetch_list
=
[
out
]
def
test_check_output
(
self
):
# There is no cpu pass for transpose_flatten_concat_fuse
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
PassVersionChecker
.
IsCompatible
(
'transpose_flatten_concat_fuse_pass'
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录