Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7f0ba045
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看板
未验证
提交
7f0ba045
编写于
7月 06, 2023
作者:
C
cyber-pioneer
提交者:
GitHub
7月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Prim] Fix none var added with op error (#55133)
* fix prim add fill_any_like bug * polish code
上级
4d1b9f04
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
38 addition
and
13 deletion
+38
-13
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+14
-0
python/paddle/fluid/core.py
python/paddle/fluid/core.py
+22
-0
python/paddle/incubate/autograd/primx.py
python/paddle/incubate/autograd/primx.py
+1
-12
test/prim/composite_ops/test_composite_batch_norm.py
test/prim/composite_ops/test_composite_batch_norm.py
+1
-1
未找到文件。
python/paddle/fluid/backward.py
浏览文件 @
7f0ba045
...
...
@@ -2500,7 +2500,21 @@ def calc_gradient_helper(
for
op
in
reversed
(
block
.
ops
):
if
op
.
type
==
"fill_any_like"
:
continue
# Some outputs of composite op are not needed and will be removed.
# Thus, those vars should not be added with another op.
keep_var_list
=
[]
if
op
.
type
in
core
.
ops_contain_none
.
keys
():
values
=
core
.
ops_contain_none
[
op
.
type
]
if
isinstance
(
values
,
list
):
none_vars
=
values
else
:
none_vars
=
values
(
op
)
for
none_var_name
in
none_vars
:
keep_var_list
.
append
(
op
.
output
(
none_var_name
)[
0
])
for
var_name
in
op
.
desc
.
output_arg_names
():
if
keep_var_list
and
(
var_name
in
keep_var_list
):
continue
grad_var_name
=
_append_grad_suffix_
(
var_name
)
if
grad_var_name
not
in
grad_name_set
:
op_desc
=
_create_op_desc_
(
...
...
python/paddle/fluid/core.py
浏览文件 @
7f0ba045
...
...
@@ -465,6 +465,28 @@ def _test_use_sync(value):
prim_config
=
{
"forward_blacklist"
:
set
(),
"composite_ops_record"
:
set
()}
def
_get_batch_norm_none_var
(
op
):
"""Some outputs of batch_norm's replaced composite rule are not needed and will be removed."""
use_run_stat
=
(
op
.
attr
(
"is_test"
)
and
(
not
op
.
attr
(
"trainable_statistics"
))
)
or
op
.
attr
(
"use_global_stats"
)
if
use_run_stat
:
return
[
"ReserveSpace"
,
"SavedMean"
,
"SavedVariance"
]
else
:
return
[
"ReserveSpace"
]
# In some case, inputs and outputs of composite op or its replaced composite rule might be None.
# It means such arg will be no longer required in processed program by composite mechanism.
# Therefore, such special ops should be recorded in advance and be released in args check.
ops_contain_none
=
{
"batch_norm"
:
_get_batch_norm_none_var
,
"flatten_contiguous_range"
:
[
"XShape"
],
"squeeze2"
:
[
"XShape"
],
"unsqueeze2"
:
[
"XShape"
],
}
def
_set_prim_forward_blacklist
(
ops
=
None
):
if
ops
is
None
:
prim_config
[
"forward_blacklist"
]
=
[]
...
...
python/paddle/incubate/autograd/primx.py
浏览文件 @
7f0ba045
...
...
@@ -18,7 +18,7 @@ from collections import OrderedDict
import
paddle
from
paddle.fluid
import
framework
from
paddle.fluid.core
import
prim_config
from
paddle.fluid.core
import
ops_contain_none
,
prim_config
from
paddle.fluid.framework
import
Operator
,
default_main_program
from
paddle.incubate.autograd.utils
import
as_tensors
...
...
@@ -549,17 +549,6 @@ def _lower(block, reverse, blacklist):
block
.
_sync_with_cpp
()
# In some case, inputs and outputs of composite op or its replaced composite rule might be None.
# It means such arg will be no longer required in processed program by composite mechanism.
# Therefore, such special ops should be recorded in advance and be released in args check.
ops_contain_none
=
(
"batch_norm"
,
"flatten_contiguous_range"
,
"squeeze2"
,
"unsqueeze2"
,
)
def
_lower_composite
(
block
,
filter_
:
typing
.
Callable
[[
framework
.
Operator
],
bool
]
=
lambda
x
:
True
,
...
...
test/prim/composite_ops/test_composite_batch_norm.py
浏览文件 @
7f0ba045
...
...
@@ -489,7 +489,7 @@ class TestPrimEvalBranch(unittest.TestCase):
def
train
(
self
,
use_prim
):
core
.
_set_prim_all_enabled
(
use_prim
)
paddle
.
seed
(
2022
)
net
=
BatchNorm
(
2
,
act
=
"relu"
,
is_test
=
True
)
net
=
BatchNorm
(
2
,
is_test
=
True
)
net
=
apply_to_static
(
net
,
False
)
out
=
net
(
self
.
x
)
loss
=
paddle
.
mean
(
out
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录