Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2f24b2d8
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看板
未验证
提交
2f24b2d8
编写于
1月 17, 2023
作者:
W
WangZhen
提交者:
GitHub
1月 17, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2St]Support call backward() without params in dy2st (#49812)
* Support call backward() without params in dy2st
上级
989e39a5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
14 deletion
+52
-14
paddle/fluid/operators/select_output_op.cc
paddle/fluid/operators/select_output_op.cc
+2
-1
paddle/fluid/pybind/eager_legacy_custom_python_api.h
paddle/fluid/pybind/eager_legacy_custom_python_api.h
+2
-2
python/paddle/fluid/tests/unittests/dygraph_to_static/test_backward_without_params.py
...ittests/dygraph_to_static/test_backward_without_params.py
+45
-0
python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py
...d/tests/unittests/dygraph_to_static/test_for_enumerate.py
+1
-0
python/paddle/jit/dy2static/partial_program.py
python/paddle/jit/dy2static/partial_program.py
+2
-11
未找到文件。
paddle/fluid/operators/select_output_op.cc
浏览文件 @
2f24b2d8
...
...
@@ -95,7 +95,8 @@ class SelectOutputInferShape : public framework::InferShapeBase {
void
operator
()(
framework
::
InferShapeContext
*
context
)
const
override
{
OP_INOUT_CHECK
(
context
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"SelectOutput"
);
OP_INOUT_CHECK
(
context
->
HasInput
(
"Mask"
),
"Input"
,
"Mask"
,
"SelectOutput"
);
OP_INOUT_CHECK
(
context
->
HasOutputs
(
"Out"
),
"Output"
,
"Out"
,
"SelectOutput"
);
OP_INOUT_CHECK
(
context
->
HasOutputs
(
"Out"
,
true
),
"Output"
,
"Out"
,
"SelectOutput"
);
}
};
...
...
paddle/fluid/pybind/eager_legacy_custom_python_api.h
浏览文件 @
2f24b2d8
...
...
@@ -26,9 +26,9 @@ static PyObject *eager_api_run_program(PyObject *self,
PyObject
*
kwargs
)
{
PyThreadState
*
tstate
=
nullptr
;
try
{
auto
X
=
GetTensorListFromArgs
(
"run_program"
,
"X"
,
args
,
0
,
fals
e
);
auto
X
=
GetTensorListFromArgs
(
"run_program"
,
"X"
,
args
,
0
,
tru
e
);
auto
Params
=
GetTensorListFromArgs
(
"run_program"
,
"Params"
,
args
,
1
,
true
);
auto
Out
=
GetTensorPtrListFromArgs
(
"run_program"
,
"Out"
,
args
,
2
,
fals
e
);
auto
Out
=
GetTensorPtrListFromArgs
(
"run_program"
,
"Out"
,
args
,
2
,
tru
e
);
auto
OutScope
=
GetScopePtrListFromArgs
(
"run_program"
,
"OutScope"
,
args
,
3
,
false
);
auto
DOut
=
GetTensorPtrListFromArgs
(
"run_program"
,
"DOut"
,
args
,
4
,
true
);
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_backward_without_params.py
0 → 100644
浏览文件 @
2f24b2d8
# 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
numpy
as
np
import
paddle
class
Net
(
paddle
.
nn
.
Layer
):
def
__init__
(
self
):
super
(
Net
,
self
).
__init__
()
@
paddle
.
jit
.
to_static
def
forward
(
self
,
x
):
out
=
x
+
1
return
out
class
TestBackwardWithoutParams
(
unittest
.
TestCase
):
def
test_run
(
self
):
net
=
Net
()
x
=
paddle
.
ones
([
2
,
2
])
x
.
stop_gradient
=
False
out
=
net
(
x
)
loss
=
paddle
.
mean
(
out
)
loss
.
backward
()
np
.
testing
.
assert_equal
(
x
.
grad
.
numpy
(),
np
.
full
(
x
.
shape
,
0.25
))
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py
浏览文件 @
2f24b2d8
...
...
@@ -377,6 +377,7 @@ class TestTransform(TestTransformBase):
if
not
isinstance
(
dy_outs
,
(
tuple
,
list
)):
dy_outs
=
(
dy_outs
,)
self
.
dygraph_func
.
eval
()
st_outs
=
self
.
get_static_output
()
if
not
isinstance
(
st_outs
,
(
tuple
,
list
)):
st_outs
=
(
st_outs
,)
...
...
python/paddle/jit/dy2static/partial_program.py
浏览文件 @
2f24b2d8
...
...
@@ -206,10 +206,6 @@ class PartialProgramLayer:
else
:
return
core
.
Scope
()
@
LazyInitialized
def
__fake_vars
(
self
):
return
_create_fake_var
()
@
LazyInitialized
def
_double_grads
(
self
):
return
self
.
_get_double_grads
(
self
.
_origin_main_program
)
...
...
@@ -604,7 +600,7 @@ class PartialProgramLayer:
if
isinstance
(
out
,
framework
.
Variable
):
targets
.
append
(
program
.
global_block
().
var
(
out
.
name
))
if
targets
and
self
.
_params
:
if
targets
:
backward
.
gradients
(
targets
=
targets
,
inputs
=
[])
start_idx
=
len
(
main_program
.
block
(
0
).
ops
)
+
2
*
len
(
...
...
@@ -1123,12 +1119,7 @@ class PartialProgramLayer:
)
def
_valid_vars
(
self
,
vars
):
"""
Note: run_program_op.InferShape requires `X`/'Out' not be null.
But it's common in dy2static, fake varBase is created to handle the
problem.
"""
return
vars
if
vars
else
self
.
__fake_vars
return
vars
if
vars
else
None
def
_create_fake_var
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录