Add customized static cache implementation#4385
Closed
helunwencser wants to merge 1 commit intomainfrom
Closed
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/4385
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e31ff36 with merge base 28cfabb ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
fc0223d to
c29f929
Compare
a2af0f5 to
8da2fab
Compare
9e9adec to
1bfb020
Compare
8da2fab to
7c52b85
Compare
da1e974 to
b13f8aa
Compare
b13f8aa to
e31ff36
Compare
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.
This PR is based on the prototype done in huggingface/transformers#31706. We want to export HF models to ExecuTorch. However, we cannot do that right now due to its Cache is not a
torch.nn.Module.This PR tries to solve this problem by implementing a customized
StaticCachewhich is not only aCachebut also atorch.nn.Module. Most of its implementation is copied from transformers with the following modification:torch.nn.Moduleregister_buffercall, copied from [Demo][ExecuTorch] Lower and run native Gemma e2e in ExecuTorch huggingface/transformers#31706StaticCacheimplementation: 1.get_seq_lengthshould return a number instead of tensor, 2.updateshould only returned filled cache slots instead of the whole static cache.Test Plan:
Make sure the following commands generate the exact same output but the later one, with kv cache enabled, is faster: