Skip to content
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

Add customized static cache implementation #4385

Closed
wants to merge 1 commit into from
Closed

Conversation

helunwencser
Copy link
Contributor

@helunwencser helunwencser commented Jul 24, 2024

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 StaticCache which is not only a Cache but also a torch.nn.Module. Most of its implementation is copied from transformers with the following modification:

Test Plan:
Make sure the following commands generate the exact same output but the later one, with kv cache enabled, is faster:

python3 -m examples.models.phi-3-mini.eager
python3 -m examples.models.phi-3-mini.eager -kv

Copy link

pytorch-bot bot commented Jul 24, 2024

🔗 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 Failures

As of commit e31ff36 with merge base 28cfabb (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 24, 2024
@helunwencser helunwencser changed the base branch from main to use_kv_cache July 24, 2024 00:24
@helunwencser helunwencser changed the base branch from use_kv_cache to main July 24, 2024 00:25
@helunwencser helunwencser changed the base branch from main to use_kv_cache July 24, 2024 00:30
@helunwencser helunwencser changed the base branch from use_kv_cache to main July 25, 2024 18:31
@helunwencser helunwencser force-pushed the static_cache branch 3 times, most recently from da1e974 to b13f8aa Compare July 25, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants