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

Replace repeat kv with proper GQA handling. #171

Merged
merged 5 commits into from
Aug 20, 2024
Merged

Replace repeat kv with proper GQA handling. #171

merged 5 commits into from
Aug 20, 2024

Conversation

wang2yn84
Copy link
Collaborator

Repeat kv in the original llama model will copy the data in some cases. Replace it with reshaping the number of heads dimension in the query to the number of tokens dimension (-2).

Copy link
Collaborator

@FanhaiLu1 FanhaiLu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart change! So the q * k^t = [hkv, rep * seq_len, seq_len] and q * k *v = [hkv, rep * seq_len, d], you reshape the output to: [h, seq_len, d] in the end.

@lsy323
Copy link
Collaborator

lsy323 commented Aug 20, 2024

LGTM! Thank you for the change. Seems linter needs to be fixed

@wang2yn84
Copy link
Collaborator Author

Smart change! So the q * k^t = [hkv, rep * seq_len, seq_len] and q * k *v = [hkv, rep * seq_len, d], you reshape the output to: [h, seq_len, d] in the end.

Correct. The reshape doesn't affect the result.

@wang2yn84
Copy link
Collaborator Author

LGTM! Thank you for the change. Seems linter needs to be fixed
Yup, fixed!

@wang2yn84 wang2yn84 merged commit 7092cc5 into main Aug 20, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants