-
Notifications
You must be signed in to change notification settings - Fork 779
Custom op to update cache for torch.cond #16366
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
Conversation
|
Stack from ghstack (oldest at bottom): |
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16366
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 26 Pending, 1 Unrelated FailureAs of commit a8b20f5 with merge base 1ce615e ( NEW FAILURES - The following jobs have failed:
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| # Copy value into the slice | ||
| L[aten.copy_.default](cache_slice, value) | ||
|
|
||
| return cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is returning the original cache whereas eager mode returns a copy. Do you want this discrepancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. eager has to return a copy to make exported_program runnable. For inductor lowering we need it to be as efficient as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay then document the discrepancy
torch.cond doesn't take aliasing or mutations. Adding 2 ops for supporting conditionally updating kv cache:
executorch::alias: takes 2 tensors and return the same 2 tensors.executorch::update_cross_attn_cache: takes a tensorcacheand a tensorvalue, in place copyvalueintocache.With these 2 ops, we can rewrite the model definition from:
Into: