Integrate ragged paged attention v2 #8791
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.
Tested:
Please Read
This PR adds validation of ragged attn inputs to
torch.ops.xla.ragged_paged_attention
and expect to run it during runtime. Please move the validation code out if we have to compile something like (or just avoid compiling this).Key Features in Ragged Paged Attention V2
swapaxes
forseq_len
andnum_head
in pre/post kernel. The kernel takesnum_head
in 2nd minor as it naturally was. We fold swapaxes to strided load/store in the kernel and apply transpose on the fly.max_num_batched_tokens
andmax_num_seqs
in the setting of mixed engine.Note: this PR does not include tests for Ragged Paged Attention kernel. Because it is already tested in jax-ml/jax#26920 and we will directly import it as source instead of keep duplicated implementations in the future.