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.6.25.dev0-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.6.25.dev0-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.6.25.dev0-cp313-cp313-macosx_11_0_arm64.whl (54.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-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.6.25.dev0-cp312-cp312-macosx_11_0_arm64.whl (54.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-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.6.25.dev0-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.6.25.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eaf579c864a3d3621c5779b50b1c3d5e4276dba6ea2baea46c3e055b1b7dd009
MD5 264b4712aa818b5d9cab8b84c6ec6710
BLAKE2b-256 80bce7ab99ce1b233dc9d0c18a5772059ef735b16f2720499506de01c81170a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 51368c0ea25b3a84939b6e864c8eb29caa7fa157f69105ccc980f82abf988d34
MD5 c002b5c1af9ab06afe0e3f7b5a08e666
BLAKE2b-256 e014315d5c4dd05a2f400af027339850846c32f326505e81260693578e94c4b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f45a0cfbd9e34c8ed6a31509ed7ea43f1d6beb35402825f1a1d0992767b71dd
MD5 e28f95a19ca2ac3a8af62355cb594907
BLAKE2b-256 eb88be138a29fa45db88c7e366c38f16a562b5262aba6c181dedcd08fb54dee1

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db803161962a2cdb48bfa6671d60610976712f9b6b6c43ee453b58fc6de0b689
MD5 c6abf74a3d049a0778e839cf069fb35d
BLAKE2b-256 5ae7571b295dbc096523038afab1ba137f945e6f209a7a55491e34dad76bdf6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 204c5e20cfa103914c1ed75d200f5d11b81acd5c1dcb0f8263f43d1a0e6416e3
MD5 0835fef04738da59c3db770905b96a26
BLAKE2b-256 9e7e97d1071efb34c06dedf5375bc39ad448b628fc8e8fc1adfe70d264d909fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3903d7e8d1630ea602cf22d53b1d7b0ddbaa07415c9fad5e1411ed913ffd84b1
MD5 3515a5afc6226cdf3913d42bd7cc59dd
BLAKE2b-256 55e909d7d4aa8b6099fccc0fecead11d1a78de3e335ba48f1f33cea4873ff9a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b52fa51ed5ff14016594ed774243e96e86af7c7f7e769f4f6b73e1248717401
MD5 8be675b09b23bd011f5d2cff4683f7df
BLAKE2b-256 19d1a8d76502f22e889bc76ca2723266b4e1cfe2cbf5ec40346510e24bfcf658

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 50f0ab2d93136f0897b604b5dae32654213f85087c4abd2870814e7768d87cd5
MD5 05f2c95d48d627ea544aa46668858914
BLAKE2b-256 1d69724b1fdd48e37418863f8b0934519708fce847509b211504d639895d9f84

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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.6.25.dev0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_torch_mlir-2026.6.25.dev0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b35efa483f95a1464571217398cebdf38d3905e55e67cae025b9045d47fe16b
MD5 835279a95b77dd64f16a98d89e949be4
BLAKE2b-256 ccc59e333fad16c457ebcc812685f088ca670fa5bfdeaefaaed09a9a2ef0cbe5

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_torch_mlir-2026.6.25.dev0-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