Metadata-Version: 2.5
Name: mlia-converters-pytorch
Version: 0.1.1
Summary: ML Inference Advisor PyTorch Converter Plugin
Project-URL: Homepage, https://github.com/arm/mlia-converters-pytorch.git
Author-email: Arm Ltd <mlia@arm.com>
License-Expression: Apache-2.0
License-File: LICENSES/Apache-2.0.txt
Keywords: arm,ml,pytorch,tosa
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: ethos-u-vela==5.2.0
Requires-Dist: executorch==1.4.1
Requires-Dist: ml-dtypes==0.5.1
Requires-Dist: mlia==0.12.2
Requires-Dist: torch==2.13.0
Requires-Dist: torchao==0.18.0
Requires-Dist: tosa-tools==2026.2.1
Description-Content-Type: text/markdown

<!---
SPDX-FileCopyrightText: Copyright 2026, Arm Limited and/or its affiliates.
SPDX-License-Identifier: Apache-2.0
--->

# MLIA PyTorch Converter Plugin

This repository contains the MLIA converter plugins that translate PyTorch-based
models into artifacts consumed by downstream MLIA backends and target flows.

The package is distributed as `mlia-converters-pytorch`. When installed, it
registers the transformer names `nn_module_to_pt2`, `pt2_to_tosa`,
`pt2_to_pte`, and `pte_to_delegate` with MLIA through the plugin entry-point
system.

## Table of Contents

- [Overview](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#overview)
- [Repository contents](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#repository-contents)
- [Installation](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#installation)
- [How MLIA uses this plugin](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#how-mlia-uses-this-plugin)
- [Reporting bugs](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#reporting-bugs)
- [Development (uv)](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#development-uv)
- [Documentation](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#documentation)
- [Releases](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#releases)
- [License](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#license)
- [Trademarks and copyrights](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/README.md#trademarks-and-copyrights)

## Overview

This plugin package provides the conversion bridge between PyTorch export flows
and downstream MLIA backends. Today that means four main routes:

- `torch.nn.Module` to `.pt2` for Python API flows that start from an in-memory
  PyTorch module.
- `.pt2` to TOSA for flows that consume TOSA artifacts.
- `.pt2` to PTE for flows that consume ExecuTorch `.pte` artifacts.
- `.pte` to delegate payload for flows that extract the TOSA or VGF backend
  artifact stored inside the `.pte` file.

The implementation packages live under:

- `src/mlia/backend/mlia_nn_module_to_pt2_exporter/`
- `src/mlia/backend/mlia_pytorch_to_tosa_converter/`
- `src/mlia/backend/mlia_pytorch_to_pte_converter/`
- `src/mlia/backend/mlia_pte_to_delegate_converter/`

Together they include conversion logic, converter registration, and backend
installation metadata used by MLIA.

## Repository contents

- `src/mlia/backend/mlia_pytorch_to_tosa_converter/`: TOSA conversion package
  and plugin registration.
- `src/mlia/backend/mlia_nn_module_to_pt2_exporter/`: in-memory
  `torch.nn.Module` export package and plugin registration.
- `src/mlia/backend/mlia_pytorch_to_pte_converter/`: PTE conversion package and
  plugin registration.
- `src/mlia/backend/mlia_pte_to_delegate_converter/`: PTE delegate payload
  extraction package and plugin registration.
- `tests/`: unit tests for converter registration and conversion behaviour.
- `pre_commit_hooks/`: local repository hooks shared with CI quality checks.
- `pyproject.toml`: package dependencies and build configuration.

## Installation

Install the package into an environment that already contains `mlia`:

```bash
pip install mlia-converters-pytorch
```

For source-based development with `uv`:

```bash
uv sync --group dev
```

The project supports the Python versions declared in `pyproject.toml` and
installs the PyTorch-side dependencies listed there, including `torch`,
`executorch`, and `torchao`.

## How MLIA uses this plugin

MLIA discovers this repository through the `mlia.plugin.transformer` entry
point. When installed, the package registers four transformer names:

- `nn_module_to_pt2`
- `pt2_to_tosa`
- `pt2_to_pte`
- `pte_to_delegate`

The package and transformers use different names:

- `nn_module_to_pt2`, `pt2_to_tosa`, `pt2_to_pte`, and `pte_to_delegate` are the
  transformer names used in MLIA configuration and API or CLI flows.
- `mlia_pytorch_to_tosa_converter` and `mlia_pytorch_to_pte_converter` are the
  implementation package names used in the codebase.

That means downstream MLIA components can:

- Discover the transformers without hard-coded import paths.
- Request PyTorch module export, PyTorch-to-TOSA, PyTorch-to-PTE, or
  PTE-to-delegate transformations through the shared transformer registry.
- Treat the transformers as a separately versioned plugin package.

For more implementation detail, see [docs/README.md](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/README.md).

## Reporting bugs

Report bugs by creating GitHub issues. Use the
[`arm/mlia` issue tracker](https://github.com/arm/mlia/issues) by default.

Only open an issue in
[`arm/mlia-converters-pytorch`](https://github.com/arm/mlia-converters-pytorch/issues)
when the bug is clearly and specifically in this PyTorch converter plugin.

## Development (uv)

This repository uses `uv` for environment management and test execution. Ensure
the Python version in `.python-version` is available, then install dependencies:

```bash
uv sync --group dev
```

Run unit tests (uses dependencies installed from the package index, including `mlia`):

```bash
uv run pytest --no-success-flaky-report tests/
```

Run a quick test subset:

```bash
uv run pytest --no-success-flaky-report -m "not slow" tests/
```

Lint checks:

```bash
uv run pre-commit run --all-files
```

Build a wheel:

```bash
uv build --wheel
```

## Documentation

- [Documentation overview](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/README.md): how to build and preview the docs.
- [Usage and integration](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/source/usage.md): transformer names, MLIA
  discovery, and route selection.
- [Conversion flow](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/source/conversion_flow.md): what each converter route
  does.
- [CLI integration](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/source/cli.md): how this package relates to
  `mlia check`.
- [Troubleshooting](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/docs/source/troubleshooting.md): common converter failures
  and debug steps.

## Releases

Latest changes and release history can be found in
[MLIA PyTorch Converter releases](https://github.com/arm/mlia-converters-pytorch/releases).

## License

This project is licensed under the Apache License 2.0. See
[`LICENSES/Apache-2.0.txt`](https://github.com/arm/mlia-converters-pytorch/blob/b73a68e77f450cb161b5c892abccdc092d4d02ca/LICENSES/Apache-2.0.txt) for the full license text.

## Trademarks and copyrights

- Arm and Arm Ethos-U are registered trademarks or trademarks of Arm Limited (or its subsidiaries) in the U.S. and/or elsewhere.
- PyTorch and ExecuTorch are trademarks of The Linux Foundation.
- Linux is the registered trademark of Linus Torvalds in the U.S. and elsewhere.
- Python is a registered trademark of the PSF.
