Skip to content

[Relax][Frontend][TFLite] Add EMBEDDING_LOOKUP_SPARSE converter#19652

Open
LudovicoYIN wants to merge 3 commits into
apache:mainfrom
LudovicoYIN:lukeyin/tflite-embedding-lookup-sparse
Open

[Relax][Frontend][TFLite] Add EMBEDDING_LOOKUP_SPARSE converter#19652
LudovicoYIN wants to merge 3 commits into
apache:mainfrom
LudovicoYIN:lukeyin/tflite-embedding-lookup-sparse

Conversation

@LudovicoYIN
Copy link
Copy Markdown
Contributor

Summary

Add Relax TFLite frontend support for EMBEDDING_LOOKUP_SPARSE.

This PR adds a converter for EMBEDDING_LOOKUP_SPARSE in the Relax
TFLite frontend. The implementation supports the SUM, MEAN, and
SQRTN combiners and handles higher-rank sparse indices. The sparse
aggregation is lowered through scatter_nd to match TFLite operator
semantics for the supported cases.

The PR also adds handcrafted TFLite frontend tests covering:

  • SUM
  • MEAN
  • SQRTN
  • a 3D indices case

Testing

Ran tests/python/relax/test_frontend_tflite.py -k 'embedding_lookup_sparse'.

Part of #19519

Add Relax TFLite frontend support for EMBEDDING_LOOKUP_SPARSE.

This change implements the converter for the SUM, MEAN, and SQRTN
combiners and supports higher-rank sparse indices. The converter lowers
the sparse aggregation through scatter_nd to match TFLite operator
semantics for the supported cases.

The patch also adds handcrafted TFLite frontend tests covering the SUM,
MEAN, and SQRTN combiners, along with a 3D indices case.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for the EMBEDDING_LOOKUP_SPARSE operator in the TVM Relax TFLite frontend, supporting SUM, MEAN, and SQRTN combiner types. It also adds comprehensive unit tests to verify the correctness of these combiners. Feedback on the implementation suggests optimizing the calculation of the safe denominator by using a scalar constant instead of creating a full-shaped constant tensor, leveraging the broadcasting capabilities of relax.op.maximum to improve efficiency and reduce compiled model size.

Comment thread python/tvm/relax/frontend/tflite/tflite_frontend.py Outdated
LudovicoYIN and others added 2 commits June 1, 2026 15:15
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Use a scalar float32 constant when clamping the EMBEDDING_LOOKUP_SPARSE denominator.

This keeps the Relax expression smaller by relying on broadcasting in
maximum instead of materializing a full-shaped constant tensor.
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