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

[Question] How to support custom stride of paged_kv for hopper prefill attention #702

Open
jianfei-wangg opened this issue Dec 27, 2024 · 3 comments

Comments

@jianfei-wangg
Copy link
Contributor

Hello, I found that in 0.2.0.post1, the page_kv_t supports custom strides, which means we can use a page_layout of [max_num_pages, num_layer, 2, page_size, num_heads, head_dim]. this works fine with sm < 90 prefill kernels.

However, when I try the above configuration for sm90 prefill kernel, hopper params (flashinfer/attention/hopper/params.cuh) does not have variables like stride_page or custom_strides. So, how can I use non-continious paged_kv for sm90 prefill?

@yzh119
Copy link
Collaborator

yzh119 commented Dec 27, 2024

Hi @jianfei-wangg , yes we can use non-contiguous paged_kv for sm90 prefill.

The stride_page was converted to offsets here (we assume stride_block % stride_n == 0):

sparse_indices = block_sparse_indices_to_vector_sparse_offsets(
self._paged_kv_indices_buf,
self._paged_kv_indptr_buf,
self._vector_sparse_indices_buffer, # output
self._vector_sparse_indptr_buffer,
self._kv_lens_buffer,
stride_block // stride_n,
1, # stride_n // stride_n
page_size,
)

The reason we preprocess these offsets instead of computing offsets inside kernels is that we found that producer will be slow if we compute the offsets inside kernels:

So we want to avoid pointer arithmetic as much as possible and pre-compute the offsets.

@jianfei-wangg
Copy link
Contributor Author

@yzh119 Thanks for in-time response, I can integrate hopper attention into out framework now.
Besides, I wonder whether block_sparse_indices_to_vector_sparse_offsets can be put into PrefillSM90Plan, thus we can use sm90-attention in the same way as pre-sm90-attention.

@yzh119
Copy link
Collaborator

yzh119 commented Jan 1, 2025

I wonder whether block_sparse_indices_to_vector_sparse_offsets can be put into PrefillSM90Plan, thus we can use sm90-attention in the same way as pre-sm90-attention.

It depends on whether we are using the same indices for each layer, if so, we can move the logic to plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants