Skip to main content
The recommended approach to convert a PyTorch model to LiteRT is a multi-step process: PyTorch → ONNX → TensorFlow (SavedModel) → LiteRT

Export the PyTorch model to ONNX

Use torch.onnx.export to convert the PyTorch model to ONNX format:
import torch

model.eval()
dummy_input = torch.randn(1, 3, 224, 224)
torch.onnx.export(
    model,
    dummy_input,
    "model.onnx",
    opset_version=13,
    input_names=["input"],
    output_names=["output"],
    do_constant_folding=True
)

Convert ONNX to LiteRT

Once the model has been exported to ONNX, follow the instructions in Export an ONNX model to LiteRT to complete the conversion to LiteRT format.