Manuscript Offprint

arXiv:2609.37916

RLX: A Unified Multi-Backend Tensor Compiler and Distributed Runtime in Rust

Eugene Hauptmann, Nataliya Kosmyna

Eugene Hauptmann

Massachusetts Institute of Technology

Cambridge, MA, USA

eugenehp@mit.edu

Nataliya Kosmyna

Massachusetts Institute of Technology

Cambridge, MA, USA

nkosmyna@mit.edu

Abstract—Production machine learning (ML) stacks often split graph compilation and kernel execution across different layers and languages, making backend behavior, deployment guarantees, and performance fallbacks hard to reason about end-to-end. RLX addresses this gap with a single Rust codebase that combines compiler and runtime roles around one primitive-level, three-level intermediate representation (IR), plus a transparent dispatch contract that resolves each operator to native, common-IR, or rewritten lowering and fails compilation when legalization is not possible. The same IR targets fourteen runtime devices (cpu, metal,mlx, ane, cuda, rocm, oneapi, tpu, hexagon, gpu, vulkan, opengl, directx, webgpu) and two specialty codegen paths (Cortex-M INT8 and FPGA), ingests safetensors, GGUF, ONNX, and rten formats, supports F16/BF16/F64/C64 and quantized INT4/INT8 flows with AMP/PTQ/QAT, and scales via tensor-/pipeline-parallel collectives over TCP and RDMA transports. Beyond neural workloads, RLX also extends to scientific/physics-style domains through sparse and dense linear algebra extensions (e.g., CSR LU/CG/matvec and LAPACK-backed factorizations) and 3D Gaussian splatting operators. We evaluate RLX against PyTorch, TensorFlow, JAX, candle, burn, tch, rten, MLX, CoreML, IREE, Glow, TensorRT, and tinygrad under identical input generation and p50 measurement methodology on one host. On all-MiniLM-L6-v2, RLX-Metal is fastest at every batch (e.g., 16.6 ms at batch 32 vs. PyTorch-MPS 26.7 ms). In the MNIST training table, RLX also has the top-throughput entry (graph-fused MLP: 946,487 img/s), above NumPy+BLAS (787,349 img/s), while retaining 100% top-1 parity on reference checks (e.g., Qwen3).

Index Terms—machine learning systems, compilers, intermediate representation, automatic differentiation, heterogeneous hardware, Rust, quantization, distributed computing

I. INTRODUCTION

The progress of machine learning has been coupled to the ease with which developers can turn high-level model descriptions into efficient code on diverse hardware. Two strategies dominate. Graph compilers such as XLA [6], TVM [4], and MLIR [5] capture a whole-program representation and apply fusion, layout, and scheduling transformations before emitting code. Kernel runtimes such as cuDNN [7], Apple's Metal Performance Shaders, and MLX [8] instead provide a curated set of hand-optimized primitives that an eager front end dispatches at run time. The first strategy maximizes cross-operator optimization; the second minimizes the distance between a call and a vendor-tuned kernel.

In practice the two are combined together with adapter layers, foreign-function boundaries, and a host language, typically Python, that is separate from the systems language in which the kernels are written. Python’s global interpreter lock, per-object reference counting, and dynamic dispatch impose a latency cost that adds up at small batch sizes and limits threading. It further complicates deployment to limited or non-traditional targets, such as microcontrollers, web browsers, custom silicon, and makes it hard to verify end-to-end if the code will actually run.

We introduce RLX a single, memory-safe system language which can host both a graph compiler and a kernel runtime, with one IR spanning the full range of targets from a server GPU down to an INT8 microcontroller. RLX is implemented as a Rust workspace of layered crates. Its IR is a small, composable set of primitives: structured control flow (Op::Scan), dense linear solves (Op::DenseSolve), quantization (Op::FakeQuantize, Op::DequantMatMul), masked attention with an explicit MaskKind, and a first-class custom-op extension surface. The optimizer performs fusion, automatic-mixed-precision policy, reverse- and forward-mode automatic differentiation, batching (vmap), broadcast legalization, and post-training-quantization insertion. The runtime performs backend dispatch, compile caching, and cost-based device selection across heterogeneous hardware.

This paper contributes a unified IR, optimizer, and runtime in one Rust workspace (Section III); a transparent dispatch that fails and does not silently degrade (Section IV) the graph ops and performance; portability across fourteen runtime and two codegen targets (Section V); extensibility, including distributed TP/PP (Section VI, Section III-D); and a cross-framework evaluation with runnable benchmark scripts (Section VIII).

References (24)

  • TensorFlow: A system for large-scale machine learning
  • PyTorch: An imperative style, high-performance deep learning library
  • Compiling machine learning programs via high-level tracing
  • TVM: An automated end-to-end optimizing compiler for deep learning
  • MLIR: Scaling compiler infrastructure for domain-specific computation
  • XLA: Optimizing compiler for machine learning
  • cuDNN: Efficient Primitives for Deep Learning
  • MLX: machine learning on Apple Silicon
  • Burn: a deep-learning framework in Rust
  • Candle: minimalist ML for Rust
  • tch-rs: Rust bindings for libtorch
  • rten: an ML runtime for Rust
  • ONNX Runtime
  • ONNX: Open Neural Network Exchange
  • ggml: tensor library for machine learning
  • llama.cpp: LLM inference in C/C++
  • mistral.rs: an LLM inference engine in Rust
  • IREE: an MLIR-based end-to-end compiler and runtime
  • Glow: graph lowering compiler techniques for neural networks (opens arXiv in a new tab)
  • MAX and the Mojo programming language
  • TensorRT: a high-performance deep-learning inference SDK
  • tinygrad: a simple deep-learning framework
  • Luminal: ahead-of-time deep-learning compilation in Rust
  • ZML: AI inference in Zig