Skip to content

Avoid converting k and v to q dtype #2201

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

Closed
wants to merge 1 commit into from

Conversation

larryliu0820
Copy link
Contributor

Summary:
We don't want to hard code k and v into q's dtype, instead we should make sure they are always the same before feeding into sdpa.

The problem was due to dtype mismatch between the kv cache used for tracing and the actual weights. This happens in the fp16 flow. After we convert the whole model to fp16, we still use fp32 kv cache tensors for tracing and that's causes the dtype mismatch issue.

This diff changes the logic to be using the same dtype as the weights, for kv cache during tracing

Differential Revision: D54426672

Summary:
We don't want to hard code k and v into q's dtype, instead we should make sure they are always the same before feeding into sdpa.

The problem was due to dtype mismatch between the kv cache used for tracing and the actual weights. This happens in the fp16 flow. After we convert the whole model to fp16, we still use fp32 kv cache tensors for tracing and that's causes the dtype mismatch issue.

This diff changes the logic to be using the same dtype as the weights, for kv cache during tracing

Differential Revision: D54426672
Copy link

pytorch-bot bot commented Mar 1, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/2201

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit a768904 with merge base c3c667e (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 Mar 1, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D54426672

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 5a18cc6.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants