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

support q offset w.r.t k/v in flash_attention function #24830

Open
yamingx opened this issue Nov 11, 2024 · 2 comments
Open

support q offset w.r.t k/v in flash_attention function #24830

yamingx opened this issue Nov 11, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@yamingx
Copy link

yamingx commented Nov 11, 2024

Thanks for open-sourcing the flash_attention kernel! A feature is badly needed to support prefix caching.

When q_seq_len < kv_seq_len, current implementation left-aligns q to k/v, e.g.:

# Left alignment:
[1, 2, 3, 4]  # q
[1, 2, 3, 4, 5, 6, 7, 8]  # k/v

However, in case of prefix-cache-aware prefill, we need q right-aligns to k/v, like:

# Right alignment:
            [1, 2, 3, 4]  # q
[1, 2, 3, 4, 5, 6, 7, 8]  # k/v

Would be great to add offset parameter in flash_attention defaulting to 0. If offset > 0, right-shift q by offset tokens; otherwise, left-shift it.

@yamingx yamingx added the enhancement New feature or request label Nov 11, 2024
@sharadmv
Copy link
Collaborator

Which attention kernel are you referring to? (We have like 3 floating around now).

@yamingx
Copy link
Author

yamingx commented Nov 12, 2024

this one:

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

No branches or pull requests

2 participants