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

Adding cached KVs #51

Merged
merged 34 commits into from
May 12, 2023
Merged

Adding cached KVs #51

merged 34 commits into from
May 12, 2023

Conversation

gkroiz
Copy link
Contributor

@gkroiz gkroiz commented May 11, 2023

This PR adds the option to cache KVs for inference. Porting changes from https://github.com/Liyang90/lit-llama/tree/cached_kvs.

main changes:

  • added KV caching
  • moved rope cache to the whole model from each attention layer
  • added mask cache to use for attention masking with cached kvs.
  • fix ops and tensors that would cause recompilation.

Fixes #21

@gkroiz
Copy link
Contributor Author

gkroiz commented May 11, 2023

cc @Liyang90 @carmocca

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

This is looking great!

generate.py Outdated Show resolved Hide resolved
generate.py Show resolved Hide resolved
generate.py Show resolved Hide resolved
generate.py Show resolved Hide resolved
generate.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
generate.py Outdated Show resolved Hide resolved
@carmocca
Copy link
Contributor

I'm getting a 30% speedup 🐎

lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

We're done here! Awesome

Copy link
Contributor

@lantiga lantiga left a comment

Choose a reason for hiding this comment

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

Looks amazing! Good to merge (I just proposed a change in capitalization of two types, just if we feel like it)

lit_parrot/model.py Outdated Show resolved Hide resolved
lit_parrot/model.py Outdated Show resolved Hide resolved
generate.py Show resolved Hide resolved
chat.py Show resolved Hide resolved
@carmocca carmocca merged commit 0b5620d into Lightning-AI:main May 12, 2023
@gkroiz gkroiz deleted the parrot_cached_kvs branch May 12, 2023 20:39
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.

KV cache for faster generation
4 participants