-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
segment parallel parameter sync and grad sync #57061
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d049b52
sep grad all sync
liuzhenhai93 6edbe8c
polish
liuzhenhai93 0057aae
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuzhenhai93 a5700a3
polish
liuzhenhai93 07ede60
polish
liuzhenhai93 08a9137
polish
liuzhenhai93 67d8da8
add test
liuzhenhai93 2bf3f03
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuzhenhai93 a882e9e
add test, and align with dp
liuzhenhai93 cb65c7a
follow comment
liuzhenhai93 2070ebc
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuzhenhai93 b14df32
polish
liuzhenhai93 70f2030
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuzhenhai93 1157b23
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuzhenhai93 310ba7e
polish
liuzhenhai93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
python/paddle/distributed/fleet/meta_parallel/segment_parallel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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. | ||
|
||
from ..utils.hybrid_parallel_util import ( | ||
broadcast_dp_parameters, | ||
broadcast_sep_parameters, | ||
broadcast_sharding_parameters, | ||
) | ||
from ..utils.log_util import logger | ||
from .meta_parallel_base import MetaParallelBase | ||
|
||
__all__ = [] | ||
|
||
|
||
class SegmentParallel(MetaParallelBase): | ||
def __init__(self, layers, hcg, **kwargs): | ||
super().__init__(layers, hcg, **kwargs) | ||
|
||
def _prepare_for_model(self): | ||
logger.info("start broadcast sep parameters") | ||
broadcast_sep_parameters(self._layers, self._hcg) | ||
|
||
if self._hcg.get_sharding_parallel_world_size() > 1: | ||
logger.info("start broadcast sharding parameters") | ||
broadcast_sharding_parameters(self._layers, self._hcg) | ||
|
||
if self._hcg.get_data_parallel_world_size() > 1: | ||
logger.info("start broadcast dp parameters") | ||
broadcast_dp_parameters(self._layers, self._hcg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
PipelineLayer, | ||
PipelineParallel, | ||
PipelineParallelWithInterleave, | ||
SegmentParallel, | ||
ShardingParallel, | ||
TensorParallel, | ||
) | ||
|
@@ -130,25 +131,15 @@ def distributed_model(model): | |
if fleet_env._hcg.get_parallel_mode() == ParallelMode.SHARDING_PARALLEL: | ||
model = ShardingParallel(model, fleet_env._hcg, strategy=strategy) | ||
elif fleet_env._hcg.get_parallel_mode() == ParallelMode.DATA_PARALLEL: | ||
# NOTE (JZ-LIANG) init parameters broadcast within sharding group | ||
# normally it should be done inside DataParallel | ||
if fleet_env.sharding_degree > 1: | ||
from paddle.distributed.fleet.utils.hybrid_parallel_util import ( | ||
broadcast_sharding_parameters, | ||
) | ||
|
||
assert ( | ||
fleet_env.sharding_degree | ||
== fleet_env._hcg.get_sharding_parallel_world_size() | ||
) | ||
broadcast_sharding_parameters(model, fleet_env._hcg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个地方删除代码是为了什么? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sharding > 1 and dp > 1 改成在 shardding_parallel里处理 |
||
model = paddle.DataParallel( | ||
model, | ||
comm_buffer_size=strategy.fuse_grad_size_in_MB, | ||
last_comm_buffer_size=strategy.last_comm_group_size_MB, | ||
find_unused_parameters=strategy.find_unused_parameters, | ||
group=fleet_env._hcg.get_data_parallel_group(), | ||
) | ||
elif fleet_env._hcg.get_parallel_mode() == ParallelMode.SEGMENT_PARALLEL: | ||
model = SegmentParallel(model, fleet_env._hcg, strategy=strategy) | ||
elif fleet_env._hcg.get_parallel_mode() == ParallelMode.TENSOR_PARALLEL: | ||
model = TensorParallel(model, fleet_env._hcg, strategy=strategy) | ||
elif fleet_env._hcg.get_parallel_mode() == ParallelMode.PIPELINE_PARALLEL: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果
sharding_degree > 1 and dp_degree > 1
时,这个逻辑跟之前不太一样?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯, 这个之前写的不优雅;
sharding > 1 and dp > 1 改成在 shardding_parallel里处理