Skip to content

Conversation

@copybara-service
Copy link

Add EmbeddingGemma-300M example to AI Edge Torch.

This change introduces a reauthored implementation of the EmbeddingGemma-300M model. It includes scripts to convert the model to TFLite and verify its output against the original Hugging Face SentenceTransformer implementation.

TFLite conversion for EmbeddingGemma now supports quantization but is limited to fixed input shapes. Dynamic sequence length could not be implemented due to limitations in the underlying conversion tooling (ODML Torch). The model uses torch.arange for positional embeddings; when tracing with a dynamic sequence length, the converter fails in odml_torch/export.py because its i64-to-i32 rewrite logic for arange does not support symbolic shapes, raising an AttributeError.

As a workaround, dynamic shapes are disabled, and the input shape is fixed based on --prefill_seq_lens. Additionally, torch.clamp was replaced with denominator smoothing to avoid the unsupported tfl.maximum op.

This change introduces a reauthored implementation of the EmbeddingGemma-300M model. It includes scripts to convert the model to TFLite and verify its output against the original Hugging Face SentenceTransformer implementation.

TFLite conversion for EmbeddingGemma now supports quantization but is limited to fixed input shapes. Dynamic sequence length could not be implemented due to limitations in the underlying conversion tooling (ODML Torch). The model uses torch.arange for positional embeddings; when tracing with a dynamic sequence length, the converter fails in odml_torch/export.py because its i64-to-i32 rewrite logic for arange does not support symbolic shapes, raising an AttributeError.

As a workaround, dynamic shapes are disabled, and the input shape is fixed based on --prefill_seq_lens. Additionally, torch.clamp was replaced with denominator smoothing to avoid the unsupported tfl.maximum op.

PiperOrigin-RevId: 816066147
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