Skip to content
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

[AutoParallel] Support pipeline parallelism backward non-computation clip. #58449

Merged

Conversation

GhostScreaming
Copy link
Contributor

@GhostScreaming GhostScreaming commented Oct 27, 2023

PR types

New features

PR changes

Others

Description

Pcard-73145

支持流水线并行反向的非计算rank计算裁剪。前向PR参考PR 58126paddle::distributed::reshard构建前反向的PR参考PR 58238。重点对创建反向图时,对unintialized的Tensor行为进行了特殊处理。

  1. 对于IsRunAutoParallel()的情况,跳过FillZeroForEmptyGradInput处理。
  2. SetGradInMeta特殊处理PP的情况
  3. GradTensorHolder::add特殊处理PP的情况,防止反向节点之间的边未连接。

@paddle-bot
Copy link

paddle-bot bot commented Oct 27, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Oct 27, 2023
wanghuancoder
wanghuancoder previously approved these changes Oct 30, 2023
Comment on lines 2227 to 2232
fill_zero_str += f"{indent}if (!IsRunAutoParallel()) {{\n{indent}{indent}egr::EagerUtils::FillZeroForEmptyOptionalGradInput(&grads[{fwd_position}][0], input_metas[{fwd_position}][0]);\n{indent}}}"
else:
if IsPlainTensorType(ttype):
fill_zero_str += f"{indent}egr::EagerUtils::FillZeroForEmptyGradInput(&grads[{fwd_position}][0], input_metas[{fwd_position}][0]);\n"
fill_zero_str += f"{indent}if (!IsRunAutoParallel()) {{\n{indent}{indent}egr::EagerUtils::FillZeroForEmptyGradInput(&grads[{fwd_position}][0], input_metas[{fwd_position}][0]);\n{indent}}}"
else:
fill_zero_str += f"{indent}egr::EagerUtils::FillZeroForEmptyGradInput(&grads[{fwd_position}], input_metas[{fwd_position}]);\n"
fill_zero_str += f"{indent}if (!IsRunAutoParallel()) {{\n{indent}{indent}egr::EagerUtils::FillZeroForEmptyGradInput(&grads[{fwd_position}], input_metas[{fwd_position}]);\n{indent}}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这个if是所有情况都要有的。可以放到FillZeroForEmptyOptionalGradInput和FillZeroForEmptyGradInput函数里来实现。放在gen.py里会越来越难维护。生成的代码也不容易阅读。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsRunAutoParallel()方法绑定在GradNodeBase类里,判断条件放在nodes.cc代码会简洁一点。修改了eager_gen.py的代码生成逻辑,增强代码可读性,thx~

self.mp_loss, _, _ = self.run_dynamic(
PPDemoNet(self.w0, self.w1, self._pp_mesh0, self._pp_mesh1),
is_pp=True,
self.mp_loss, self.mp_w0, self.mp_w1 = self.run_dynamic(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥是mp_loss

# modify test_semi_auto_parallel_hybrid_strategy.py `setUp` function,
# just set num_of_devices=8, nnode =1 and _changeable_envs = {"backend": ["gpu"]}
# to test it.
# self.dp_mp_pp_demo_net()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个单测原来也是CPU模拟执行的,这里三种策略混合CI会挂吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在pp的send/recv不支持在CPU执行,会挂掉

wanghuancoder
wanghuancoder previously approved these changes Oct 31, 2023
@GhostScreaming GhostScreaming merged commit c569297 into PaddlePaddle:develop Nov 2, 2023
XieYunshen pushed a commit that referenced this pull request Nov 2, 2023
GhostScreaming added a commit to GhostScreaming/Paddle that referenced this pull request Nov 2, 2023
GhostScreaming added a commit that referenced this pull request Nov 2, 2023
…clip. (#58609)

* [AutoParallel] Support paddle.distributed.reshard construct GradNode,
which is needed for pipeline parallel.

* Fix problem of CI, and fix pp testcase as review comments advising.

* Fix including files problem.

* Polish paddle.distributed.reshard implementation according to review comments.

* Fix some problems.

* Polish code.

* Fix problem of failed testcase.

* Move reshard function to tensor_utils.h, as files in phi/core is
not allowed to include files in phi/api.

* Add forgetting file.

* Fix some compilation problem.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Fix problem of WITH_PYTHON=OFF compilation option.

* Fix bug of conditional compilation.

* [AutoParallel] Support pipeline parallel backward. Both pp single
strategy and dp-mp-pp hybrid strategy are verified. As CI machine
only has 2 cards and dp-mp-pp strategy needs 9 GPU cards, such case
will be added in testcase later.

* Polish pipeline parallel backward implementation.

* Remove useless modification.

* Add MLP dp-mp-pp hybrid strategy testcase, it can't be run on
CI Machine now as it needs 8 gpus.

* Remove useless modification.

* Fix problem of Tensor double free and polish code.

* Fix problem of ReshardOutputPartialAxisToReplicated.

* Revert "Revert "[AutoParallel] Support pipeline parallelism backward non-computation clip. (#58449)" (#58601)"

This reverts commit 79e24ec.
@paddle-bot paddle-bot bot removed the contributor External developers label Nov 3, 2023
zeroRains pushed a commit to zeroRains/Paddle that referenced this pull request Nov 8, 2023
…clip. (PaddlePaddle#58449)

* [AutoParallel] Support paddle.distributed.reshard construct GradNode,
which is needed for pipeline parallel.

* Fix problem of CI, and fix pp testcase as review comments advising.

* Fix including files problem.

* Polish paddle.distributed.reshard implementation according to review comments.

* Fix some problems.

* Polish code.

* Fix problem of failed testcase.

* Move reshard function to tensor_utils.h, as files in phi/core is
not allowed to include files in phi/api.

* Add forgetting file.

* Fix some compilation problem.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Fix problem of WITH_PYTHON=OFF compilation option.

* Fix bug of conditional compilation.

* [AutoParallel] Support pipeline parallel backward. Both pp single
strategy and dp-mp-pp hybrid strategy are verified. As CI machine
only has 2 cards and dp-mp-pp strategy needs 9 GPU cards, such case
will be added in testcase later.

* Polish pipeline parallel backward implementation.

* Remove useless modification.

* Add MLP dp-mp-pp hybrid strategy testcase, it can't be run on
CI Machine now as it needs 8 gpus.

* Remove useless modification.

* Fix problem of Tensor double free and polish code.

* Fix problem of ReshardOutputPartialAxisToReplicated.
zeroRains pushed a commit to zeroRains/Paddle that referenced this pull request Nov 8, 2023
zeroRains pushed a commit to zeroRains/Paddle that referenced this pull request Nov 8, 2023
…clip. (PaddlePaddle#58609)

* [AutoParallel] Support paddle.distributed.reshard construct GradNode,
which is needed for pipeline parallel.

* Fix problem of CI, and fix pp testcase as review comments advising.

* Fix including files problem.

* Polish paddle.distributed.reshard implementation according to review comments.

* Fix some problems.

* Polish code.

* Fix problem of failed testcase.

* Move reshard function to tensor_utils.h, as files in phi/core is
not allowed to include files in phi/api.

* Add forgetting file.

* Fix some compilation problem.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Fix problem of WITH_PYTHON=OFF compilation option.

* Fix bug of conditional compilation.

* [AutoParallel] Support pipeline parallel backward. Both pp single
strategy and dp-mp-pp hybrid strategy are verified. As CI machine
only has 2 cards and dp-mp-pp strategy needs 9 GPU cards, such case
will be added in testcase later.

* Polish pipeline parallel backward implementation.

* Remove useless modification.

* Add MLP dp-mp-pp hybrid strategy testcase, it can't be run on
CI Machine now as it needs 8 gpus.

* Remove useless modification.

* Fix problem of Tensor double free and polish code.

* Fix problem of ReshardOutputPartialAxisToReplicated.

* Revert "Revert "[AutoParallel] Support pipeline parallelism backward non-computation clip. (PaddlePaddle#58449)" (PaddlePaddle#58601)"

This reverts commit 79e24ec.
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
…clip. (PaddlePaddle#58449)

* [AutoParallel] Support paddle.distributed.reshard construct GradNode,
which is needed for pipeline parallel.

* Fix problem of CI, and fix pp testcase as review comments advising.

* Fix including files problem.

* Polish paddle.distributed.reshard implementation according to review comments.

* Fix some problems.

* Polish code.

* Fix problem of failed testcase.

* Move reshard function to tensor_utils.h, as files in phi/core is
not allowed to include files in phi/api.

* Add forgetting file.

* Fix some compilation problem.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Fix problem of WITH_PYTHON=OFF compilation option.

* Fix bug of conditional compilation.

* [AutoParallel] Support pipeline parallel backward. Both pp single
strategy and dp-mp-pp hybrid strategy are verified. As CI machine
only has 2 cards and dp-mp-pp strategy needs 9 GPU cards, such case
will be added in testcase later.

* Polish pipeline parallel backward implementation.

* Remove useless modification.

* Add MLP dp-mp-pp hybrid strategy testcase, it can't be run on
CI Machine now as it needs 8 gpus.

* Remove useless modification.

* Fix problem of Tensor double free and polish code.

* Fix problem of ReshardOutputPartialAxisToReplicated.
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
…clip. (PaddlePaddle#58609)

* [AutoParallel] Support paddle.distributed.reshard construct GradNode,
which is needed for pipeline parallel.

* Fix problem of CI, and fix pp testcase as review comments advising.

* Fix including files problem.

* Polish paddle.distributed.reshard implementation according to review comments.

* Fix some problems.

* Polish code.

* Fix problem of failed testcase.

* Move reshard function to tensor_utils.h, as files in phi/core is
not allowed to include files in phi/api.

* Add forgetting file.

* Fix some compilation problem.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Remove useless PADDLE_WITH_DISTRIBUTE conditional compilation.

* Fix problem of WITH_PYTHON=OFF compilation option.

* Fix bug of conditional compilation.

* [AutoParallel] Support pipeline parallel backward. Both pp single
strategy and dp-mp-pp hybrid strategy are verified. As CI machine
only has 2 cards and dp-mp-pp strategy needs 9 GPU cards, such case
will be added in testcase later.

* Polish pipeline parallel backward implementation.

* Remove useless modification.

* Add MLP dp-mp-pp hybrid strategy testcase, it can't be run on
CI Machine now as it needs 8 gpus.

* Remove useless modification.

* Fix problem of Tensor double free and polish code.

* Fix problem of ReshardOutputPartialAxisToReplicated.

* Revert "Revert "[AutoParallel] Support pipeline parallelism backward non-computation clip. (PaddlePaddle#58449)" (PaddlePaddle#58601)"

This reverts commit 79e24ec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants