-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
Cache: Static cache as a standalone object #30476
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa0b05e
working :D
gante 56cf73b
tmp commit
gante 97aa785
working on generate too; make fixup
gante a6853a1
dbrx
gante 326a1c7
missing in dbrx
gante 9de9556
more dbrx details; gemma
gante 90771df
tmp
gante cd6aecd
finalized mvp
gante b8caa5e
test for different cuda compute capabilities
gante 16e01f2
missing doc entry
gante 2d1eab8
tmp commit
gante bb159d2
final nits
gante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
final nits
- Loading branch information
commit bb159d293d15b49329271c851b54a8446c0ce5ca
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import unittest | ||
|
||
import pytest | ||
from packaging import version | ||
from parameterized import parameterized | ||
|
||
from transformers import LlamaConfig, is_torch_available, set_seed | ||
|
@@ -685,6 +686,9 @@ def test_model_13b_greedy_generation(self): | |
def test_compile_static_cache(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should require torch > 2.2 |
||
# `torch==2.2` will throw an error on this test (as in other compilation tests), but torch==2.1.2 and torch>2.2 | ||
# work as intended. See https://github.com/pytorch/pytorch/issues/121943 | ||
if version.parse(torch.__version__) < version.parse("2.3.0"): | ||
self.skipTest("This test requires torch >= 2.3 to run.") | ||
|
||
NUM_TOKENS_TO_GENERATE = 40 | ||
# Note on `EXPECTED_TEXT_COMPLETION`'s diff: the current value matches the original test if the original test | ||
# was changed to have a cache of 53 tokens (as opposed to 4096), on Ampere GPUs. | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, once the StaticCache is initialized, there is no need to pass it in
past_key_values
argument. That's why additional condition is necessary. Suggestion:using_static_cache = isinstance(past_key_values, StaticCache) or isinstance( getattr(self.layers[0].self_attn, "past_key_value", None), StaticCache )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@poedator This PR changes precisely the assumption you wrote: we will always need to pass the cache, after this PR it is an object that does NOT live inside the model.
This change will make the transformers' team work easier 🤗