Transformers documentation
LiteRT
Get started
Base classes
Models
Preprocessors
Inference
Pipeline API
Generate API
Optimization
Chat with models
Serving
Training
Quantization
Ecosystem integrations
Resources
API
You are viewing main version, which requires installation from source. If you'd like
regular pip install, checkout the latest stable version (v5.17.0).
LiteRT
LiteRT (formerly TensorFlow Lite) is Google’s runtime for on-device inference. The model format is .tflite and language models ship as one .litertlm file for the LiteRT-LM runtime.
Export a Transformers model with litert-torch. It lowers the torch.export graph to LiteRT directly, and not through ONNX or a TensorFlow SavedModel.
pip install litert-torch
CLI (LLM)
Python (any model)
export_hf loads a language model from the Hub, quantizes the weights to int8 by default, and writes model.litertlm.
litert-torch export_hf \
--model="HuggingFaceTB/SmolLM2-135M-Instruct" \
--output_dir="./smollm2_litertlm"Transformers integration
- from_pretrained() loads the model weights in safetensors format.
- litert-torch runs torch.export and lowers the graph to LiteRT operators.
export_hfadds the KV cache, prefill and decode signatures, and int8 quantization. - AutoTokenizer loads the tokenizer.
export_hfpacks it and the chat template into the.litertlmfile. - At runtime,
.tfliteruns on LiteRT and.litertlmon LiteRT-LM, from Kotlin, Swift, C++, or Python (ai-edge-litertandlitert-lm-api). The oldertflite-runtimewheels stop at Python 3.11.
Transformers v4 documented
optimum-cli export tflite, which converted through TensorFlow. It was removed with TensorFlow support in v5 (#40760) and is not part of Optimum 2.x.
Resources
- LiteRT and LiteRT-LM docs
- Convert PyTorch models and GenAI models guides