-
Notifications
You must be signed in to change notification settings - Fork 136
Fix quantized cache #30
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
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
cfa4e58
fix generate_answer for quantized cache
maxjeblick 190b3c4
fix value chache pruning
maxjeblick 4255ba1
improve test
maxjeblick d766ce9
improve test
maxjeblick 9c30df1
add integration tests
maxjeblick 4df78ef
Merge branch 'main' into max/fix_quanto_cache
maxjeblick f753eae
get correct context length
maxjeblick 7649ab9
fix qunatized key cache
maxjeblick 11a4c45
fix qunatized key cache
maxjeblick cfec9b8
fix test
maxjeblick 1bfe667
fix test
maxjeblick d46cc55
fix test
maxjeblick 524fe47
add more asserts
maxjeblick c07cc4d
fix test
maxjeblick 6ff4bc9
fix test
maxjeblick 960e05e
fix test
maxjeblick 5c5e1b9
Merge branch 'main' into max/fix_quanto_cache
maxjeblick 58bc8ae
fix merge conflicts
maxjeblick 16e8671
fix failing tests
maxjeblick d9887ea
import flash attn skip
maxjeblick f5d9d59
fix test
maxjeblick c620cb0
add integration tests
maxjeblick ca4f0ba
add integration tests
maxjeblick 702888a
add integration tests
maxjeblick 4369c02
add fixture
maxjeblick 22c9549
easen up test
maxjeblick 4b66477
undo vvariable extraction
maxjeblick 8006a75
undo newlines
maxjeblick 8eb3b3d
Merge branch 'main' into max/fix_quanto_cache
maxjeblick 519222b
address pr feedback
maxjeblick f75cb61
fix broken test
maxjeblick 261bcea
fix broken test
maxjeblick 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
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from kvpress.presses.base_press import BasePress | ||
|
|
||
|
|
||
|
|
||
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
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import datasets | ||
| import pytest | ||
| import torch | ||
| from transformers import DynamicCache, QuantizedCacheConfig, QuantoQuantizedCache | ||
| from transformers.utils import is_flash_attn_2_available, is_optimum_quanto_available | ||
|
|
||
| from kvpress import ( | ||
| ExpectedAttentionPress, | ||
| KnormPress, | ||
| SimLayerKVPress, | ||
| SnapKVPress, | ||
| StreamingLLMPress, | ||
| ThinKPress, | ||
| TOVAPress, | ||
| ) | ||
| from tests.fixtures import kv_press_llama3_1_flash_attn_pipeline # noqa: F401 | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def df_ruler(): | ||
| df = datasets.load_dataset("simonjegou/ruler", "4096")["test"].to_pandas() | ||
| df = df.loc[df["task"] == "niah_multikey_1"].reset_index(drop=True) | ||
| return df | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not torch.cuda.is_available(), reason="GPU is not available") | ||
| @pytest.mark.skipif(not is_flash_attn_2_available(), reason="flash_attn is not installed") | ||
| @pytest.mark.parametrize( | ||
| "cls", [KnormPress, ExpectedAttentionPress, StreamingLLMPress, SnapKVPress, TOVAPress, ThinKPress, SimLayerKVPress] | ||
| ) | ||
| @pytest.mark.parametrize("compression_ratio", [0.1, 0.2]) | ||
| @pytest.mark.parametrize("cache", ["dynamic", "quantized"]) | ||
| def test_ruler_is_correct(kv_press_llama3_1_flash_attn_pipeline, df_ruler, cls, compression_ratio, cache): # noqa: F811 | ||
| if cls == ThinKPress: | ||
| press = cls(key_channel_compression_ratio=compression_ratio, window_size=2) | ||
| elif cls == SimLayerKVPress: | ||
| press = cls(lazy_threshold=1 - compression_ratio) | ||
| else: | ||
| press = cls(compression_ratio=compression_ratio) | ||
| if cache == "dynamic": | ||
| cache = DynamicCache() | ||
| elif cache == "quantized" and is_optimum_quanto_available(): | ||
| config = QuantizedCacheConfig(nbits=4) | ||
| cache = QuantoQuantizedCache(config) | ||
| elif cache == "quantized" and not is_optimum_quanto_available(): | ||
| pytest.skip("Quanto is not installed") | ||
| else: | ||
| raise ValueError(f"Unknown cache type: {cache}") | ||
|
|
||
| idx = 0 | ||
| context = df_ruler.iloc[idx]["context"] | ||
| question = df_ruler.iloc[idx]["question"] | ||
| true_answer = df_ruler.iloc[idx]["answer"][0] | ||
|
|
||
| pred_answer = kv_press_llama3_1_flash_attn_pipeline(context, question=question, press=press, cache=cache)["answer"] | ||
| assert true_answer in pred_answer | ||
Empty file.
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.