Fusion in XLA is the suite of aggressive compiler optimizations performed by Google's Accelerated Linear Algebra (XLA) compiler that merges multiple computational operators or kernels into a single, compound operation. This transformation occurs on the High-Level Operations (HLO) intermediate representation, where the compiler identifies subgraphs of operations—like a convolution followed by batch normalization and ReLU—and replaces them with a custom, fused kernel. The primary goals are to minimize kernel launch overhead, reduce costly intermediate memory transfers between global and on-chip memory, and increase arithmetic intensity to better saturate hardware like TPUs and GPUs.
Glossary
Fusion in XLA

What is Fusion in XLA?
Fusion in XLA is the compiler's core technique for merging multiple low-level operations into a single, efficient kernel.
The compiler uses fusion heuristics and a cost model to decide fusion profitability, balancing improved data locality against potential downsides like increased register pressure. Common strategies include vertical fusion of dependent operations and horizontal fusion of parallel ones. By generating these optimized kernels ahead-of-time (AOT) or just-in-time (JIT), XLA significantly accelerates model execution in frameworks like TensorFlow and JAX, making it a foundational technique for inference optimization and latency reduction.
Key Fusion Mechanisms in XLA
XLA's aggressive fusion strategies transform a high-level computational graph into a minimal set of high-performance kernels by eliminating intermediate memory traffic and launch overhead.
Vertical (Producer-Consumer) Fusion
Vertical fusion merges a sequence of dependent operations where the output of one operator is the immediate input to the next. This is the most common and profitable fusion pattern.
- Mechanism: Chains operations like
MatMul -> BiasAdd -> ReLUinto a single kernel. - Primary Benefit: Eliminates the write and subsequent read of the intermediate tensor to slow global memory (e.g., HBM).
- Example: Fusing a convolution with its following batch normalization and activation function is a classic vertical fusion that can yield >2x speedup by keeping data in registers or shared memory.
Horizontal (Sibling) Fusion
Horizontal fusion combines multiple independent operations that consume the same input tensor or operate in parallel within the dataflow graph.
- Mechanism: Executes several element-wise operations on the same data in a single kernel pass.
- Primary Benefit: Amortizes kernel launch overhead and improves memory bandwidth utilization by reading the input data once for multiple computations.
- Example: Applying both a
Sinand aCosfunction to the same tensor can be fused horizontally. The compiler must ensure the fused operations have compatible shapes and can be mapped to the same parallel execution grid.
Elementwise and Pointwise Fusion
This is a specific, highly profitable case of vertical/horizontal fusion targeting elementwise operations.
- Definition: An operation is elementwise if it computes each output element independently using only the corresponding input elements (e.g.,
Add,ReLU,Tanh). - Mechanism: XLA fuses long chains of pointwise ops into a single kernel. The combined operation performs all per-element computations before writing the final result to memory.
- Benefit: Dramatically reduces memory-bound bottlenecks. For example, a graph with ten sequential pointwise ops would perform ten global memory reads and writes without fusion, but only one read and one write with fusion.
Fusion via The HLO Intermediate Representation
XLA performs fusion on its High-Level Operations (HLO) IR, which is a compiler-friendly representation of the computation.
- Process: The input graph (e.g., from TensorFlow or JAX) is lowered to HLO. The HLO fusion pass analyzes the dataflow and applies fusion heuristics.
- Cost Model: The compiler uses a cost model to estimate the profitability of fusing a candidate group, considering factors like reduced memory bytes accessed versus potential increase in kernel register pressure.
- Output: The pass outputs a new HLO graph where
HloFusionInstructionnodes replace the original subgraphs of primitive operations.
The Fusion Planner and Profitability Analysis
XLA does not fuse all possible operations; it uses a fusion planner to make greedy or cost-model-driven decisions.
- Key Consideration - Fusion Profitability: Not all fusion is beneficial. Fusing a very large, compute-intensive operation (like a convolution) with a tiny one may not justify the added complexity and could hurt occupancy.
- Heuristics: The planner uses rules such as:
- Fuse producers into consumers unless the producer has multiple users.
- Prefer to fuse operations that are "expensive" to materialize (large outputs).
- Avoid fusing operations that would create a kernel with excessive register usage.
- Goal: To generate a fusion plan that minimizes total execution time, not just kernel count.
Canonical Fused Patterns (e.g., Conv-BN-ReLU)
XLA recognizes and aggressively fuses common, performance-critical subgraph patterns found in neural networks.
- Conv-BN-ReLU: The quintessential fused layer in CNNs. XLA fuses the Convolution, Batch Normalization (scale, shift, mean, variance), and ReLU activation. The BN parameters are compiled directly into the kernel, and the activation is applied before writing to global memory.
- LayerNorm + GeLU: A common pattern in transformers. The elementwise GeLU activation is fused with the preceding LayerNorm operation.
- Impact: These hand-optimized equivalent patterns are generated automatically, providing performance comparable to manually written fused kernels without requiring user intervention.
How Does Fusion in XLA Work?
Fusion in XLA is the compiler's process of combining multiple low-level computational operations into a single, optimized kernel to minimize execution overhead and maximize hardware efficiency.
Fusion in XLA is an aggressive, multi-pass optimization performed by Google's Accelerated Linear Algebra compiler on a model's High-Level Operations (HLO) graph. It identifies subgraphs of operations—like elementwise functions or a Conv-BN-ReLU sequence—that can be merged. The compiler then replaces these subgraphs with a single, custom fused kernel. This eliminates the kernel launch overhead and costly intermediate memory reads/writes between the original separate operations, which are significant bottlenecks.
The fusion process is guided by heuristics and cost models that analyze data dependencies, memory access patterns, and hardware characteristics to determine fusion profitability. XLA performs both vertical fusion (chaining producer-consumer ops) and horizontal fusion (merging parallel ops). The final fused kernel is just-in-time (JIT) compiled for the specific target accelerator (e.g., GPU, TPU), ensuring the combined computation is executed with optimal data locality and minimal latency.
Canonical Fused Patterns
Canonical fused patterns are pre-defined, high-performance operator combinations that the XLA compiler recognizes and automatically replaces with a single, optimized kernel. These patterns represent common computational motifs in neural networks where fusion provides significant performance benefits.
Conv-Bias-Activation
This is the quintessential fused pattern for convolutional neural networks. XLA fuses a Convolution layer, an Add operation for the bias term, and a non-linear activation function (e.g., ReLU, Sigmoid) into one kernel.
- Eliminates two intermediate tensor writes and reads.
- Keeps data in fast GPU registers or shared memory between operations.
- Example:
Conv2D+BiasAdd+ReLUbecomes a single__nv_fused_conv2d_bias_relukernel call.
BatchNorm and its Variants
XLA aggressively fuses Batch Normalization with surrounding operations. The canonical pattern is Conv-BatchNorm-Activation. During inference, the batch norm's mean, variance, scale, and offset are statically folded into the preceding convolution's weights and bias, creating a mathematically equivalent but faster single operation.
- Training vs. Inference: Folding is primarily an inference-time optimization.
- Extended Patterns: Can include preceding Conv or MatMul and following Activation.
MatMul-Bias-(Activation/GeLU)
The fundamental building block of transformer and fully-connected networks. XLA fuses a Matrix Multiplication (MatMul), the addition of a bias vector, and frequently an activation like ReLU or Gaussian Error Linear Unit (GeLU).
- Critical for LLMs: This fusion is a major performance factor in the dense layers of transformers.
- Reduces Memory Bandwidth: The large output of the MatMul is consumed immediately without a round-trip to global GPU memory.
Elementwise Op Chains
XLA fuses sequences of pointwise (elementwise) operations that apply a function independently to each tensor element. Common examples include:
-
Add -> Tanh
-
Multiply -> Add (e.g., a residual connection adjustment)
-
Long chains of Unary Ops (e.g.,
Cast->Log->Neg) -
Key Benefit: Amortizes kernel launch overhead across many light operations.
-
Horizontal Fusion: Can also fuse independent elementwise ops on the same input.
Reduction Fusion
XLA fuses a reduction operation (e.g., Sum, Max) with a preceding elementwise operation that prepares the data. Instead of writing the full intermediate tensor, the fused kernel performs the elementwise op and immediately accumulates the result.
- Pattern:
Broadcast->Elementwise->Reduce. - Example: Calculating Softmax involves a
Exp,Reduce(Sum)across a dimension, and aDivide. Key parts of this chain are fused. - Impact: Dramatically reduces memory footprint for large reduction dimensions.
The Fusion Planner & Profitability
XLA doesn't fuse blindly. Its fusion planner uses a cost model to assess fusion profitability. It analyzes:
- Data Dependencies: Only fuses producers with direct consumers (vertical fusion).
- Memory vs. Compute Bound: Prioritizes fusing memory-bound ops to reduce data movement.
- Kernel Launch Overhead: Weighs savings against potential downsides like increased register pressure or decreased parallelism.
The planner identifies subgraphs matching canonical patterns and decides if generating a custom fused kernel will be faster than executing the ops separately.
Fusion in XLA vs. Other Compiler Approaches
A feature comparison of operator fusion strategies across major deep learning compilers, highlighting architectural priorities and target use cases.
| Feature / Dimension | XLA (TensorFlow/JAX) | TVM (Apache) | MLIR-based Compilers (e.g., IREE) |
|---|---|---|---|
Primary Fusion Strategy | Aggressive, heuristic-driven graph fusion | Schedule-driven, explicit via Tensor Expression | Pattern-based, dialect-specific rewrite rules |
Optimization Scope | Whole-graph, ahead-of-time (AOT) & just-in-time (JIT) | Per-layer or subgraph, often via auto-scheduling | Multi-level, from high-level ops to low-level loops |
Fusion Profitability Model | Rule-based heuristics with simple cost estimates | Cost model guided by hardware performance metrics | Transformations defined within dialect semantics |
Canonical Fused Patterns | Conv-BN-ReLU, elementwise chains, reductions | Custom patterns via manual scheduling templates | Linalg tiled operations, affine loop fusion |
Hardware Target Specialization | TPU-first, with strong GPU support | Extensive backend support (CPU, GPU, accelerators) | Retargetable via lowering through multiple dialects |
Integration with Framework | Tightly coupled (TensorFlow, JAX runtime) | Frontend-agnostic (PyTorch, TensorFlow, ONNX) | Framework-agnostic intermediate representation |
Key Performance Goal | Minimize kernel launch overhead & HBM traffic | Maximize hardware utilization via auto-tuning | Expose and optimize for data locality & parallelism |
Typical Use Case | Production server-side inference & training | Deployment to diverse edge & server hardware | Research into novel compiler passes & hardware |
Frequently Asked Questions
Fusion in XLA refers to the suite of aggressive operator fusion optimizations performed by Google's Accelerated Linear Algebra compiler, a core component of frameworks like TensorFlow and JAX. These FAQs address how it works and its impact on performance.
Operator fusion in XLA is a compiler optimization that merges multiple low-level computational operations into a single, unified kernel to be executed on an accelerator like a GPU or TPU. It works by analyzing the High-Level Operations (HLO) intermediate representation of a computational graph, identifying clusters of operations (fusion groups) that can be profitably combined, and then generating a single, custom kernel for that cluster. This process eliminates intermediate memory allocations and kernel launch overhead, directly improving execution speed and hardware utilization.
Key Mechanisms:
- Graph Analysis: XLA's fusion pass traverses the HLO graph, applying heuristics to find fusible patterns.
- Fusion Planning: A planner decides which groups of operations to fuse based on a cost model that estimates the trade-off between reduced memory traffic and potential downsides like increased register pressure.
- Code Generation: For each fusion group, XLA's LLVM-based backend generates a single, optimized kernel loop that performs all the fused operations in a single pass over the data.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Fusion in XLA is a core compiler optimization. To fully understand its mechanics and impact, explore these related concepts that define the landscape of computational graph optimization.
Kernel Fusion
Kernel fusion is the low-level compiler technique of combining multiple GPU or accelerator kernels into a single, unified kernel. This eliminates the kernel launch overhead and temporary memory writes/reads between operations. It is the fundamental hardware-level mechanism that enables the performance gains from higher-level operator fusion.
- Primary Benefit: Reduces latency from repeated kernel launch setup and teardown.
- Key Challenge: Requires careful management of on-chip resources like registers and shared memory.
- Example: Fusing an element-wise
tanhoperation with a preceding matrix multiplication into one CUDA kernel.
Operator Fusion
Operator fusion is a graph-level optimization that merges adjacent nodes (operators) in a neural network's computational graph. XLA performs this before generating low-level kernels. The goal is to minimize intermediate tensor materialization in high-bandwidth memory (HBM).
- Vertical Fusion: Chains a producer operator with its consumer (e.g., a
matmulfeeding directly into abias_add). - Horizontal Fusion: Combines independent operators that share an input or have similar shapes.
- Profitability Analysis: The compiler uses a cost model to decide if fusion reduces memory traffic more than it increases register pressure.
Graph Fusion
Graph fusion is the automated process of identifying and merging subgraphs within a full computational graph. In XLA, this involves pattern matching to find known profitable sequences (like Conv2D -> BatchNorm -> ReLU). The compiler partitions the graph into fusion groups, where all internal edges represent fast, on-chip communication.
- Fusion Planner: The component that explores the search space of possible fusions.
- Fusion Group: The final set of operators scheduled for a single kernel.
- Scope: Works across both linear chains and more complex, branching subgraphs.
Fusion Heuristics & Cost Models
Fusion heuristics are the rule-based or ML-driven policies a compiler uses to decide what to fuse. A cost model for fusion predicts the execution time of a potential fusion group, balancing:
- Reduced Global Memory Access: The primary benefit.
- Increased Register Pressure: Can limit parallelism if too high.
- Kernel Launch Overhead Savings: More significant for many small ops.
- Potential for Parallelism Loss: Fusing independent ops may reduce concurrent execution.
XLA's fusion planner uses such models to maximize fusion profitability.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us