Fix incorrect batch-dim shape annotations on vmapped _get_new_text_tokens_inner - #746
Open
PratikDhanave wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…kens_inner
`_get_new_text_tokens_inner` is invoked under `jax.vmap(..., in_axes=(0, 0,
None, None))`, so it receives single rows of shape [L], not [B, L]. Its
parameters were annotated `Bool['B L']` / `Int['B L']`, contradicting:
- its own docstring ("without batch dimension") and `-> Int['L']` return,
- the vmap that strips axis 0, and
- the sibling `_get_new_mm_tokens_inner`, which correctly uses `Bool['L']`.
The body confirms rank-1: it allocates `jnp.zeros((length_with_mm,))` and
indexes it 1-D. Correct the annotations to `['L']` (matching the sibling's
`unknown-name` ignore). Annotation-only; no runtime behavior change.
PratikDhanave
force-pushed
the
fix/token-utils-inner-shape-annotations
branch
from
July 25, 2026 04:46
d2739c8 to
b925d5a
Compare
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.
What
In
gemma/gm/vision/_token_utils.py,_get_new_text_tokens_inneris called inside avmap:in_axes=(0, 0, None, None)strips the leading axis, so the callee operates on single rows of shape[L]. But its parameters were annotated as batched:This contradicts three things:
_get_new_text_tokens_positionswithout batch dimension" — and its-> Int['L']return type;vmapin_axes that remove axis 0;_get_new_mm_tokens_inner, which correctly annotates its post-vmap arg asBool['L'].The body confirms rank-1: it allocates
jnp.zeros((length_with_mm,))and indexes it 1-D.Change
Correct the two annotations to
['L'], matching the sibling's# pyrefly: ignore[not-a-type, unknown-name]style. The function is not@typechecked, so this is an annotation/static-analysis fix with no runtime behavior change.