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

feat(checkpoint): TP recomputation communication optimization #275

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

li126com
Copy link
Collaborator

@li126com li126com commented Jul 8, 2024

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Refer to mindspeed:

When tensor parallelism is enabled, an AllReduce operation is inserted at the end of the forward pass. In the backward pass, this corresponds to an Identity operation. Since recomputation is only used to retrieve intermediate activation values, the output of the AllReduce at the end of the recomputation is redundant. Therefore, the AllReduce at the end can be removed without affecting the intermediate calculations or subsequent backward calculations.

When sequence parallelism is enabled, a ReduceScatter communication is inserted at the end of the forward pass, and an AllGather communication is inserted in the backward pass. During recomputation, the ReduceScatter communication can be directly removed. Additionally, since the gradient at the very end is not related to recomputation, the AllGather in the backward pass can overlap with the forward recomputation. This is illustrated in the diagram below.

企业微信截图_17204118124011

7B tp=4 checkpoint tgs:
mtp: 2215->2269
msp: 2309->2336

Loss

image

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

@li126com li126com requested a review from SolenoidWGT July 8, 2024 04:24
internlm/initialize/launch.py Outdated Show resolved Hide resolved
internlm/model/modeling_internlm.py Outdated Show resolved Hide resolved
internlm/model/modeling_internlm2.py Outdated Show resolved Hide resolved
internlm/solver/activation_checkpoint.py Outdated Show resolved Hide resolved
in_features,
out_features,
bias,
multiple_of,
device,
dtype,
)
if name == "w2":
Copy link
Contributor

Choose a reason for hiding this comment

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

这样会不会很hardcode?

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.

5 participants