-
Notifications
You must be signed in to change notification settings - Fork 31.9k
New dynamic cache for sliding window attention #34352
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
456eda6 to
21b472c
Compare
00b66b5 to
5efa057
Compare
Member
Author
|
Ok @ArthurZucker it has been a long time on the side but it's now ready for final review! |
Member
Author
|
Slow tests for Mistral are all good (4 failing but similar on main) |
Collaborator
|
Hey! As we discussed offline, not super super sure we need this. The big blocker for me is that you are changing a lot of model forward, which is something we try to avoid ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This supersedes #33619 to introduce a new
DynamicSlidingWindowCache.This cache behaves the exact same way as
DynamicCache, and contrarily toSlidingWindowCache(static variant), we can correctly continue generation from an existing cache instance (fully filled or not), with more than 1 new token added to the sequence (e.g. for prefix caching).In order for this to work I had to do the following main modifications:
get_past_seen_tokens(), which should replaceget_seq_length()(almost) everywhere. This is because once the cache is filled, the 2 will not longer provide the same information, so we need to correctly differentiate to recreate thecache_positionDynamicSlidingWindowCache, bothget_past_seen_tokensandget_seq_lengthwill return the same value, so no issue thereOnce
generateno longer returns legacy cache by default (tuples), we can make this class the default for generative models with sliding window. We cannot do it before because we would lose the information of the past seen tokens if the cache is full.It also makes a nice precedent to support the same features with the static variant in a subsequent PR.