litert-tunner
Fine-tune fully-quantized INT8 LiteRT (TFLite) models after export — without retraining from scratch.
What is this?
litert-tunner parses an exported INT8 .tflite model, reconstructs it as a Keras 3 model with simulated quantization, lets you fine-tune parameters (biases, scales, weights), and writes them back into the flatbuffer. Graph topology stays intact.
Note: Even though this library simulates the quantization process during fine-tuning, in some cases the resulting INT8 model may still perform worse than a full-precision float32 model.
Installation
From source (recommended for development)
# Clone the repository
git clone https://github.com/kmkolasinski/litert-tunner.git
cd litert-tunner
# Create a virtual environment and install uv
make venv
make init
# Install the project in editable mode with dev dependencies
make install
As a dependency (pip)
pip install litert-tunner
(Core dependencies: keras>=3.0, numpy, tflite>=2.18.0, flatbuffers. tensorflow and ai-edge-litert are only needed for dev/tests).
Quickstart
For a complete, runnable end-to-end example, see the Example Notebook.
import litert_tunner
# 1. Load an INT8 LiteRT model → trainable Keras replica
model = litert_tunner.load_model("model_int8.tflite")
# 2. Inference — should match LiteRT Interpreter output
predictions = model.predict(inputs)
# 3. Prepare for fine-tuning (freeze everything except biases & scales)
litert_tunner.prepare_for_finetuning(model, trainable_pattern=".*bias")
# 4. Fine-tune with any Keras optimizer / loss
model.compile(optimizer="adam", loss="mse")
model.fit(x_train, y_train, epochs=5)
# 5. Export — writes updated parameters back into the flatbuffer
litert_tunner.save_model(model, "model_int8_finetuned.tflite")
Distillation Fine-Tuning (Recommended)
import litert_tunner
# 1. Load an INT8 LiteRT model → trainable Keras replica
student_model = litert_tunner.load_model("model_int8.tflite")
teacher_model = litert_tunner.load_model("model_float32.tflite")
# 2. Freeze everything except biases
litert_tunner.prepare_for_finetuning(student_model, trainable_pattern=".*bias")
# 3. Fine-tune using Trainer (handles distillation & weight drift)
trainer = litert_tunner.Trainer(
student_model=student_model,
teacher_model=teacher_model, # Original float32 model
)
trainer.compile(optimizer="adam", loss="mse")
trainer.fit(train_ds, validation_data=val_ds, epochs=5)
# 4. Save updated parameters to flatbuffer
litert_tunner.save_model(student_model, "model_int8_finetuned.tflite")
Supported Operations
- Linear:
FULLY_CONNECTED,CONV_2D,DEPTHWISE_CONV_2D,TRANSPOSE_CONV - Arithmetic:
ADD,SUB,MUL,DIV,SQUARED_DIFFERENCE,NEG - Activation:
RELU,GELU,LOGISTIC,SOFTMAX - Pooling:
AVERAGE_POOL_2D,MAX_POOL_2D,MEAN - Reshape/Resize:
RESHAPE,TRANSPOSE,PACK,STRIDED_SLICE,RESIZE_NEAREST_NEIGHBOR,SHAPE,EXPAND_DIMS,PAD,TILE - Other:
CONCATENATION,RSQRT,QUANTIZE,DEQUANTIZE
Fused activations (RELU, RELU6, RELU_N1_TO_1) are supported.
License
MIT — Copyright © 2026 Krzysztof Kolasinski
Metadata
Release files for litert-tunner 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litert_tunner-0.3.0.tar.gz | 61.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| litert_tunner-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 152.9 kB
Release files / litert_tunner-0.3.0.tar.gz
| Download URL | litert_tunner-0.3.0.tar.gz |
|---|---|
| Size | 61.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d40a602a378ef219c6f259b9ed1f3c551fee3279eee548802877f62878c4f53
|
|
BLAKE2b-256 checksum How to use checksums |
8efd9027b5ea3641178a741816c8920c626810c93c01617f96c6933b4dc705fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / litert_tunner-0.3.0-py3-none-any.whl
| Download URL | litert_tunner-0.3.0-py3-none-any.whl |
|---|---|
| Size | 91.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd24d866308ec9ba285c425cd29069e3311cf6c7249c722db7dfbc11bdca07ad
|
|
BLAKE2b-256 checksum How to use checksums |
f70559903e13c28be1703ba1015a706917a46ed8318efe9b12c16a89613bc95b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|