Add paged attention kernel for Spyre#23
Conversation
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
|
|
||
|
|
||
| @triton.jit | ||
| def _paged_attn_kernel_NHD_td( |
There was a problem hiding this comment.
I feel that having the _td is not really needed, if you need to import them into the same file we could do import as?
There was a problem hiding this comment.
@fabianlim I follow this convention. Is it ok with removing _td? I am neutral on this.
There was a problem hiding this comment.
ic sorry then lets leave it
| ): | ||
| HD: tl.constexpr = H * BLOCK_D | ||
|
|
||
| cur_b = tl.program_id(0) |
There was a problem hiding this comment.
im abit confused with the original kernel, it is already in tensor descriptor, I thought this repo's scope is to rewrite kernels that were previously in pointer arithmetic
There was a problem hiding this comment.
I see. I started working with tensor descriptor at first. I will drop original.py
| vv = tl.permute(v_g, (0, 2, 1, 3)) # (BLK_B, BLK_H, KV_BLOCK, D) | ||
|
|
||
| # 4-D batched matmul over (BLK_B, BLK_H) | ||
| scores = tl.dot(q, kT) # (BLK_B, BLK_H, BLOCK_Q, KV_BLOCK) |
There was a problem hiding this comment.
this is not standard triton. tl.dot cannot accept a 4D tensor. The tensor_descriptor.py needs to be runnable on other archs like GPU
| straight in as the index, and `h_start` is the second index — yielding | ||
| `(BLK_B, KV_BLOCK, BLK_H, D)` directly, with **no reshape** of the index or of | ||
| the gathered result. This maps the gather onto the Spyre indirect-access tile | ||
| more directly than the flatten/reshape of the base form. |
There was a problem hiding this comment.
will be good to have a comment that need to revisit with the physical layouts
There was a problem hiding this comment.
Thanks, I will add the comment.
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
|
@fabianlim I addressed your comments except the first one. |
fabianlim
left a comment
There was a problem hiding this comment.
comments are addressed
This PR adds a paged attention kernel based on @ani300 's implementation.
This version uses a logical (PyTorch) tensor shape.
A test using ktir-cpu passed.