Support SegmentID when doing data prallel SPMD #8425
Merged
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_attention
will 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_sharding
all of the computation becomes based on local shape.segment_ids
is not the output of theflash_attnetion
hence we don't have to bring it back to full. We saved thefull_q/k/v
but we also usedenable_manual_sharding
to shard it again.Note that another tricky part is that
q_segment_id
is 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_fa
to make it more clear.