Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3dc99088
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看板
未验证
提交
3dc99088
编写于
5月 23, 2023
作者:
H
huangjiyi
提交者:
GitHub
5月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move fusion_group infershape to phi (#53934)
* update * update * update * set out dtype
上级
bcf67536
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
55 deletion
+83
-55
paddle/fluid/operators/fused/fusion_group_op.cc
paddle/fluid/operators/fused/fusion_group_op.cc
+10
-55
paddle/phi/infermeta/multiary.cc
paddle/phi/infermeta/multiary.cc
+66
-0
paddle/phi/infermeta/multiary.h
paddle/phi/infermeta/multiary.h
+7
-0
未找到文件。
paddle/fluid/operators/fused/fusion_group_op.cc
浏览文件 @
3dc99088
...
...
@@ -12,7 +12,9 @@ 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/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/multiary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -21,60 +23,6 @@ class FusionGroupOp : public framework::OperatorWithKernel {
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInputs
(
"Inputs"
),
"Input"
,
"Inputs"
,
"FusionGroup"
);
OP_INOUT_CHECK
(
ctx
->
HasOutputs
(
"Outs"
),
"Output"
,
"Outs"
,
"FusionGroup"
);
auto
input_names
=
ctx
->
Inputs
(
"Inputs"
);
auto
output_names
=
ctx
->
Outputs
(
"Outs"
);
const
size_t
num_ins
=
input_names
.
size
();
const
size_t
num_outs
=
output_names
.
size
();
PADDLE_ENFORCE_GE
(
num_ins
,
1UL
,
platform
::
errors
::
InvalidArgument
(
"Expected the number of inputs >= 1. Received %d."
,
num_ins
));
PADDLE_ENFORCE_GE
(
num_outs
,
1UL
,
platform
::
errors
::
InvalidArgument
(
"Expected the number of outputs >= 1. Recived %d."
,
num_outs
));
int
type
=
ctx
->
Attrs
().
Get
<
int
>
(
"type"
);
PADDLE_ENFORCE_EQ
(
type
,
0UL
,
platform
::
errors
::
InvalidArgument
(
"Only support fusion of elementwise operations."
));
std
::
vector
<
framework
::
DDim
>
x_dims
=
ctx
->
GetInputsDim
(
"Inputs"
);
if
(
type
==
0
)
{
for
(
size_t
i
=
1
;
i
<
num_ins
;
++
i
)
{
PADDLE_ENFORCE_EQ
(
x_dims
[
0
],
x_dims
[
i
],
platform
::
errors
::
InvalidArgument
(
"All the inputs' dims is expected to be the same. "
"But received [%s] (name: %s) vs [%s] (name: %s)."
,
x_dims
[
0
],
input_names
[
0
],
x_dims
[
i
],
input_names
[
i
]));
}
std
::
vector
<
framework
::
DDim
>
out_dims
;
for
(
size_t
j
=
0
;
j
<
num_outs
;
++
j
)
{
out_dims
.
push_back
(
x_dims
[
0
]);
}
ctx
->
SetOutputsDim
(
"Outs"
,
out_dims
);
}
// Only lod of Inputs[0] would be shared with Outs.
for
(
size_t
j
=
0
;
j
<
num_outs
;
++
j
)
{
ctx
->
ShareLoD
(
"Inputs"
,
/*->*/
"Outs"
,
0
,
j
);
}
}
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -115,5 +63,12 @@ multiple operators into one. It supports several types:
}
// namespace operators
}
// namespace paddle
DECLARE_INFER_SHAPE_FUNCTOR
(
fusion_group
,
FusionGroupInferShapeFunctor
,
PD_INFER_META
(
phi
::
FusionGroupInferMeta
));
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
fusion_group
,
ops
::
FusionGroupOp
,
ops
::
FusionGroupOpMaker
);
REGISTER_OPERATOR
(
fusion_group
,
ops
::
FusionGroupOp
,
ops
::
FusionGroupOpMaker
,
FusionGroupInferShapeFunctor
);
paddle/phi/infermeta/multiary.cc
浏览文件 @
3dc99088
...
...
@@ -23,6 +23,7 @@ limitations under the License. */
#include "paddle/phi/common/scalar.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/core/meta_tensor.h"
#include "paddle/phi/core/utils/data_type.h"
#include "paddle/phi/kernels/funcs/common_shape.h"
#include "paddle/phi/kernels/funcs/concat_funcs.h"
...
...
@@ -1313,6 +1314,71 @@ void FusedLinearParamGradAddInferMeta(const MetaTensor& x,
}
}
void
FusionGroupInferMeta
(
const
std
::
vector
<
const
MetaTensor
*>&
ins
,
const
std
::
vector
<
int
>&
outs_dtype
,
const
std
::
vector
<
int
>&
inputs_dtype
,
const
std
::
string
&
func_name
,
int
type
,
std
::
vector
<
MetaTensor
*>
outs
)
{
const
size_t
num_ins
=
ins
.
size
();
const
size_t
num_outs
=
outs
.
size
();
PADDLE_ENFORCE_GE
(
num_ins
,
1UL
,
phi
::
errors
::
InvalidArgument
(
"Expected the number of inputs >= 1. Received %d."
,
num_ins
));
PADDLE_ENFORCE_GE
(
num_outs
,
1UL
,
phi
::
errors
::
InvalidArgument
(
"Expected the number of outputs >= 1. Recived %d."
,
num_outs
));
PADDLE_ENFORCE_EQ
(
type
,
0UL
,
phi
::
errors
::
InvalidArgument
(
"Only support fusion of elementwise operations."
));
std
::
vector
<
phi
::
DDim
>
x_dims
;
for
(
size_t
i
=
0
;
i
<
num_ins
;
++
i
)
{
x_dims
.
push_back
(
ins
[
i
]
->
dims
());
}
if
(
type
==
0
)
{
for
(
size_t
i
=
1
;
i
<
num_ins
;
++
i
)
{
PADDLE_ENFORCE_EQ
(
x_dims
[
0
],
x_dims
[
i
],
phi
::
errors
::
InvalidArgument
(
"All the inputs' dims is expected to be the same. "
"But received [%s] (name: %s) vs [%s] (name: %s)."
,
x_dims
[
0
],
ins
[
0
],
x_dims
[
i
],
ins
[
i
]));
}
for
(
size_t
j
=
0
;
j
<
num_outs
;
++
j
)
{
outs
[
j
]
->
set_dims
(
x_dims
[
0
]);
}
}
// Only lod of Inputs[0] would be shared with Outs.
for
(
size_t
j
=
0
;
j
<
num_outs
;
++
j
)
{
outs
[
j
]
->
share_lod
(
*
ins
[
0
]);
}
for
(
size_t
j
=
0
;
j
<
num_outs
;
++
j
)
{
if
(
outs_dtype
[
j
]
==
phi
::
TransToProtoVarType
(
phi
::
DataType
::
FLOAT16
))
{
outs
[
j
]
->
set_dtype
(
phi
::
DataType
::
FLOAT16
);
}
else
if
(
outs_dtype
[
j
]
==
phi
::
TransToProtoVarType
(
phi
::
DataType
::
FLOAT32
))
{
outs
[
j
]
->
set_dtype
(
phi
::
DataType
::
FLOAT32
);
}
else
if
(
outs_dtype
[
j
]
==
phi
::
TransToProtoVarType
(
phi
::
DataType
::
FLOAT64
))
{
outs
[
j
]
->
set_dtype
(
phi
::
DataType
::
FLOAT64
);
}
}
}
void
GenerateProposalsV2InferMeta
(
const
MetaTensor
&
scores
,
const
MetaTensor
&
bbox_deltas
,
const
MetaTensor
&
im_shape
,
...
...
paddle/phi/infermeta/multiary.h
浏览文件 @
3dc99088
...
...
@@ -268,6 +268,13 @@ void FusedLinearParamGradAddInferMeta(const MetaTensor& x,
MetaTensor
*
dweight_out
,
MetaTensor
*
dbias_out
);
void
FusionGroupInferMeta
(
const
std
::
vector
<
const
MetaTensor
*>&
ins
,
const
std
::
vector
<
int
>&
outs_dtype
,
const
std
::
vector
<
int
>&
inputs_dtype
,
const
std
::
string
&
func_name
,
int
type
,
std
::
vector
<
MetaTensor
*>
outs
);
void
GenerateProposalsV2InferMeta
(
const
MetaTensor
&
scores
,
const
MetaTensor
&
bbox_deltas
,
const
MetaTensor
&
im_shape
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录