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

Shard MHA. #3115

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Shard MHA. #3115

merged 2 commits into from
Oct 15, 2024

Conversation

wujingyue
Copy link
Collaborator

As a follow-up to #3045.

For #2199.

wujingyue added a commit that referenced this pull request Oct 7, 2024
Similar to #3073, `sdpfa_fwd` shouldn't assume DIDs are available at
definition time. Instead, treat extra preceding dimensions as batch at
definition time and check they are device parallel at evaluation time.

This is required to land #3115.
wujingyue added a commit that referenced this pull request Oct 9, 2024
For #2199. 

This PR only shards the MLP. MHA will come in a separate PR (#3115) to
keep changes small and incremental.
Base automatically changed from wjy/forward to main October 9, 2024 17:05
@wujingyue wujingyue force-pushed the wjy/mha branch 2 times, most recently from 28fadd2 to 0ec0749 Compare October 9, 2024 17:37
@wujingyue wujingyue marked this pull request as ready for review October 9, 2024 17:38
@wujingyue
Copy link
Collaborator Author

!build

@wujingyue
Copy link
Collaborator Author

!build

Copy link
Collaborator

@samnordmann samnordmann left a comment

Choose a reason for hiding this comment

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

LGTM

[0, 2, 3],
),
)
T152_matmul = self.ops.sum(T152_local_matmul, [0]) # allreduce
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder what would happen currently if we do not decompose the matmul and the allreduce...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The first thing that'll break is that linear will produce a wrong shape. linear, as is implemented today, will output a tensor of rank input_rank + weight_rank - 2 = 5. However, we want the shape to be [d,b,s,e] and thus 4D.

T131 = self.ops.permute(T130, dims=[0, 2, 1, 3])
T137 = self.ops.reshape(T117, new_shape=[b, s, h, e // h])
T138 = self.ops.permute(T137, dims=[0, 2, 1, 3])
T123 = self.ops.reshape(T104, new_shape=[d, b, s, h // d, e // h])
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC, we pass from shape [d, b, s, e//d] to [d, b, s, h//d, e//h]. Nothing illegal about it but it looks surprising to me so I just want to make sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I double checked -- it looks right. MHA is head parallel according to Figure 3b in https://arxiv.org/pdf/1909.08053.

@wujingyue
Copy link
Collaborator Author

!build

@wujingyue wujingyue merged commit 66c4bed into main Oct 15, 2024
33 of 34 checks passed
@wujingyue wujingyue deleted the wjy/mha branch October 15, 2024 18:13
@wujingyue wujingyue added the enhancement New feature or request label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants