Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7c2c965d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
7c2c965d
编写于
6月 27, 2023
作者:
X
xiaoguoguo626807
提交者:
GitHub
6月 27, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【prim】modify eular_beam (#54736)
* modify eular_beam * modify matmul infermeta * add test * modify timeout
上级
8dc97857
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
26 deletion
+99
-26
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+27
-26
test/legacy_test/CMakeLists.txt
test/legacy_test/CMakeLists.txt
+1
-0
test/legacy_test/test_paddlescience.py
test/legacy_test/test_paddlescience.py
+71
-0
未找到文件。
python/paddle/fluid/backward.py
浏览文件 @
7c2c965d
...
...
@@ -368,7 +368,6 @@ def _create_op_desc_(op_type, inputs, outputs, attrs):
)
),
)
op_role_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpRoleAttrName
()
op_device_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
()
...
...
@@ -1351,28 +1350,6 @@ def _append_backward_ops_(
assert
isinstance
(
rename_var_map
,
dict
)
if
core
.
_is_bwd_prim_enabled
():
grad_name_set
=
set
()
for
target
in
target_vars
:
grad_name_set
.
add
(
_append_grad_suffix_
(
target
.
name
))
for
op
in
reversed
(
block
.
ops
):
if
op
.
type
==
"fill_any_like"
:
for
out_name
in
op
.
desc
.
output_arg_names
():
grad_name_set
.
add
(
out_name
)
continue
for
var_name
in
op
.
desc
.
output_arg_names
():
grad_var_name
=
_append_grad_suffix_
(
var_name
)
if
grad_var_name
not
in
grad_name_set
:
op_desc
=
_create_op_desc_
(
"fill_any_like"
,
{
"X"
:
[
var_name
]},
{
"Out"
:
[
grad_var_name
]},
{
'value'
:
0
,
'dtype'
:
target_vars
[
0
].
dtype
},
)
block
.
desc
.
append_op
().
copy_from
(
op_desc
)
break
block
.
program
.
_sync_with_cpp
()
composite_block
=
program
.
clone
().
current_block
()
# Create output and infer shape for operators whose output haven't
# been created.
...
...
@@ -2461,6 +2438,7 @@ def calc_gradient_helper(
target_grad_map
=
{}
rename_var_map
=
{}
skip_rename_var_list
=
[]
grad_name_set
=
set
()
for
i
,
grad
in
enumerate
(
target_gradients
):
target
=
targets
[
i
]
grad_name
=
_append_grad_suffix_
(
target
.
name
)
...
...
@@ -2490,9 +2468,10 @@ def calc_gradient_helper(
input_grad_names_set
.
add
(
grad
.
name
)
rename_var_map
[
grad_name
]
=
grad
.
name
grad_name_set
.
add
(
grad_name
)
if
core
.
_is_bwd_prim_enabled
():
core
.
_set_prim_target_grad_name
(
target_grad_map
)
# For double backward, input_grad_names is used for filter
# some non-used gradients op. rename_var_map is used to
# associate target_grad var name with first grad_op input name.
...
...
@@ -2503,7 +2482,6 @@ def calc_gradient_helper(
for
input
in
inputs
:
if
input
.
block
.
program
!=
prog
:
raise
"input must be in the same program as targets"
block_no_grad_set
=
set
(
map
(
_strip_grad_suffix_
,
no_grad_dict
[
0
]))
op_path_dict
=
dict
()
...
...
@@ -2511,9 +2489,32 @@ def calc_gradient_helper(
block
,
targets
,
inputs
,
block_no_grad_set
,
op_path_dict
)
# only for composite to add grad_op input,
# tmp_targets includes targets and other outputs
# of the same forward op who create targets
tmp_targets
=
targets
if
core
.
_is_bwd_prim_enabled
():
for
op
in
reversed
(
block
.
ops
):
if
op
.
type
==
"fill_any_like"
:
continue
for
var_name
in
op
.
desc
.
output_arg_names
():
grad_var_name
=
_append_grad_suffix_
(
var_name
)
if
grad_var_name
not
in
grad_name_set
:
op_desc
=
_create_op_desc_
(
"fill_any_like"
,
{
"X"
:
[
var_name
]},
{
"Out"
:
[
grad_var_name
]},
{
'value'
:
0
,
'dtype'
:
targets
[
0
].
dtype
},
)
block
.
desc
.
append_op
().
copy_from
(
op_desc
)
tmp_targets
.
append
(
block
.
var
(
var_name
))
break
block
.
program
.
_sync_with_cpp
()
# find no grad var by op_path
no_grad_vars
=
_find_no_grad_vars
(
block
,
op_path
,
targets
,
block_no_grad_set
block
,
op_path
,
t
mp_t
argets
,
block_no_grad_set
)
block_no_grad_set
.
update
(
no_grad_vars
)
...
...
test/legacy_test/CMakeLists.txt
浏览文件 @
7c2c965d
...
...
@@ -1000,6 +1000,7 @@ set_tests_properties(test_elementwise_add_op PROPERTIES TIMEOUT 120)
set_tests_properties
(
test_weight_decay PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_imperative_ptb_rnn_sorted_gradient PROPERTIES TIMEOUT
120
)
set_tests_properties
(
test_paddlescience PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_crop_tensor_op PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_imperative_ptb_rnn PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_imperative_save_load_v2 PROPERTIES TIMEOUT 120
)
...
...
test/legacy_test/test_paddlescience.py
0 → 100644
浏览文件 @
7c2c965d
# 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
paddle
from
paddle
import
fluid
,
jit
,
nn
paddle
.
jit
.
enable_to_static
(
True
)
fluid
.
core
.
_set_prim_all_enabled
(
True
)
x
=
paddle
.
randn
([
4
,
1
])
y
=
paddle
.
randn
([
4
,
1
])
x
.
stop_gradient
=
False
y
.
stop_gradient
=
False
model
=
nn
.
Sequential
(
nn
.
Linear
(
1
,
1
),
nn
.
Tanh
())
model2
=
nn
.
Sequential
(
nn
.
Linear
(
1
,
1
),
)
class
TestPaddleSciencemodel
(
unittest
.
TestCase
):
def
test_concat
(
self
):
@
jit
.
to_static
def
concat
(
x
,
y
):
"""abc"""
z
=
paddle
.
concat
([
x
,
y
],
0
)
out
=
model
(
z
)
out0
,
out1
=
paddle
.
split
(
out
,
2
,
axis
=
0
)
g0
=
paddle
.
grad
(
out0
,
x
)[
0
]
g1
=
paddle
.
grad
(
out1
,
y
)[
0
]
return
g0
,
g1
g0
,
g1
=
concat
(
x
,
y
)
loss
=
g0
.
sum
()
+
g1
.
sum
()
loss
.
backward
()
class
TestEularBeam
(
unittest
.
TestCase
):
def
test_eular_beam
(
self
):
@
jit
.
to_static
def
eular_beam
(
x
):
"""abc"""
z_
=
model
(
x
)
out
=
model2
(
z_
)
g0
=
paddle
.
grad
(
out
,
x
)[
0
]
g1
=
paddle
.
grad
(
g0
,
x
)[
0
]
g2
=
paddle
.
grad
(
g1
,
x
)[
0
]
g3
=
paddle
.
grad
(
g2
,
x
)[
0
]
return
g3
g3
=
eular_beam
(
x
)
loss
=
g3
.
sum
()
loss
.
backward
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录