Skip to content

fix: Scale QK in vision/attention #1154

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

changlan
Copy link
Contributor

@changlan changlan commented May 4, 2025

WindowAttention layer in vision/attention.py overrides the forward calls directly so we need to scale the QK before computing logits.

@changlan changlan requested review from ruomingp, markblee and a team as code owners May 4, 2025 04:22
@changlan changlan enabled auto-merge May 4, 2025 05:03
Copy link
Contributor

@ruomingp ruomingp left a comment

Choose a reason for hiding this comment

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

Thanks! Please also see my comments on the internal PR.

Comment on lines 218 to 227
# Scale query and key.
key_positions = jnp.arange(k_proj.shape[1])[None, :]
q_proj, k_proj = self._scale_qk(
q_proj=q_proj,
k_proj=k_proj,
query_positions=query_positions,
key_positions=key_positions,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a unittest that can be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - I added a unit test.

@changlan changlan requested a review from ruomingp May 5, 2025 00:14
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.

2 participants