Skip to main content

First-class interop between PyTorch and MLIR

Project description

The Torch-MLIR Project

The Torch-MLIR project aims to provide first class compiler support from the PyTorch ecosystem to the MLIR ecosystem.

This project is participating in the LLVM Incubator process: as such, it is not part of any official LLVM release. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project is not yet endorsed as a component of LLVM.

PyTorch PyTorch is an open source machine learning framework that facilitates the seamless transition from research and prototyping to production-level deployment.

MLIR The MLIR project offers a novel approach for building extensible and reusable compiler architectures, which address the issue of software fragmentation, reduce the cost of developing domain-specific compilers, improve compilation for heterogeneous hardware, and promote compatibility between existing compilers.

Torch-MLIR Several vendors have adopted MLIR as the middle layer in their systems, enabling them to map frameworks such as PyTorch, JAX, and TensorFlow into MLIR and subsequently lower them to their target hardware. We have observed half a dozen custom lowerings from PyTorch to MLIR, making it easier for hardware vendors to focus on their unique value, rather than needing to implement yet another PyTorch frontend for MLIR. The ultimate aim is to be similar to the current hardware vendors adding LLVM target support, rather than each one implementing Clang or a C++ frontend.

pre-commit

All the roads from PyTorch to Torch MLIR Dialect

We have few paths to lower down to the Torch MLIR Dialect.

  • ONNX as the entry points.
  • Fx as the entry points

Project Communication

  • #torch-mlir channel on the LLVM Discord - this is the most active communication channel
  • Github issues here
  • torch-mlir section of LLVM Discourse

Install torch-mlir snapshot

At the time of writing, we release pre-built snapshots of torch-mlir for Python 3.11 and Python 3.10.

If you have supported Python version, the following commands initialize a virtual environment.

python3.11 -m venv mlir_venv
source mlir_venv/bin/activate

Or, if you want to switch over multiple versions of Python using conda, you can create a conda environment with Python 3.11.

conda create -n torch-mlir python=3.11
conda activate torch-mlir
python -m pip install --upgrade pip

Then, we can install torch-mlir with the corresponding torch and torchvision nightlies.

pip install --pre torch-mlir torchvision \
  --extra-index-url https://download.pytorch.org/whl/nightly/cpu \
  -f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels

Using torch-mlir

Torch-MLIR is primarily a project that is integrated into compilers to bridge them to PyTorch and ONNX. If contemplating a new integration, it may be helpful to refer to existing downstreams:

While most of the project is exercised via testing paths, there are some ways that an end user can directly use the APIs without further integration:

FxImporter ResNet18

# Get the latest example if you haven't checked out the code
wget https://raw.githubusercontent.com/llvm/torch-mlir/main/projects/pt1/examples/fximporter_resnet18.py

# Run ResNet18 as a standalone script.
python projects/pt1/examples/fximporter_resnet18.py

# Output
load image from https://upload.wikimedia.org/wikipedia/commons/2/26/YellowLabradorLooking_new.jpg
...
PyTorch prediction
[('Labrador retriever', 70.65674591064453), ('golden retriever', 4.988346099853516), ('Saluki, gazelle hound', 4.477451324462891)]
torch-mlir prediction
[('Labrador retriever', 70.6567153930664), ('golden retriever', 4.988325119018555), ('Saluki, gazelle hound', 4.477458477020264)]

Repository Layout

The project follows the conventions of typical MLIR-based projects:

  • include/torch-mlir, lib structure for C++ MLIR compiler dialects/passes.
  • test for holding test code.
  • tools for torch-mlir-opt and such.
  • python top level directory for Python code

Developers

If you would like to develop and build torch-mlir from source please look at Development Notes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (78.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

belfort_torch_mlir-2026.7.1-cp313-cp313-macosx_11_0_arm64.whl (54.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (78.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

belfort_torch_mlir-2026.7.1-cp312-cp312-macosx_11_0_arm64.whl (54.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (78.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

belfort_torch_mlir-2026.7.1-cp311-cp311-macosx_11_0_arm64.whl (54.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b4009c5676488b0d7137157923110d716aaecc9c269620a2baeb30409410ed1c
MD5 333e7b185a5447de6e1b8ed3f5cfe41e
BLAKE2b-256 17a042d398947696567b91cbe2802fb7ca2a628f68a6f4824141de35aa38b98c

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c55a9a2e99046bd8d9d3b504f8b14d13473b678906d10bd9c7a2c1355521df35
MD5 44545f7cd800beca6fc948a802142851
BLAKE2b-256 a6736f3249ef62627341cc3adad27b4e713f6c7ea3bf890578d1aa7cfd1dfb42

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6485cf4e8ee94091d3dc0dc1f974ae8bde5a42f7b51619915d0fb011f9037f10
MD5 a43682ada7971ea266aec482dbc51c20
BLAKE2b-256 d62b80c341704c8704afbfa34bc7f669c6898df9ca775fa3202dfeee107fe3a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6dddc3c49e45497c0ae94077bb4075569a34c62e4ec8a987a56fd412e2b2246d
MD5 019c4aaf765b2de62bd225ce1d1b5d4e
BLAKE2b-256 088ddd4d42559115f4db68bff3b3dc917f575023f52961a0711c8d3f8b755a95

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6f2d863ff53989a745ab183b6a2ebf046ec4db4717dd90ae69f9b7674ab9a70f
MD5 9ffab987f6634d99ae96d66566d1113d
BLAKE2b-256 cce4b2c5aac5da4c8cbc6072f884e425d671311b94a3549eab4399bb4a53b7fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fdeb34f384d4759412786a43ce35ca79ec714a933a5ef629409f33af358e68de
MD5 f7395baa6c88b2da55e9884c57398e9b
BLAKE2b-256 718d7db733eccaeec879006259d51569d336c0280f53d0bc968d65db8a71a5e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 551dee293062c83b6c51d85bed5de68216784a675481e129d505b90447d2e889
MD5 687145b90222f0efa796128f6d09a32e
BLAKE2b-256 403a89d78e07aeb7abc27996eba948d8c825ffb0a02f379bf4c51957c506797b

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ff78f6215bdff3c49b1f2f80bf2277caec61a6237d25f6643dc0fa76a4ffa88b
MD5 5a5f2066ca56808181f4708116ca04e6
BLAKE2b-256 255b6284aecc790330a08df2268c45676deb629682dc60ad8b24f98b2db185df

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file belfort_torch_mlir-2026.7.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.7.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 981da9ac2891f5784b6c8a9b49387aa4bf85611eb7a3eae2bb1d47328019780f
MD5 0a683a314234b556ef638e698911b410
BLAKE2b-256 4ae1bc38a13857bcb7047dc15a97e2cf7c98b3690c962790481e0931969c7798

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.7.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on belfortlabs/torch-mlir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page