Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
95768115
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看板
未验证
提交
95768115
编写于
10月 12, 2022
作者:
Y
Yuang Liu
提交者:
GitHub
10月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Multi groups for broadcast of sharding stage 2 (#46894)
上级
a9cc5482
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
6 deletion
+33
-6
python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_optimizer_stage2.py
.../meta_parallel/sharding/group_sharded_optimizer_stage2.py
+33
-6
未找到文件。
python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_optimizer_stage2.py
浏览文件 @
95768115
...
...
@@ -184,7 +184,10 @@ class GroupShardedOptimizerStage2(Optimizer):
# Enable gradients' reduces overlap with backward calculation.
self
.
_reduce_overlap
=
reduce_overlap
def
_set_broadcast_overlap
(
self
,
broadcast_overlap
,
layers
=
None
):
def
_set_broadcast_overlap
(
self
,
broadcast_overlap
,
layers
=
None
,
num_groups
=
None
):
# Enable post optimizer broadcasts overlap with the forward calculation of next batch.
self
.
_broadcast_overlap
=
broadcast_overlap
if
self
.
_broadcast_overlap
:
...
...
@@ -202,6 +205,27 @@ class GroupShardedOptimizerStage2(Optimizer):
"overlap broadcast may harm the performance."
)
self
.
_broadcast_order_params
=
self
.
_local_params
if
num_groups
is
None
or
num_groups
>
len
(
self
.
_broadcast_order_params
):
warnings
.
warn
(
"The num_groups for broadcast is larger than the number of params to be broadcast. "
"It will set to default value: 1 (use the default sharding group)."
)
num_groups
=
1
assert
isinstance
(
num_groups
,
int
)
and
num_groups
>
0
,
"num_groups should be a positive integer"
self
.
_number_of_broadcast_groups
=
num_groups
self
.
_broadcast_groups
=
[
None
for
_
in
range
(
self
.
_number_of_broadcast_groups
)
]
self
.
_broadcast_groups
[
0
]
=
self
.
_group
ranks
=
self
.
_group
.
ranks
for
i
in
range
(
1
,
self
.
_number_of_broadcast_groups
):
self
.
_broadcast_groups
[
i
]
=
new_group
(
ranks
)
def
_generate_master_params
(
self
,
trainable_params
):
if
self
.
offload
:
for
param
in
trainable_params
:
...
...
@@ -484,14 +508,17 @@ class GroupShardedOptimizerStage2(Optimizer):
def
_broadcast_params_overlap_forward
(
self
):
# Exchange all the shards with the other ranks,
# but overlap the broadcast with next batch's calculation.
group_idx
=
0
param2task
=
{}
for
x
in
self
.
_broadcast_order_params
:
if
x
.
trainable
:
task
=
broadcast
(
tensor
=
x
,
src
=
self
.
_group
.
ranks
[
self
.
_param2rank
[
x
.
name
]],
group
=
self
.
_group
,
sync_op
=
False
)
group
=
self
.
_broadcast_groups
[
group_idx
]
group_idx
=
(
group_idx
+
1
)
%
self
.
_number_of_broadcast_groups
task
=
broadcast
(
tensor
=
x
,
src
=
group
.
ranks
[
self
.
_param2rank
[
x
.
name
]],
group
=
group
,
sync_op
=
False
)
assert
x
.
name
not
in
param2task
param2task
[
x
.
name
]
=
task
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录