-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
[Bugfix] Fix interns1-vit qk norm code path #27480
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
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
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.
Code Review
This pull request correctly fixes a critical bug in the InternSdpaAttention's forward pass for interns1-vit models with QK normalization enabled. The previous implementation would crash due to incorrectly attempting to unpack a 3D tensor into four variables and also used flatten incorrectly. The fix applies the QK normalization directly to the query and key tensors, which is the correct approach. The removal of the unused B, N, C variables is also a good cleanup.
I've added one comment pointing out a related latent bug when num_dummy_heads > 0, which will also cause a crash. This seems to stem from incorrectly adapted logic for tensor parallelism dummy heads. While the current PR fixes the most obvious issue, addressing the related bug would make the implementation more robust.
| q = self.q_norm(q) | ||
| k = self.k_norm(k) |
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.
While this change correctly fixes the immediate crash, there's a latent critical bug when num_dummy_heads > 0 which will cause crashes in this block and later on.
-
q_normandk_norminitialization: In__init__,self.q_normis initialized asRMSNorm(hidden_size=self.dummy_dim, ..., var_hidden_size=self.embed_dim). Ifnum_dummy_heads > 0,self.dummy_dim > self.embed_dim. The inputqhas a last dimension ofself.embed_dim.RMSNormexpects the input's last dimension to match itshidden_size(self.dummy_dim), soself.q_norm(q)will raise aValueError. The same applies tok_norm. -
projection_layerinput shape: The output ofself.attn(q, k, v)will have a shape of(..., self.embed_dim). However,self.projection_layeris initialized asnn.Linear(self.dummy_dim, self.embed_dim). Ifnum_dummy_heads > 0, the call toself.projection_layeron a subsequent line will fail due to a shape mismatch.
The MultiHeadAttention implementation used here doesn't seem to account for dummy heads. The entire dummy_dim logic within InternSdpaAttention might need to be re-evaluated to either be correctly implemented or removed if it's not applicable for this ViT attention layer. A potential fix for the normalization part would be to initialize RMSNorm with self.embed_dim.
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn> Signed-off-by: 0xrushi <6279035+0xrushi@users.noreply.github.com>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn> Signed-off-by: 0xrushi <6279035+0xrushi@users.noreply.github.com>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Purpose
Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.