IREE Python Compiler API - MLIR-based end-to-end compiler for Machine Learning models
npx @tessl/cli install tessl/pypi-iree-base-compiler@3.6.0IREE Base Compiler provides Python APIs for compiling Machine Learning models using IREE's MLIR-based end-to-end compiler infrastructure. It enables developers to compile ML models from various frameworks (TensorFlow, PyTorch, ONNX) into IREE's optimized intermediate representation for deployment across diverse hardware targets including CPUs, GPUs, and accelerators.
pip install iree-base-compilerimport iree.compilerHigh-level compilation tools:
from iree.compiler.tools import compile_str, compile_file, CompilerOptionsLow-level embedding API:
from iree.compiler.api import Session, Invocation, Source, OutputBuild system:
import iree.buildimport iree.compiler.tools
# Simple MLIR compilation
SIMPLE_MUL_ASM = """
func.func @simple_mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> {
%0 = arith.mulf %arg0, %arg1 : tensor<4xf32>
return %0 : tensor<4xf32>
}
"""
# Compile to FlatBuffer binary for CPU target
binary = iree.compiler.tools.compile_str(
SIMPLE_MUL_ASM,
input_type="auto",
target_backends=["llvm-cpu"]
)
# Compile from file with options
options = iree.compiler.tools.CompilerOptions(
target_backends=["llvm-cpu"],
optimize=True,
output_file="output.vmfb"
)
iree.compiler.tools.compile_file("input.mlir", **options.__dict__)IREE Base Compiler provides multiple API layers for different use cases:
iree.compiler.tools): User-friendly compilation functions with simplified options for common workflowsiree.compiler.api): Direct access to the C embedding API for advanced control over compilation sessions and invocationsiree.build): Declarative build system for complex compilation workflows with dependencies and actionsThis layered design supports everything from simple model compilation to complex multi-step build pipelines in production ML deployment systems.
High-level compilation functions for compiling MLIR code to IREE VM modules, supporting various input formats and target backends.
def compile_str(input_str: Union[str, bytes], **kwargs) -> Optional[bytes]: ...
def compile_file(input_file: str, **kwargs) -> Optional[bytes]: ...
def query_available_targets() -> List[str]: ...Low-level C API bindings providing direct access to IREE's compiler infrastructure through Session, Invocation, Source, and Output objects.
class Session: ...
class Invocation: ...
class Source: ...
class Output: ...Declarative build system for managing complex compilation workflows with dependencies, actions, and entrypoints.
@entrypoint
def build_func(): ...
class CompileSourceAction: ...
class CompileStdModuleAction: ...Specialized APIs for importing and compiling models from TensorFlow and TensorFlow Lite frameworks.
def compile_from_tf_module(tf_module, **kwargs): ...
def compile_from_tflite_file(tflite_path, **kwargs): ...Console scripts providing command-line access to compilation, optimization, and import functionality.
# Console scripts:
# iree-compile, iree-opt, iree-import-onnx, iree-ir-tool, iree-build