Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8d2ce06e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
8d2ce06e
编写于
10月 20, 2022
作者:
W
wuhuachaocoding
提交者:
GitHub
10月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test for stage2 + dp (#47114)
* add test for stage2 + dp * update test for stage2 + dp. * update. * update.
上级
f0408778
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
8 deletion
+24
-8
python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_stage2.py
...uted/fleet/meta_parallel/sharding/group_sharded_stage2.py
+6
-6
python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py
...tests/collective/fleet/dygraph_group_sharded_api_eager.py
+18
-2
未找到文件。
python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_stage2.py
浏览文件 @
8d2ce06e
...
@@ -205,7 +205,7 @@ class GroupShardedStage2(nn.Layer):
...
@@ -205,7 +205,7 @@ class GroupShardedStage2(nn.Layer):
Before the gradient accumulation, scale the gradient.
Before the gradient accumulation, scale the gradient.
"""
"""
if
self
.
_dp_group
is
None
:
if
self
.
_dp_group
is
None
or
self
.
_dp_group
.
nranks
<=
1
:
scale_factor
=
self
.
_world_size_scaling
scale_factor
=
self
.
_world_size_scaling
else
:
else
:
scale_factor
=
1.0
/
(
self
.
_group
.
nranks
*
self
.
_dp_group
.
nranks
)
scale_factor
=
1.0
/
(
self
.
_group
.
nranks
*
self
.
_dp_group
.
nranks
)
...
@@ -296,7 +296,7 @@ class GroupShardedStage2(nn.Layer):
...
@@ -296,7 +296,7 @@ class GroupShardedStage2(nn.Layer):
self
.
_group
,
self
.
_group
,
sync_op
=
True
)
sync_op
=
True
)
if
self
.
_dp_group
:
if
self
.
_dp_group
and
self
.
_dp_group
.
nranks
>
1
:
collective
.
broadcast
(
buffer
,
collective
.
broadcast
(
buffer
,
self
.
_dp_group
.
ranks
[
0
],
self
.
_dp_group
.
ranks
[
0
],
self
.
_dp_group
,
self
.
_dp_group
,
...
@@ -369,8 +369,8 @@ class GroupShardedStage2(nn.Layer):
...
@@ -369,8 +369,8 @@ class GroupShardedStage2(nn.Layer):
group
=
self
.
_group
,
group
=
self
.
_group
,
sync_op
=
not
self
.
_reduce_overlap
))
sync_op
=
not
self
.
_reduce_overlap
))
if
self
.
_dp_group
:
if
self
.
_dp_group
and
self
.
_dp_group
.
nranks
>
1
:
assert
not
self
.
_
comm
_overlap
,
'dp + stage2 hybrid parallel only Synchronize due to the new communication lib.'
assert
not
self
.
_
reduce
_overlap
,
'dp + stage2 hybrid parallel only Synchronize due to the new communication lib.'
#TODO(wuhuachao):after the new communication lib upgrading, overlapping the comm of dp + stage2.
#TODO(wuhuachao):after the new communication lib upgrading, overlapping the comm of dp + stage2.
collective
.
all_reduce
(
tensor
=
param
.
grad
,
collective
.
all_reduce
(
tensor
=
param
.
grad
,
group
=
self
.
_dp_group
,
group
=
self
.
_dp_group
,
...
@@ -426,8 +426,8 @@ class GroupShardedStage2(nn.Layer):
...
@@ -426,8 +426,8 @@ class GroupShardedStage2(nn.Layer):
group
=
self
.
_group
,
group
=
self
.
_group
,
sync_op
=
not
self
.
_reduce_overlap
))
sync_op
=
not
self
.
_reduce_overlap
))
if
self
.
_dp_group
:
if
self
.
_dp_group
and
self
.
_dp_group
.
nranks
>
1
:
assert
not
self
.
_
comm
_overlap
,
'dp + stage2 hybrid parallel only Synchronize due to the new communication lib.'
assert
not
self
.
_
reduce
_overlap
,
'dp + stage2 hybrid parallel only Synchronize due to the new communication lib.'
#TODO(wuhuachao):after the new communication lib upgrading, overlapping the comm of dp + stage2.
#TODO(wuhuachao):after the new communication lib upgrading, overlapping the comm of dp + stage2.
collective
.
all_reduce
(
tensor
=
grad_storage
.
buffer
,
collective
.
all_reduce
(
tensor
=
grad_storage
.
buffer
,
group
=
self
.
_dp_group
,
group
=
self
.
_dp_group
,
...
...
python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py
浏览文件 @
8d2ce06e
...
@@ -75,7 +75,9 @@ def train_mlp(model,
...
@@ -75,7 +75,9 @@ def train_mlp(model,
shard_level
,
shard_level
,
use_multi_precision
,
use_multi_precision
,
output_dir
,
output_dir
,
amp_level
=
'O1'
):
amp_level
=
'O1'
,
sync_buffers
=
False
,
dp_group
=
None
):
optimizer
=
optimizer_setting
(
model
=
model
,
optimizer
=
optimizer_setting
(
model
=
model
,
use_multi_precision
=
use_multi_precision
)
use_multi_precision
=
use_multi_precision
)
model
=
paddle
.
amp
.
decorate
(
models
=
model
,
model
=
paddle
.
amp
.
decorate
(
models
=
model
,
...
@@ -86,7 +88,9 @@ def train_mlp(model,
...
@@ -86,7 +88,9 @@ def train_mlp(model,
model
,
optimizer
,
scaler
=
group_sharded_parallel
(
model
=
model
,
model
,
optimizer
,
scaler
=
group_sharded_parallel
(
model
=
model
,
optimizer
=
optimizer
,
optimizer
=
optimizer
,
level
=
shard_level
,
level
=
shard_level
,
scaler
=
scaler
)
scaler
=
scaler
,
sync_buffers
=
sync_buffers
,
dp_group
=
dp_group
)
train_reader
=
paddle
.
batch
(
reader_decorator
(),
train_reader
=
paddle
.
batch
(
reader_decorator
(),
batch_size
=
batch_size
,
batch_size
=
batch_size
,
...
@@ -134,6 +138,18 @@ def test_sharding_api():
...
@@ -134,6 +138,18 @@ def test_sharding_api():
output_dir
=
tempfile
.
mkdtemp
()
output_dir
=
tempfile
.
mkdtemp
()
#test sharding + dp, just for test
dp_group
=
paddle
.
distributed
.
new_group
(
list
(
range
(
paddle
.
distributed
.
get_world_size
())))
stage2_dp_params
=
train_mlp
(
mlp1
,
shard_level
=
"os_g"
,
use_multi_precision
=
True
,
output_dir
=
output_dir
,
amp_level
=
'O2'
,
sync_buffers
=
True
,
dp_group
=
dp_group
)
# fp16
# fp16
stage2_params
=
train_mlp
(
mlp1
,
stage2_params
=
train_mlp
(
mlp1
,
shard_level
=
"os_g"
,
shard_level
=
"os_g"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录