-
Notifications
You must be signed in to change notification settings - Fork 27k
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
New dynamic cache for sliding window attention #34352
Open
Cyrilvallez
wants to merge
60
commits into
main
Choose a base branch
from
sliding-window
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
Cyrilvallez
force-pushed
the
sliding-window
branch
4 times, most recently
from
October 24, 2024 17:23
456eda6
to
21b472c
Compare
Cyrilvallez
changed the title
Sliding window
New dynamic cache for sliding window attention
Oct 24, 2024
Cyrilvallez
force-pushed
the
sliding-window
branch
from
November 1, 2024 09:30
00b66b5
to
5efa057
Compare
Ok @ArthurZucker it has been a long time on the side but it's now ready for final review! |
Slow tests for Mistral are all good (4 failing but similar on main) |
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_position
DynamicSlidingWindowCache
, bothget_past_seen_tokens
andget_seq_length
will return the same value, so no issue thereOnce
generate
no 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.