Skip to content

Fix the performance regression with ragged attention on for llama2 7b. #172

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

Merged
merged 4 commits into from
Aug 20, 2024

Conversation

wang2yn84
Copy link
Collaborator

@wang2yn84 wang2yn84 commented Aug 19, 2024

In this PR we did the following:

  1. We split the attention calculation in the generate step into 2 parts, the self attention of the existing KV cache and the newly calculated cache. For the 2nd part, since the cache length is 1, we should not use ragged attention because of performance. That accounts for ~15% of the attention calculation time.
  2. Replace global attention out calculation with more numerical stable way.
  3. Replace args with kwargs when possible to avoid potential issues in the Attention class.

@wang2yn84 wang2yn84 requested review from qihqi and FanhaiLu1 August 19, 2024 22:00
Copy link
Collaborator

@FanhaiLu1 FanhaiLu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a short description about this PR? Did this PR fix the performance issue of ragged attention? I also saw some repeat kv change in this PR.

@wang2yn84
Copy link
Collaborator Author

Can you add a short description about this PR? Did this PR fix the performance issue of ragged attention? I also saw some repeat kv change in this PR.

That's because it's based on the another PR. After that one is pushed, I'll rebase and it'll be more clear.

@wang2yn84
Copy link
Collaborator Author

Can you add a short description about this PR? Did this PR fix the performance issue of ragged attention? I also saw some repeat kv change in this PR.

Rebased.

…ay. Fix tests. Replace args with kwargs when possible to avoid potential issues.
@wang2yn84 wang2yn84 merged commit 7307541 into main Aug 20, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

3 participants