Skip to content

Add final L2 normalization option and update README for Embedding Gemma-300M#931

Open
kamalkraj wants to merge 1 commit intogoogle-ai-edge:mainfrom
kamalkraj:embedding_gemma
Open

Add final L2 normalization option and update README for Embedding Gemma-300M#931
kamalkraj wants to merge 1 commit intogoogle-ai-edge:mainfrom
kamalkraj:embedding_gemma

Conversation

@kamalkraj
Copy link

Introduce an option for final L2 normalization in the Embedding Gemma-300M model. Update the README to reflect this new feature and provide clearer instructions for model conversion and verification. Adjust formatting in relevant files for consistency.

This commit introduces an optional final_l2_norm parameter to the EmbeddingGemma model, allowing users to enable or disable the final L2 normalization step. This enhancement is particularly useful for advanced use cases such as Matryoshka embeddings.

Changes:
- Model Update: Modified EmbeddingGemma in embedding_gemma.py to accept a final_l2_norm argument in __init__ and build_model. The forward method now conditionally applies L2 normalization.
- Conversion Script: Updated convert_to_tflite.py to include a --final_l2_norm flag (defaulting to True), passing it to the model builder.
- Verification: Updated verify.py and verify_util.py to support the final_l2_norm flag, ensuring the verification process matches the model configuration.
- Documentation: Updated README.md to document the new flag, mention Matryoshka embeddings, and include litert-torch in the requirements.

The default behavior remains unchanged (final_l2_norm=True), ensuring backward compatibility.
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