Repository navigation
Issue 313 Fix: ChunkedEmbedding for Gemma-3n-E4B - #383
Merged
Merged
Conversation
tjia1818
approved these changes
Oct 27, 2026
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.
Type of Change
Motivation and Context
This PR fixes the issue found in #313. The per-layer embedding table for Gemma-3n-E4B is 262,144 x 8,960 parameters. Currently, this is stored in one table. The GPU gather can count up to 2^31 parameters, so lookups for token IDs greater than 239,675 (with 8,960 elements per row) silently fail and return rows of zeroes.
This fix checks the table size and creates a ChunkedEmbedding (splits the table in half so each row holds only 4,480 columns) if the number of elements exceeds 2^31. Then, a token lookup is done on both tables and the row is put back together.
This leads to bit-identical results as before (besides fixing the issue), and the extra operation of split-table lookup/concat is negligible.
Changes
ChunkedEmbeddingtableMAX_GATHER_CONSTANT_ELEMENTSTesting
The issue contained a repro script. I was able to reproduce the error mode with the existing code, and verified that this fix passes that script now. Essentially, we now properly lookup the table instead of silently returning rows of zeroes.
Follow Up
This may be fixed downstream in a future OS release. At that point, this fix can be removed.