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

[Semi AutoParall] Support Partial Semantic I #55508

Merged
merged 84 commits into from
Aug 4, 2023

Conversation

JZ-LIANG
Copy link
Contributor

@JZ-LIANG JZ-LIANG commented Jul 18, 2023

PR types

New features

PR changes

Others

Description

Pcard-70448

Background
"Partial" is a data distribution type for tensor like "Replicated" and "Sharded".
A tensor is Partial means that: its shape is the same among ranks, but the local element value in each rank is only a partial of the global value, and reduced (sum/max/min/all/any) op over ranks is need to rebuild the global tensor from the locals.
image

Motivation
Before the PR, dist_tensor in auto parallel only has two type: "Replicated" and "Sharded". And it work quite well for most hybrid parallelism scenario. It is just a design choice to introduce a third distribution type "Partial".

  1. "Partial" make it easier to explain why there need an Allreduce in Tensor Parallel (Vocab Parallel Embedding, Forward of Row Parallel Linear, Backward of Col Parallel Linear, etc ) for user and developer.
  2. "Partial" make some Optimizations easier in Dynamic Graph mode of Auto Parallel. (Previously, Auto Parallel Only has Static Graph mode, and we could delay any Allreduce by Graph Transformation Pass. But we need "Partial" semantic for these optimizations in Dynamic Graph mode)
    image

HOW
The Introducing of Partial is divided into two Stages.

First Stage(This PR):

  • Introduce partial but not allow its propagation in computation graph.
  • DistTensorAttribute will add new data member to maintain Partial related info.
  • Op's inputs will always be non-partial.
  • If an Op generate a Partial output, the partial will clean by Reshard(Redistribute) immediately.
  • Meet the need of Motivation-I

Second Stage(Future PR):

  • Allow partial to propagate in computation graph.
  • User is allowed to mark tensor as Partial for Optimization.
  • Op with linearity property will propagate the partial status from input to it output.
  • Reshard(Partial --> Replicated) would only be called before the last non-linearity Op who consumes that tensor.
  • Meet the need of Motivation-II

@paddle-bot
Copy link

paddle-bot bot commented Jul 18, 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.

@JZ-LIANG JZ-LIANG changed the title [Semi Auto] Support Partial Semantic I [Semi AutoParall] Support Partial Semantic I Jul 25, 2023
// partial map would be small (less than mesh.size)
// iterate operation (copy and comparision) would more frequency than random
// element access. <key: dim on mesh, value: partial object>
paddle::flat_hash_map<int64_t, _Partial_> partial_status_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use a map structure here? If the "dim_" in Partial indicates the mesh dim, it seems unnecessary to store another mesh dim. In addition, if one tensor has only one reduce type, is it better to use a data structure like:
Partial {
vector<int64_t> mesh_dims;
ReduceType type_;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct !
firstly I thought we would use 『set』 for partial_status_, so build the Partial struct.
then I found『map』would be better for partial_status_, in most of use cases we use dim as key to retrieve Partial .

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

MIN,
PRODUCT,
ANY,
ALL
Copy link
Contributor

Choose a reason for hiding this comment

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

ALL means?

@FeixLiu FeixLiu merged commit e3b6e02 into PaddlePaddle:develop Aug 4, 2023
cxxly pushed a commit to cxxly/Paddle that referenced this pull request Aug 7, 2023
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