November 24, 2026
Bodo Engineering Team
In Part 1 of this series, we examined four established open-source inference compiler ecosystems: torch.compile, vLLM, XLA, and TVM. Despite differences in their architectures, they share a common approach of transforming high-level model computations through a series of intermediate representations, applying graph-level optimizations, and ultimately generating or selecting optimized hardware-specific kernels.
In this post, we explore three more specialized approaches to inference optimization: TensorRT/TensorRT-LLM, Luminal, and Mirage Persistent Kernel (MPK). These systems illustrate different strategies for extracting more performance from inference workloads, including hardware-specific kernel selection and tuning, search-based exploration of equivalent implementations, and persistent execution of entire model computations on the GPU as a megakernel.
As in Part 1, we examine each system's compilation pipeline, high- and low-level IRs, and key transformations, using matrix multiplication, attention, and Qwen3-0.6B as representative examples.
TensorRT is NVIDIA’s inference SDK for building and running optimized, target-specific engines on NVIDIA GPUs. A typical workflow imports a model (often from ONNX) or constructs a network through TensorRT’s API. During the build phase, TensorRT transforms the network, selects implementations and tactics for its operations, and produces a serialized engine. At runtime, an application loads that engine and executes it through an execution context. For dynamic dimensions, the builder uses optimization profiles that specify supported minimum, preferred, and maximum shapes.
TensorRT-LLM is an LLM library and runtime built around NVIDIA’s inference stack. It includes model definitions, weight-loading paths, attention implementations, and serving features such as batching and KV-cache management. In its PyTorch backend, models are implemented using PyTorch modules that can use TensorRT-LLM-specific modules and attention backends. For example, its model-authoring guide describes decoder layers built from embedding, normalization, attention, and MLP modules; it also recommends specialized Linear, Embedding, RotaryEmbedding, and RMSNorm modules where their parallelism, quantization, or performance features are needed.
The TensorRT API exposes a network representation called INetworkDefinition. It is a directed acyclic graph (DAG) of ILayer objects connected by ITensor values. Layers describe operations, while tensors carry properties such as shape and datatype. The API includes operations such as matrix multiplication, activation, reduction, softmax, normalization, gather, slice, and shuffle (used for shape and layout transformations). Dynamic dimensions are represented symbolically and constrained by optimization profiles at build time.
Matrix multiplication can be represented by an IMatrixMultiplyLayer, which specifies how each operand is treated (e.g., normally, transposed, or as a vector). When importing a graph, matrix multiplication may originate as an ONNX MatMul or Gemm operation. The builder may select a specialized implementation for the operation; the network-level layer does not by itself specify the final GPU kernel.
Attention can be represented in more than one way. A network may contain the attention operation as a high-level IAttention layer, or represent it as a series of matrix multiplications, softmax, masking, and tensor-layout operations. TensorRT’s attention API exposes choices such as softmax normalization and causal masking. Whether that operation can remain fused depends on the supported configuration and implementation; it is not safe to assume every attention graph is automatically converted to one fused attention kernel.
TensorRT-LLM’s PyTorch backend has its own model-facing abstractions, including attention modules and backend interfaces. Its attention backend receives runtime metadata describing the batch and KV cache, then delegates the operation to an implementation such as the TensorRT-LLM or FlashInfer backend. This is a model/runtime interface, distinct from TensorRT’s public INetworkDefinition graph.
During engine construction, TensorRT can simplify and rewrite the network. Depending on the imported graph and available implementations, transformations include constant folding, elimination of redundant shape operations, removal of unused layers, and recognition or fusion of supported patterns. It can also combine compatible matrix multiplications that share an input, such as Q/K/V projections, when the graph and build path allow their weights and outputs to be combined. Such fusion is an optimization opportunity, not a guarantee for every model.
The builder chooses tactics (called candidate implementations) for supported operations and may benchmark them for the target GPU and configured shapes. Tactics can differ in kernel algorithm, tiling, precision, and data layout. Build configuration, optimization profiles, available plugins, precision constraints, and hardware all affect the final engine.
TensorRT-LLM adds LLM-oriented model and runtime capabilities. Its model implementations can use fused projections, quantization-aware modules, optimized normalization and rotary operations, and specialized attention backends. The selected attention backend determines how attention and KV-cache operations are executed; for example, TensorRT-LLM documents backends with support for paged KV cache and features such as RoPE fusion. These capabilities are backend and configuration dependent.
TensorRT’s internal compiler representations are not public. The builder lowers network operations into implementations such as library calls, plugins, and generated kernels, then records the selected tactics and required runtime information in the serialized engine. The engine is specific to the target environment and is executed by TensorRT’s runtime.
However, verbose build and layer information can expose selected tactics, layer types, tensor shapes and layouts, and metadata linking optimized layers to source graph operations. Some logs also show generated-kernel entries, including Myelin or kgen layers. These are useful evidence that TensorRT grouped work into generated kernels, but they are not a complete public specification of TensorRT’s internal IR or optimization pipeline.
TensorRT-LLM’s PyTorch backend can instead run model code through its PyTorch runtime and dispatch attention to its configured backend. Therefore, the low-level execution path depends on which TensorRT-LLM workflow is being used: a serialized TensorRT engine or the PyTorch backend. In either case, runtime features such as batching, attention metadata, and KV-cache management are part of how LLM inference is executed, not merely details of the model’s mathematical graph.
Luminal is an ahead-of-time, search-based compiler targeting CUDA and Metal. Models can be defined using its Rust-native Tensor API or compiled from PyTorch using a torch.compile backend. During compilation, Luminal first lowers the model into a Logical IR containing primitive tensor operations. It then applies transformation rules to generate alternative computations and backend-specific implementations, rather than committing to a single implementation immediately. A genetic search explores these alternatives, lowering candidate implementations through Layout IR and Buffer IR for memory planning before compiling and benchmarking them on the target hardware. Measured performance guides subsequent search iterations, ultimately selecting an optimized execution plan.
Luminal uses a small set of primitive tensor operators, including elementwise arithmetic, indexing operations, and reductions. Higher-level operations such as matrix multiplication are expressed as compositions of these primitives.
For example, the following graph implements a matrix multiplication between tensors of shapes [3,1] and [1,4]. The LogicalIndexMapApply nodes map both inputs into a common [3,4,1] iteration space, after which LogicalMul performs elementwise multiplication and LogicalReduceSum reduces the final dimension to produce a [3,4] result.

The IR is a directed acyclic graph (DAG): nodes represent tensor-producing operations, and edges represent their input dependencies. Tensor shapes and dtypes are tracked throughout the graph. The same primitive operators are used to represent more complex computations such as attention.
Unlike compilers that apply optimization rules greedily, Luminal uses search-based optimization to explore alternative implementations of a computation. Rather than committing to a particular transformation immediately, Luminal uses E-graphs to compactly represent many equivalent expressions in a single graph, allowing it to explore different combinations of optimizations before selecting an implementation.
An E-graph consists of E-classes and E-nodes. Each E-class groups expressions that compute the same result, while each E-node represents an operator whose inputs reference other E-classes. For example, the diagram below represents v3 = v0 * v1 + v2, including alternative operand orderings and a fused multiply-add implementation. All expressions within the same E-class are considered equivalent.

Luminal uses Egglog rules to populate the E-graph with alternative computations and implementations through a process called equality saturation. Logical rules introduce equivalent expressions, such as reordering operands, while backend-specific implementation rules recognize patterns that can be implemented using optimized operators.
For the matmul example, Luminal can recognize the combination of elementwise multiplication and reduction as matrix multiplication and introduce a cuBLAS implementation. This alternative coexists with other valid implementations in the E-graph rather than immediately replacing them. Candidate extraction and benchmarking determine which implementation is ultimately selected.
For a Qwen3 decode layer including the attention, QKV projections, and MLP), Luminal selected cuBLAS implementations for several matrix multiplications and matrix multiply-add operations (AB + C). However, the attention computation remained largely unfused, with QKᵀ, softmax, and PV represented as separate operations in the selected plan.
After E-graph saturation, Luminal samples candidate implementations and lowers them to Layout IR, a DAG of operators connected by tensors with explicit shapes, dtypes, and memory layouts (e.g., row-major). Layout IR is then lowered to Buffer IR, where operations explicitly read from and write to buffers. A subsequent memory-planning phase assigns physical storage to these buffers.
The Buffer IR for the CUDA matmul example is shown below:

Finally, Luminal generates kernel code and launch metadata from Buffer IR. For external library operations, such as the CublasLt matmul shown above, the runtime instead invokes the corresponding library call.
Mirage Persistent Kernel (MPK) is a compiler and runtime for executing LLM inference as a persistent GPU workload. Rather than launching a separate GPU kernel for each model operation, MPK divides operations into tasks and executes them inside a long-running megakernel. Dependencies between tasks are managed on the GPU, reducing the need for host-driven launches and global kernel boundaries during inference.
MPK targets NVIDIA GPUs and includes architecture-specific task implementations. It can load Hugging Face model weights, but the model computation is described by a model-specific builder using MPK’s layer APIs rather than captured directly from an arbitrary PyTorch graph. The builder defines the operations, tensor buffers, and task grids. MPK then analyzes their dependencies, generates a task graph and CUDA code, and compiles the result for the target GPU.
MPK uses Mirage’s kernel graph to represent the model as a graph of layer operations connected by tensors. Each layer has a thread-block graph describing its task grid and how the grid partitions its input and output tensors. A layer can represent a matrix multiplication, attention, or a more specialized operation such as a matrix multiplication with a residual addition. The actual work for one task is supplied by a registered task implementation.
For Qwen3, the builder describes the beginning of each attention block approximately as follows:
mpk.rmsnorm_layer(
input=x, weight=w_norm, output=rmsnorm_out,
grid_dim=(max_num_batched_tokens, 1, 1),
block_dim=(128, 1, 1),
)
mpk.linear_layer(
input=rmsnorm_out, weight=w_qkv, output=attn_in,
grid_dim=(64, 1, 1), block_dim=(128, 1, 1),
)
mpk.paged_attention_layer(
input=attn_in, k_cache=k_cache, v_cache=v_cache,
q_norm=w_q_norm, k_norm=w_k_norm,
cos_pos_embed=cos_pos_embed, sin_pos_embed=sin_pos_embed,
output=attn_out,
grid_dim=(1, 8, 1), block_dim=(128, 1, 1),
)
Here the builder selects separate RMSNorm and linear operations, followed by a paged attention operation. The QKV weights are arranged into a combined projection, so the linear operation produces Q, K, and V together. The attention task receives the KV cache, normalization weights, and rotary embedding inputs and attention is not represented as separate QKᵀ, softmax, and PV nodes in this graph. The builder also selects a linear operation with residual addition for the attention output projection and the MLP down projection.
MPK lowers the layer graph into a task and event graph. A task represents one partition of a layer’s work that has a descriptor which identifies the task implementation, input and output tensor regions, and synchronization events. An event tracks completion of a group of producer tasks and determines when dependent work can proceed.
For the Qwen3 configuration above, each layer’s QKV projection is divided into 64 tasks, while paged attention is divided into eight tasks, one per KV head. MPK compares how the two layers partition their shared tensor and creates eight dependency events. Each attention task waits for the eight QKV tasks producing its portion of the projection, rather than waiting for all 64 tasks. This allows downstream work to begin as soon as its required tiles are ready.
MPK also analyzes dependencies when intermediate buffers are reused across layers. It can remove a redundant direct residual dependency when another path already enforces the required ordering; the residual tensor remains an input to the operation. In this Qwen3 builder, QKV and gate/up weights are rearranged during initialization so that the corresponding projection tasks read contiguous regions.
These transformations do not imply that every neighboring operation is automatically fused into one task. In this example, RMSNorm and the QKV linear projection remain separate tasks; their execution is combined into the persistent workload, while their intermediate data is still passed through GPU memory.
The lowered task graph records tensor names, offsets, shapes, strides, task types, and event IDs. MPK also emits CUDA code containing a dispatcher that selects a specialized device implementation for each task type and variant. At initialization, tensor references are resolved to GPU addresses and the task and event descriptors are prepared for execution.
In the Qwen3 run, the graph contains 7,464 task descriptors and 1,772 events. Many descriptors share the same implementation: the generated dispatcher has 11 task variants for operations including linear layers, RMSNorm, paged attention, SiLU multiplication, and argmax. Repeated layers therefore reuse task code while referring to different weights and tensor regions.
The runtime enqueues work for an iteration and workers wait on dependency counters before executing tasks. Completion updates the corresponding counters, and the scheduler advances to the next batch or decode iteration when the graph finishes. Depending on configuration, workers and schedulers can run in one persistent kernel or in separate persistent kernels.
This approach removes repeated per-operation launches, but it does not eliminate all intermediate memory traffic or synchronization. Tasks still exchange data through GPU memory, and persistent workers must operate within a shared resource budget for registers and shared memory. Performance also depends on the selected task grids, worker and scheduler configuration, and target-specific implementations.
Across the seven compilers examined in this series, we see several different approaches to optimizing LLM inference. While they share many underlying techniques, an important distinction is the scope of optimization decisions they explore. Most compilers perform some form of kernel selection and tuning, evaluating alternative implementations for individual operations or fused groups. TVM extends this through search-based scheduling of tensor computations, while Luminal uses equality saturation to explore a broader space of equivalent computation graphs and backend implementations. These approaches offer different tradeoffs between compilation cost, search complexity, and the ability to discover more efficient execution plans.
Another important distinction is the granularity at which computations are optimized and executed. Most compilers focus on individual operations or fused groups, often relying on highly optimized libraries such as cuBLAS, FlashAttention, and FlashInfer. MPK takes a different approach, coordinating execution across an entire model within a persistent GPU megakernel. This enables optimizations to scheduling and synchronization across traditional kernel boundaries, without necessarily fusing all operations into a single task. As model architectures and hardware platforms continue to diversify, we expect broader optimization search spaces and more aggressive cross-operator optimization to become increasingly important.



