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

Fix: Discard KV cache for last token before reusing prompt cache for prompt + suffix #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: Discard KV cache for last token before reusing prompt cache with…
… suffix added to prompt
  • Loading branch information
sannat17 committed Oct 21, 2024
commit 6606949bb0b42d534bec129897787aae7990b19a
2 changes: 2 additions & 0 deletions performance_optimization/prompt_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
inputs = tokenizer(INITIAL_PROMPT, return_tensors="pt").to("cuda")
with torch.no_grad():
prompt_cache = model(**inputs, past_key_values = prompt_cache).past_key_values
prompt_cache.key_cache = [x[:, :, :-1] for x in prompt_cache.key_cache]
prompt_cache.value_cache = [x[:, :, :-1] for x in prompt_cache.value_cache]


prompt = "Why are french people obsessed with french?"
Expand Down