fix: apply QK norm in MultiheadAttention hook methods#85
Open
orrzohar wants to merge 1 commit into
Open
Conversation
q_norm and k_norm modules were instantiated from attention_qk_norm_layer config but never invoked in the forward pass. Apply them in process_q_before_logits_calc and process_k_before_logits_calc so that QK normalization actually affects attention logits when configured. Made-with: Cursor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
attention_qk_norm_layerconfig instantiatesself.q_normandself.k_norminMultiheadAttention.__init__, but neither is ever called in the forward pass. QK normalization is silently a no-op.Fix
Apply
self.q_norm/self.k_norminsideprocess_q_before_logits_calcandprocess_k_before_logits_calc, so Q and K are normalized before the logits matmul when configured.