Fix incorrect error message and inconsistent ndim check#1377
Open
Mr-Neutr0n wants to merge 1 commit intofacebookresearch:mainfrom
Open
Fix incorrect error message and inconsistent ndim check#1377Mr-Neutr0n wants to merge 1 commit intofacebookresearch:mainfrom
Mr-Neutr0n wants to merge 1 commit intofacebookresearch:mainfrom
Conversation
…code Fix two bugs in attention input handling: 1. _rand_seqlens_padded_k in attn_bias_utils.py: The error message said "need more queries than keys" when the condition `q_len > kv_len` is triggered, but the intent (as documented in the comments) is that there must be more keys than queries. Fixed the message to say "need more keys than queries (kv_len must be >= q_len)". 2. get_qkv_in_bmghk in ops/fmha/common.py: The first two branches check `self.query.ndim` (for ndim==5 and ndim==4), but the third branch inconsistently checked `self.value.ndim == 3` instead of `self.query.ndim == 3`. While validate_inputs() ensures all tensors share the same ndim, this inconsistency could cause silent wrong behavior if get_qkv_in_bmghk is called without prior validation and the tensors have mismatched dimensions.
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.
Summary
Fix misleading error message in
_rand_seqlens_padded_k(attn_bias_utils.py): Whenq_len > kv_len, the function raisesValueError("need more queries than keys"), but the comments and logic clearly indicate the constraint is that there must be more keys than queries (bottom-right causal mask). Fixed the message to"need more keys than queries (kv_len must be >= q_len)".Fix inconsistent
ndimcheck inInputs.get_qkv_in_bmghk(ops/fmha/common.py): The first two branches checkself.query.ndim(for 5D and 4D), but the third branch checksself.value.ndim == 3instead ofself.query.ndim == 3. Whilevalidate_inputs()ensures all tensors share the same ndim, this inconsistency could cause silent wrong behavior ifget_qkv_in_bmghkis called without prior validation and the tensors have mismatched dimensions.Test plan
get_qkv_in_bmghk