Usage and Integration
Installation
Start with a target plugin for the hardware you want to analyze. It installs MLIA as a dependency. Add this converter in the same Python environment only if your workflow needs PyTorch conversion. A converter alone cannot provide target-specific analysis.
pip install mlia-converters-pytorch
Overview
This package registers four transformer names through the
mlia.plugin.transformer entry point:
nn_module_to_pt2, implemented byNNModuleToPt2ExporterPlugin.pt2_to_tosa, implemented byPT2ToTosaConverterPlugin.pt2_to_pte, implemented byPT2ToPteConverterPlugin.pte_to_delegate, implemented byPteToDelegateConverterPlugin.
Naming convention
This repo uses two names that matter in different places:
- Use
nn_module_to_pt2,pt2_to_tosa,pt2_to_pte, andpte_to_delegateas the transformer names exposed to MLIA and used in API or CLI-facing flows. - Use
mlia_pytorch_to_tosa_converterandmlia_pytorch_to_pte_converteras the implementation package names used in the codebase.
Operational model
This package adds conversion to an MLIA workflow with a target plugin. It does not provide a standalone analysis command. Once installed, MLIA can discover the transformers and route conversion requests through the shared transformer registry.
Typical workflow
The converters are usually part of a larger MLIA flow rather than something you invoke in isolation:
- MLIA receives a
torch.nn.Module,.pt2model, or ExecuTorch.pteartifact. - MLIA chooses the conversion route that matches the input and downstream backend.
- The converter produces a
.pt2,.tosa,.pte, or.vgfartifact. - A downstream backend consumes the converted artifact.
- MLIA returns target-specific analysis results.
Choosing the route
Use nn_module_to_pt2 when a Python API workflow starts from an in-memory
torch.nn.Module. The exporter requires example_inputs as a tuple so
torch.export can trace the module and write a model.pt2 artifact.
Use pt2_to_tosa when the downstream backend expects TOSA. That is also the
path can disable post-training quantization for workflows that need to try
direct lowering.
Use pt2_to_pte when the downstream backend expects an ExecuTorch .pte
artifact and supplies the required ExecuTorch target configuration. In practice,
that means flows where the next stage expects a delegated ExecuTorch program
rather than a .tosa artifact, and where the target configuration provides the
required target, mac, system_config, and memory_mode fields.
Use pte_to_delegate when the input is already an ExecuTorch .pte artifact
and the downstream backend needs the delegate payload stored inside it rather
than the full ExecuTorch program. The converter extracts a single delegate
payload for TOSABackend or VgfBackend and writes either a .tosa or .vgf
file.
Implementation layout
The .pt2 converter implementations share validation helpers for PyTorch
export input handling, but diverge after that:
- The TOSA path lowers the exported program into a TOSA artifact.
- The nn.Module export path writes a
.pt2artifact from a live PyTorch module and example inputs. - The PTE path lowers the exported program into an ExecuTorch program and
writes a
.ptefile. - The delegate path deserializes an existing
.ptefile and writes the TOSA or VGF delegate payload stored inside it. - The TOSA path can run with quantization enabled or disabled, depending on how the wider MLIA workflow calls it.
- The PTE path currently performs quantization as part of Ethos-U delegation.
Source layout
- See
mlia_pytorch_to_tosa_converter/conversion.pyfor TOSA conversion. - See
mlia_nn_module_to_pt2_exporter/exporter.pyfor in-memory PyTorch module export. - See
mlia_pytorch_to_pte_converter/conversion.pyfor PTE conversion. - See
mlia_pte_to_delegate_converter/conversion.pyfor PTE delegate payload extraction. - See the corresponding
converter_plugin.pymodules for MLIA plugin registration. - See
pytorch_export_converter.pyfor shared.pt2validation and loading helpers.
Cross-links
- See conversion_flow.md for a more pipeline-oriented view.
- See conversion_outputs.md for conversion success signals from this converter's perspective.
- See troubleshooting.md for the practical debugging sequence and common conversion failures.