Skip to content

Fix _maybe_unbatch return annotation (Float -> Array) in t5gemma - #762

Open
PratikDhanave wants to merge 1 commit into
google-deepmind:mainfrom
PratikDhanaveFork:fix/t5gemma-maybe-unbatch-return-annotation
Open

Fix _maybe_unbatch return annotation (Float -> Array) in t5gemma#762
PratikDhanave wants to merge 1 commit into
google-deepmind:mainfrom
PratikDhanaveFork:fix/t5gemma-maybe-unbatch-return-annotation

Conversation

@PratikDhanave

Copy link
Copy Markdown

In gemma/research/t5gemma/sampling.py, _maybe_unbatch is annotated:

def _maybe_unbatch(self, x: Array['B *d']) -> Float['*d']:

The body just unbatches and returns x unchanged (dtype-preserving), and its only caller is the tokens property, declared Int['B L'] | Int['L'] and passing the integer predicted_tokens buffer. So the return is never Float — it's whatever integer array is passed in. Change the return annotation to mirror the generic input type Array['*d'], which is correct for a dtype-preserving passthrough. Annotation only; no behavior change.

_maybe_unbatch is a dtype-preserving passthrough (unbatch) over an
Array['B *d'] input, and its only caller (the `tokens` property) declares
Int and passes the integer predicted_tokens buffer. Annotating the return
as Float['*d'] is a copy-paste error; mirror the generic input as Array['*d'].
@PratikDhanave
PratikDhanave force-pushed the fix/t5gemma-maybe-unbatch-return-annotation branch from 97694e0 to 22afad1 Compare July 25, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant