Repository navigation
Trim trailing zero-padded soft tokens in Gemma 4 ViT. - #1100
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
When an image's aspect ratio yields fewer than `max_soft_tokens` pooled tokens (for example, 256 out of 280 for a square image), `PrefillVitGemma4` left the unused trailing rows zero-filled and returned all `max_soft_tokens` rows. Because callers insert `image_tokens.Rows()` placeholders into the prompt, those zero rows were passed into the language model instead of being stripped as in the JAX and HuggingFace Gemma 4 implementations—polluting attention and wasting prefill/KV-cache work (and distorting mean-pooled embeddings). Resize `image_tokens` to the actual pooled token count via `OverrideRows` and add a unit test covering partial-budget aspect ratios and buffer reuse. PiperOrigin-RevId: 1031133282
|
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. |
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.
Trim trailing zero-padded soft tokens in Gemma 4 ViT.
When an image's aspect ratio yields fewer than
max_soft_tokenspooled tokens(for example, 256 out of 280 for a square image),
PrefillVitGemma4left theunused trailing rows zero-filled and returned all
max_soft_tokensrows.Because callers insert
image_tokens.Rows()placeholders into the prompt,those zero rows were passed into the language model instead of being stripped
as in the JAX and HuggingFace Gemma 4 implementations—polluting attention and
wasting prefill/KV-cache work (and distorting mean-pooled embeddings).
Resize
image_tokensto the actual pooled token count viaOverrideRowsandadd a unit test covering partial-budget aspect ratios and buffer reuse.