Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
31e380ce
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
31e380ce
编写于
11月 30, 2022
作者:
R
Roc
提交者:
GitHub
11月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Eager] fix recompute for stop_gradient and inpalce (#48471)
* fix recompute for stop_gradient and inpalce * fix ut * update
上级
12486712
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
6 deletion
+30
-6
python/paddle/distributed/fleet/recompute/recompute_hybrid.py
...on/paddle/distributed/fleet/recompute/recompute_hybrid.py
+12
-0
python/paddle/fluid/tests/unittests/collective/fleet/hybrid_parallel_pp_recompute.py
...nittests/collective/fleet/hybrid_parallel_pp_recompute.py
+18
-6
未找到文件。
python/paddle/distributed/fleet/recompute/recompute_hybrid.py
浏览文件 @
31e380ce
...
...
@@ -150,6 +150,18 @@ class _HPRecomputeFunction(PyLayer):
tensor_inputs
.
append
(
arg
)
ctx
.
tensor_indices
.
append
(
i
)
ctx
.
inputs
.
append
(
None
)
# In new dygraph mode, in some cases a subset of outputs is identity to the subset of inputs,
# which is inplace operating. When the inputs' stop_gradient is True, an
# error will occurs because the stop_gradient=True and inpalce-op are not
# supported in the same time. The solution is to mark the inputs non_differentiable
# if its stop_gradient is True.
# Note:
# If not marked non_differentiable, all output tensors' attr `stop gradient`
# will be reset to `False` in c++ backend.
# See https://github.com/PaddlePaddle/Paddle/blob/9d62efb0e6e5373823039d9eda96cd5905426c0a/paddle/fluid/pybind/eager_py_layer.cc#L388
if
framework
.
in_dygraph_mode
()
and
state
:
ctx
.
mark_non_differentiable
(
arg
)
else
:
ctx
.
inputs
.
append
(
arg
)
...
...
python/paddle/fluid/tests/unittests/collective/fleet/hybrid_parallel_pp_recompute.py
浏览文件 @
31e380ce
...
...
@@ -22,6 +22,7 @@ import paddle.distributed as dist
import
paddle.distributed.fleet
as
fleet
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddle
import
framework
from
paddle.distributed.fleet.meta_parallel
import
LayerDesc
,
PipelineLayer
from
paddle.fluid
import
layers
from
paddle.fluid.dygraph.layers
import
Layer
...
...
@@ -88,14 +89,22 @@ class TransformerNet(Layer):
class
EmbeddingPipe
(
EmbeddingNet
):
def
forward
(
self
,
x
):
return
super
().
forward
(
x
)
def
forward
(
self
,
tensors
):
if
framework
.
in_dygraph_mode
():
stable
,
x
=
tensors
return
stable
,
super
().
forward
(
x
)
else
:
return
super
().
forward
(
tensors
)
class
TransformerNetPipe
(
TransformerNet
):
def
forward
(
self
,
x
):
output
=
super
().
forward
(
x
)
return
output
def
forward
(
self
,
tensors
):
if
framework
.
in_dygraph_mode
():
stable
,
x
=
tensors
output
=
super
().
forward
(
x
)
return
stable
,
output
else
:
return
super
().
forward
(
tensors
)
class
CriterionPipe
(
Layer
):
...
...
@@ -103,6 +112,8 @@ class CriterionPipe(Layer):
super
().
__init__
()
def
forward
(
self
,
out
,
label
):
if
framework
.
in_dygraph_mode
():
out
=
out
[
-
1
]
loss
=
out
.
mean
()
return
loss
...
...
@@ -171,7 +182,8 @@ class TestDistPPTraning(unittest.TestCase):
x_data
=
np
.
random
.
randint
(
0
,
vocab_size
,
size
=
[
batch_size
,
length
])
x
=
paddle
.
to_tensor
(
x_data
)
x
.
stop_gradient
=
True
loss
=
model
.
train_batch
([
x
,
x
],
optimizer
,
scheduler
)
input_
=
(
x
,
x
)
if
framework
.
in_dygraph_mode
()
else
x
loss
=
model
.
train_batch
([
input_
,
x
],
optimizer
,
scheduler
)
# TODO(shenliang03) add utest for loss
print
(
"loss: "
,
loss
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录