Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b4d7e1e0
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看板
未验证
提交
b4d7e1e0
编写于
7月 11, 2023
作者:
Z
zhangbo9674
提交者:
GitHub
7月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR] Add op compat info for grad op (#55277)
* fix bug * fix bug * fix bug
上级
036c0ae1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
23 deletion
+38
-23
paddle/fluid/ir/dialect/op_generator/op_gen.py
paddle/fluid/ir/dialect/op_generator/op_gen.py
+25
-9
paddle/fluid/ir_adaptor/translator/op_compat_gen.py
paddle/fluid/ir_adaptor/translator/op_compat_gen.py
+8
-8
test/cpp/ir/core/program_translator_test.cc
test/cpp/ir/core/program_translator_test.cc
+5
-6
未找到文件。
paddle/fluid/ir/dialect/op_generator/op_gen.py
浏览文件 @
b4d7e1e0
...
@@ -138,6 +138,14 @@ DEFINE_OP_TYPE_ID = """
...
@@ -138,6 +138,14 @@ DEFINE_OP_TYPE_ID = """
IR_DEFINE_EXPLICIT_TYPE_ID({op_name})
IR_DEFINE_EXPLICIT_TYPE_ID({op_name})
"""
"""
scalar_type_maps
=
{
'int'
:
'ir::Int32Attribute'
,
'int64_t'
:
'ir::Int64Attribute'
,
'float'
:
'ir::FloatAttribute'
,
'dobule'
:
'ir::DoubleAttribute'
,
'bool'
:
'ir::BoolAttribute'
,
}
def
to_phi_and_fluid_op_name
(
op_item
):
def
to_phi_and_fluid_op_name
(
op_item
):
# Templat: - op : phi_name (fluid_name)
# Templat: - op : phi_name (fluid_name)
...
@@ -151,13 +159,14 @@ def to_phi_and_fluid_op_name(op_item):
...
@@ -151,13 +159,14 @@ def to_phi_and_fluid_op_name(op_item):
return
phi_name
,
fluid_name
return
phi_name
,
fluid_name
scalar_type_maps
=
{
def
to_phi_and_fluid_grad_op_name
(
op_item
):
'int'
:
'ir::Int32Attribute'
,
# Templat: sum_grad (reduce_sum_grad), sum_double_grad
'int64_t'
:
'ir::Int64Attribute'
,
rtn
=
[]
'float'
:
'ir::FloatAttribute'
,
all_names
=
op_item
.
split
(
', '
)
'dobule'
:
'ir::DoubleAttribute'
,
for
name
in
all_names
:
'bool'
:
'ir::BoolAttribute'
,
backward_phi_name
,
backward_fluid_name
=
to_phi_and_fluid_op_name
(
name
)
}
rtn
.
append
([
backward_phi_name
,
backward_fluid_name
])
return
rtn
# =====================================
# =====================================
...
@@ -171,9 +180,16 @@ class OpCompatParser:
...
@@ -171,9 +180,16 @@ class OpCompatParser:
def
get_compat
(
self
,
op_name
):
def
get_compat
(
self
,
op_name
):
for
compat
in
self
.
ops_compat
:
for
compat
in
self
.
ops_compat
:
phi_name
,
fluid_name
=
to_phi_and_fluid_op_name
(
compat
[
'op'
])
forward_phi_name
,
forward_fluid_name
=
to_phi_and_fluid_op_name
(
if
op_name
==
phi_name
:
compat
[
'op'
]
)
if
op_name
==
forward_phi_name
:
return
compat
return
compat
elif
'backward'
in
compat
.
keys
():
bkw_names
=
to_phi_and_fluid_grad_op_name
(
compat
[
'backward'
])
for
name
in
bkw_names
:
if
op_name
==
name
[
0
]:
return
compat
return
None
return
None
...
...
paddle/fluid/ir_adaptor/translator/op_compat_gen.py
浏览文件 @
b4d7e1e0
...
@@ -114,17 +114,17 @@ def OpNameNormalizerInitialization(
...
@@ -114,17 +114,17 @@ def OpNameNormalizerInitialization(
insert_new_mutable_attributes
(
insert_new_mutable_attributes
(
legacy_name
,
op_compat_item
[
"int_array"
]
legacy_name
,
op_compat_item
[
"int_array"
]
)
)
for
backward_op
in
legacy_backward_op_names
:
insert_new_mutable_attributes
(
backward_op
,
op_compat_item
[
"int_array"
]
)
if
"scalar"
in
op_compat_item
:
if
"scalar"
in
op_compat_item
:
insert_new_mutable_attributes
(
legacy_name
,
op_compat_item
[
"scalar"
])
insert_new_mutable_attributes
(
legacy_name
,
op_compat_item
[
"scalar"
])
for
backward_op
in
legacy_backward_op_names
:
if
"int_array"
in
op_compat_item
:
insert_new_mutable_attributes
(
insert_new_mutable_attributes
(
backward_op
,
op_compat_item
[
"scalar"
]
legacy_name
,
op_compat_item
[
"int_array"
]
)
)
if
"scalar"
in
op_compat_item
:
insert_new_mutable_attributes
(
legacy_name
,
op_compat_item
[
"scalar"
])
# special op mappings
# special op mappings
op_name_mappings
[
"fetch_v2"
]
=
"fetch"
op_name_mappings
[
"fetch_v2"
]
=
"fetch"
...
...
test/cpp/ir/core/program_translator_test.cc
浏览文件 @
b4d7e1e0
...
@@ -56,14 +56,13 @@ TEST(PaddleDialectTest, MainProgram) {
...
@@ -56,14 +56,13 @@ TEST(PaddleDialectTest, MainProgram) {
ctx
->
GetOrRegisterDialect
<
ir
::
BuiltinDialect
>
();
ctx
->
GetOrRegisterDialect
<
ir
::
BuiltinDialect
>
();
auto
program
=
paddle
::
TranslateLegacyProgramToProgram
(
p
);
auto
program
=
paddle
::
TranslateLegacyProgramToProgram
(
p
);
size_t
op_size
=
program
->
block
()
->
size
();
// ops.size() = op size in BlockDesc + get_parameter_op + combine op + int
// array op + full op
EXPECT_EQ
(
op_size
,
p
.
Block
(
0
).
OpSize
()
+
program
->
parameters_num
()
+
20
+
3
+
8
);
std
::
stringstream
ss
;
std
::
stringstream
ss
;
program
->
Print
(
ss
);
program
->
Print
(
ss
);
// ops.size() = op size in BlockDesc + get_parameter_op + combine op + int
// array op + full op (Note: p already has a full)
EXPECT_EQ
(
program
->
block
()
->
size
(),
p
.
Block
(
0
).
OpSize
()
+
program
->
parameters_num
()
+
20
+
5
+
8
);
EXPECT_GT
(
ss
.
str
().
size
(),
0u
);
EXPECT_GT
(
ss
.
str
().
size
(),
0u
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录