Repository navigation
Add AfterglowPress and QueryAwareKVzipPlusPress - #310
Open
blindTissue wants to merge 1 commit into
Open
blindTissue wants to merge 1 commit into
blindTissue wants to merge 1 commit into
Conversation
Signed-off-by: Sungwon Kim <112958105+blindTissue@users.noreply.github.com>
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
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.
PR description
This PR adds Afterglow (paper), a training-free plug-in for the scoring step of query-aware presses. It follows up on #292 (QuerySpanPress), which was closed.
Query-aware scorers such as SnapKV give the highest scores to the first tokens of the span which the question asks about (a value, an identifier, a title). Eviction thus then retains many of the starting span cache but evicts most of the remaining span, leading to truncated or corrupted answer. Afterglow lets each token inherit the decayed scores of the tokens before it, separately for each layer and KV head:
The wrapped press then selects from
s'with the same budget.New presses:
AfterglowPress(press)(afterglow_press.py): wraps anyScorerPressand composes withAdaKVPressandCriticalAdaKVPress, which then allocate their budgets from the propagated scores.CriticalKVPresssets the scores it protects to the largest float, so Afterglow goes inside it:CriticalAdaKVPress(AfterglowPress(SnapKVPress())). Afterglow works in log space and raises an error for negative scores (e.g.KnormPress).QueryAwareKVzipPlusPress(query_aware_kvzip_plus_press.py): the best configuration of the paper. It inherits fromKVzipPressand replaces the reconstruction pass with the attention of the question (the lastwindow_sizetokens). The KVzip+ scores then go through Afterglow, with the inherited part scaled by a predictability gateu(t)^alpha,u(t) = 1 - p(x_t | x_<t)from the prefill's own final hidden states, so that predictable continuations inherit less. The budget allocation across layers and heads (compress_post), the||W_O v||normalization and the causal mask are KVzip's.PRESS_REGISTRYentries:snapkv_afterglow,adakv_snapkv_afterglow,critical_adakv_snapkv_afterglow,kvzip_plus_query_aware. All of them are meant for query-aware compression (query_aware=True).Results
Each cell is without -> with Afterglow, from paper's runs.
kvzip_plus_query_aware, (Afterglow + predictability gate), run with the PR's code throughevaluation/evaluate.py. Within 0.15pp of the paper at every ratio.Tests
tests/presses/test_afterglow_press.pychecksafterglow()against a naive double loop,AfterglowPressalone and insideAdaKVPress/CriticalAdaKVPress, and the error for negative scores.QueryAwareKVzipPlusPressis indefault_presses.Checklist
Before submitting a PR, please make sure:
Tests are working (
make test)Code is formatted correctly (
make style, on errors try fix withmake format)Copyright header is included
All commits are signed-off using
git commit -s(new press)
mypress_press.pyis in thepressesdirectory(new press)
MyPressis in__init__.py(new press)
README.mdis updated with a 1 liner about the new press in the Available presses section(new press) New press is in the
default_presseslist intests/default_presses.py(new press) A docstring is provided that follows the same structure as the existing ones