Guide: Exporting Keras models to LiteRT with PyTorch backend#2373
Conversation
- Rewrite the guide to use the PyTorch backend as the recommended path - Document why TF backend is not recommended (flex ops, deprecated interpreter) - Show ai-edge-quantizer as the recommended quantization approach - Include ai_edge_litert.interpreter.Interpreter for inference - Add backend comparison table and troubleshooting section - Reference Gemma 3 270M as the practical LLM example
There was a problem hiding this comment.
Code Review
This pull request introduces a new guide on exporting Keras models to LiteRT using the PyTorch backend, adding the Python script, Jupyter Notebook, and Markdown versions of the guide, and registering it in the master guides list. The review feedback suggests removing redundant model.compile() calls since the model is only used for inference and export, and simplifying the Gemma 3 preprocessing code by passing a single string directly to the preprocessor instead of a training-like dictionary.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…zing, signature runner
- Add Android dependencies section (com.google.ai.edge.litert, tensorflow-lite, select-tf-ops) - Fix Gemma3 example to use empty responses for inference export - Reorganize: features before quantization (subclass models, multi-input, dict inputs, resizing, signature runner, custom input signature) - Add TensorFlow backend alternative section with Float16 example - Follow keras.io guide style: clear explanations before code, runnable examples
- Add master branch installation instructions for keras and keras-hub - Document dynamic shapes behavior and recommend runtime resizing - Clarify that InputSpec(None) becomes static at export time - Fix Gemma3 example to use generate_preprocess() for inference - Update Android dependency versions to latest (2.1.5, 2.16.1) - Add runtime input resizing to backend comparison table - Update best practices and troubleshooting sections
…ning, signature names
eee5846 to
d77844d
Compare
|
@laxmareddyp May you please review the PR, it is ready for it. |
| pip install -q git+https://github.com/keras-team/keras.git | ||
| pip install -q git+https://github.com/keras-team/keras-hub.git | ||
| pip install -q git+https://github.com/google-ai-edge/litert-torch.git |
There was a problem hiding this comment.
Now that keras and keras-hub were released, this should work and is much cleaner (and predictable):
pip install -qU keras
pip install -qU keras-hub
pip install -q litert-torch
There was a problem hiding this comment.
changed keras and keras-hub to latest,
kept litert-torch as installation from github, as our fix for input name mismatch is not in release.
edfaeba to
947b0c6
Compare
hertschuh
left a comment
There was a problem hiding this comment.
Thanks for adding this guide!
This PR adds a comprehensive guide for exporting Keras models to LiteRT using the PyTorch backend.
Key changes from the previous approach (TF backend)
ai_edge_litert.interpreter.Interpreter—tf.lite.Interpreteris deprecated and scheduled for deletion.optimizationsto the exporter, which can fail on the PyTorch backend for some models.Verified
Notes