fix: use integer division (//) in GQA reshape operations#643
Open
tomohiro86 wants to merge 1 commit intogoogle-deepmind:mainfrom
Open
fix: use integer division (//) in GQA reshape operations#643tomohiro86 wants to merge 1 commit intogoogle-deepmind:mainfrom
tomohiro86 wants to merge 1 commit intogoogle-deepmind:mainfrom
Conversation
…eshape Replaces `int(kg / self.num_kv_heads)` with `kg // self.num_kv_heads` in all GQA reshape operations across 4 modules. Using float division with int() silently truncates when kg is not evenly divisible by num_kv_heads, producing an incorrect tensor shape with no error. Fixes google-deepmind#641.
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
Fixes #641.
In GQA (Grouped Query Attention) reshape operations,
int(kg / self.num_kv_heads)was using float division (/) instead of integer division (//). Whenkgis not evenly divisible bynum_kv_heads, Python silently truncates the result viaint(), producing an incorrect tensor shape with no error.int(kg / self.num_kv_heads)→kg // self.num_kv_headsin all 8 occurrences across 4 filesChanged files
gemma/gm/nn/_modules.pygemma/gm/nn/gemma3n/_modules.pygemma/gm/nn/gemma4/_modules.pygemma/research/t5gemma/modules.pyTest plan
num_query_headsis a multiple ofnum_kv_heads)//andint(/)produce the same result in that caseValueErrorfrom JAX/NumPy instead of silently truncating🤖 Generated with Claude Code