Support SegmentID when doing data prallel SPMD#8425
Merged
Conversation
qihqi
approved these changes
Nov 27, 2024
165da7b to
c4db598
Compare
rpsilva-aws
pushed a commit
to rpsilva-aws/xla
that referenced
this pull request
Dec 6, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this is built on top of #8333
When sharding spec is provided, we also need to shard the segment ID. The data parallel case is the easiest one.
in the data parallel(or fsdp in this manner since we will do a all_gather on all parameters which make parameter full), the mesh is 1D like
(num_device, ), name=("data")and the sharding spec we passed toflash_attentionwill be("data", None, None, None). We just need to shard the segment_id the same way.The tricky part is what do we save for the backward. I think we need to save the sharded segment_ids. You can imagine that after the
enable_manual_shardingall of the computation becomes based on local shape.segment_idsis not the output of theflash_attnetionhence we don't have to bring it back to full. We saved thefull_q/k/vbut we also usedenable_manual_shardingto shard it again.Note that another tricky part is that
q_segment_idis not what we passed to the pallas kernel, we actually add one dimension to it. checkxla/torch_xla/experimental/custom_kernel.py
Lines 219 to 224 in 20f5166
q_segment_ids_fato make it more clear.