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

[Auto Parallel] Support MoE expert parallelism in dygraph auto parallel #63904

Merged
merged 9 commits into from
May 14, 2024

Conversation

pkuzyc
Copy link
Contributor

@pkuzyc pkuzyc commented Apr 26, 2024

PR Category

Auto Parallel

PR Types

New features

Description

Pcard-76459
Support MoE expert parallelism in dygraph auto parallel. In auto-parallel expert parallelism, experts' weights have different process meshes. This pr implements the expert parallelism as following:
图片 1

Main changes

  1. Add two apis local_tensor_list_from_dtensor and dtensor_from_local_list to transform the tensors between global and local meshes.
  2. Fix the problems when the input tensors of a op have different mesh, which is necessary in expert parallelism:
    1). add a skip_check_mesh flag in TensorDistAttr to skip checking whether the process mesh are different.
    2). adapt the computing of tensors with local and global process meshes in grad_clip.

Copy link

paddle-bot bot commented Apr 26, 2024

你的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.

Comment on lines 785 to 792
if set(g.process_mesh.process_ids) < set(
clip_input.process_mesh.process_ids
):
clip_input = clip_input._local_value()
else:
clip_input = paddle.distributed.reshard(
clip_input, g.process_mesh, clip_input.placements
)
Copy link
Contributor

Choose a reason for hiding this comment

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

U can refine reshard() to support reshard clip_input to g.process_mesh

Comment on lines +102 to +122
h = self.gate(x)
if self.config.run_ep:
local_val_list = (
dist.auto_parallel.api.local_tensor_list_from_dtensor(
h, self.config.mesh, 0, [dist.Shard(0)]
)
)
else:
local_val_list = paddle.split(h, num_or_sections=2, axis=0)
expert_out_list = []
for i, expert in enumerate(self.experts):
local_val = local_val_list[i]
expert_out_list.append(expert(local_val))
if self.config.run_ep:
out = dist.auto_parallel.api.dtensor_from_local_list(
expert_out_list, self.config.mesh, [dist.Shard(0)], 0
)
else:
out = paddle.stack(expert_out_list, axis=0)
out = out.reshape((-1, self.config.class_num))
return out
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, we need to polish the api of ep

zhiqiu
zhiqiu previously approved these changes May 7, 2024
Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

The comments can be fixed in the future.

Copy link

paddle-ci-bot bot commented May 8, 2024

Sorry to inform you that ad7fd06's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for set_tests_properties(test_semi_auto_parallel_simple_net_ep PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE" TIMEOUT 120)

Copy link
Contributor

@heavyrain-lzy heavyrain-lzy left a comment

Choose a reason for hiding this comment

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

LGTM for ops.yaml

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiqiu zhiqiu merged commit 3f4cf83 into PaddlePaddle:develop May 14, 2024
30 of 31 checks passed
@JZ-LIANG JZ-LIANG self-requested a review June 20, 2024 08:37
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