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.
Description
Commit 1:
past_kv_cache
.past_kv_cache
.past_kv_cache
.past_kv_cache
.Commit 2:
Commit 3:
past_left_attention_mask
intoHookedTransformerKeyValueCache
so that it doesn't need to managed manually. Remove fromHookedTransformer.forward()
.Motivation for allowing multiple tokens to run with key value cache
In ACDC we run the same prompt many times. Patching only affects token positions after the point where the clean and corrupt prompts differ. We want to run the first part of the prompt that is identical between clean and corrupt, freeze the cache, then pass in only the tokens after the point of divergence for our patched runs.
Breaking change
Commit 3 removes
past_left_attention_mask
fromHookedTransformer.forward()
because theleft_attention_mask
of previous inputs is stored automatically byHookedTransformerKeyValueCache
. I think this won't break many people's code as this argument was only added 2 weeks ago in #344. And the fix should be quite trivial as it only requires deleting this input. (See changes to tests in commit 3 for an example).Overall I think the benefits are worth the cost as this makes caching easier to do and generally reduces complexity. I can't think of any case where someone would want to pass in a
past_left_attention_mask
that doesn't matchpast_kv_cache
.Type of change
Checklist: