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(moe): support isp for moe #57

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

blankde
Copy link
Contributor

@blankde blankde commented Feb 26, 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

This PR supports weight parallel for moe. If isp is used, then the ws(world size) =wps*eps*edps, otherwise, ws = tp*eps*edps. Related to #44

Modification

  1. configs/7B_MoE4_sft.py: add new parallel config for expert
  2. internlm/core/context/parallel_context.py: add expert parallel and expert weight parallel check
  3. internlm/core/context/process_group_initializer.py: if isp is used, run Initializer_Expert_Weight_Data to divide Expert、Expert_Weight、Expert_Data groups. Here Expert_Data means expert weight data parallel groups, and each device only save part of weight of some experts. Otherwise, run Initializer_Expert_Data to divide Expert and Expert_Data groups.
  4. internlm/moe/gshard_moe.py: find the true mlp impl class.
  5. internlm/core/communication/isp.py: change the logic for ISPLinear check since moe linears are deeper modules in moe model.
  6. internlm/solver/optimizer/hybrid_zero_optim.py: change the logic for weight accum grad hooks
  7. internlm/train/training_internlm.py: set moe linears params as IS_WEIGHT_EXPERT_DATA_PARALLEL if isp is used
  8. internlm/solver/optimizer/utils.py: add moe linears norm calculate is isp is used

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.

@blankde blankde marked this pull request as draft February 26, 2024 02:57
2. overlap: bool, enable/disable all_gather/reduce_scatter communication overlap, defaults to False.
3. memory_pool: bool, enable/disable memory pool, defaults to False.
expert parallel (dict):
1. size: int, the size of expert parallel, each device would save {num_expert/ep_size} local experts.
expert parallel (dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

应该改成 expert weight parallel (dict): ?

@@ -71,6 +72,14 @@ def is_tensor_expert_data_parallel_parameter(p):
)


def is_weight_expert_data_parallel_parameter(p):
return (
gpc.is_initialized(ParallelMode.TENSOR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里应该是gpc.is_initialized(ParallelMode.WEIGHT)?

@blankde blankde marked this pull request as ready for review March 12, 2024 06:26
@blankde blankde marked this pull request as draft March 14, 2024 14:16
@blankde blankde marked this pull request as ready for review March 18, 2024 11:20
@blankde blankde marked this pull request as draft March 18, 2024 11:20
@blankde blankde marked this pull request as ready for review March 18, 2024 11:21
@blankde blankde marked this pull request as draft March 18, 2024 11:22
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.

None yet

3 participants