Graph fusion is a compiler optimization technique that automatically identifies and merges sequences or clusters of operators within a neural network's computational graph into single, compound operations. This process, guided by pattern matching and hardware-aware cost models, creates custom fused kernels that execute the combined logic. The primary goal is to minimize kernel launch overhead and reduce costly intermediate memory transfers between global GPU memory and on-chip registers or caches, thereby improving computational efficiency and reducing latency.
Glossary
Graph Fusion

What is Graph Fusion?
Graph fusion is a core compiler optimization for accelerating neural network inference and training by restructuring computational graphs.
The optimization is performed by fusion compilers like XLA, TVM, and MLIR, which analyze data dependencies and operator properties to form fusion groups. Key strategies include vertical fusion of dependent operations and horizontal fusion of parallel operations. Successful fusion, as seen in patterns like Conv-BN-ReLU or FlashAttention, transforms memory-bound operations into compute-bound ones, maximizing hardware utilization. The profitability of fusion is evaluated against potential downsides like increased register pressure.
Core Mechanisms of Graph Fusion
Graph fusion is a compiler-driven optimization that transforms a computational graph by merging multiple primitive operations into efficient, compound kernels. Its core mechanisms are designed to minimize overhead and maximize hardware utilization.
Pattern Matching & Subgraph Identification
The compiler first traverses the computational graph to identify subgraphs of operators that are profitable to fuse. This is often done via pattern matching against known, high-benefit sequences (e.g., Conv-BatchNorm-ReLU). The process analyzes data dependencies and tensor shapes to find fusible groups, known as fusion groups.
Cost Model & Profitability Analysis
A cost model evaluates whether fusing a candidate group will yield a net performance gain. It estimates:
- Reduction in kernel launch overhead and global memory traffic.
- Increase in arithmetic intensity and data locality.
- Potential downsides like increased register pressure or reduced parallelism. The fusion planner uses this model to construct an optimal fusion plan, prioritizing memory-bound operations where fusion benefits are highest.
Kernel Generation & Code Emission
Once a fusion group is finalized, the compiler generates a single fused kernel. This involves:
- Lowering the fused operator subgraph to a unified intermediate representation.
- Applying loop fusion and scheduling transformations to optimize for cache hierarchy (e.g., L1, shared memory).
- Emitting target-specific code (e.g., CUDA, Metal) for the new compound operation. Compilers like XLA, TVM, and MLIR specialize in this automated kernel generation.
Vertical vs. Horizontal Fusion
Fusion strategies are categorized by the dataflow relationship between operators:
- Vertical Fusion: Merges a producer operator with its consumer (e.g., a matrix multiplication followed by a bias add). This reduces intermediate results written to slow memory.
- Horizontal Fusion: Merges independent operators that consume the same input or operate in parallel. This amortizes kernel launch overhead and can improve memory coalescing. Compilers use heuristics to apply the most beneficial strategy per subgraph.
Ahead-of-Time vs. Just-in-Time Fusion
Fusion can occur at different stages in the compilation pipeline:
- Ahead-of-Time (AOT) Fusion: The graph is analyzed, fused, and compiled to a static executable before deployment. This minimizes runtime overhead and is used for fixed graph deployments.
- Just-in-Time (JIT) Fusion: Performed dynamically at runtime (e.g., via
torch.compile). This allows fusion decisions to adapt to dynamic input shapes and specific hardware contexts, offering flexibility for dynamic graphs.
Canonical Fused Operators
Certain fused operator patterns are so ubiquitous they have dedicated, hand-tuned implementations:
- Fused Conv-BN-ReLU: The standard building block of CNNs, combining convolution, batch normalization, and activation.
- Fused Multi-Head Attention: A key optimization in transformers, famously implemented by FlashAttention. It fuses the entire attention mechanism (QKV projection, scoring, softmax, aggregation) into one IO-aware kernel to minimize HBM accesses.
- Elementwise Fusion: Chains pointwise ops (e.g., Add, Sigmoid, Mul) that operate independently on each tensor element.
How Graph Fusion Works: A Compiler's Process
Graph fusion is a compiler-driven optimization that merges multiple computational nodes in a neural network's dataflow graph into single, efficient kernels.
The process begins with graph analysis, where the compiler traverses the computational graph to identify candidate subgraphs for fusion. It uses pattern matching to find known, profitable operator sequences (like Conv-BN-ReLU) and applies fusion heuristics or a cost model to evaluate the performance impact of merging them. The goal is to create fusion groups that minimize intermediate memory transfers and kernel launch overhead.
Once groups are identified, the compiler performs kernel generation, creating a single fused kernel that implements the combined operations. This involves fusion-aware scheduling to optimize memory access patterns and register usage for the target hardware. The final fused graph is then executed, with the fused kernel reducing data movement and improving arithmetic intensity, leading to lower latency and higher throughput during inference.
Graph Fusion in Major Frameworks & Compilers
Graph fusion is not a monolithic technique but is implemented through distinct compiler architectures and optimization philosophies across the machine learning ecosystem. This section details how major frameworks execute this critical optimization.
Types of Fusion: Vertical vs. Horizontal
A comparison of the two primary strategies for combining operators within a computational graph, based on the data dependency relationship between the operations.
| Characteristic | Vertical Fusion | Horizontal Fusion |
|---|---|---|
Primary Objective | Reduce intermediate memory traffic between sequentially dependent operations | Amortize kernel launch overhead and improve parallelism for independent operations |
Dataflow Relationship | Fuses a producer operator with its direct consumer operator | Fuses multiple sibling operators that consume the same input or operate in parallel |
Graph Pattern | Linear chain (e.g., Op A -> Op B) | Fan-out or parallel branch (e.g., Input -> Op A, Op B, Op C) |
Typical Operations Fused | Elementwise ops (ReLU, Sigmoid) following heavy ops (MatMul, Conv), Convolution-BatchNorm-ReLU | Independent pointwise operations applied to the same tensor (e.g., multiple Sigmoid branches) |
Primary Performance Gain | Eliminates write/read of intermediate tensor to slow global memory (DRAM) | Reduces total number of kernel launches, consolidating parallel work |
Compiler Complexity | Moderate; requires dependency analysis and profitability checks for memory-bound sequences | High; must handle potential resource conflicts (e.g., register pressure) and may reduce parallelism if done naively |
Impact on Kernel Characteristics | Increases arithmetic intensity of the fused kernel; can become compute-bound | Increases the workload and potential parallelism of a single kernel; remains memory-bound if fusing only light ops |
Example in Frameworks | XLA fusing a MatMul with a following bias add and ReLU activation | TVM fusing three independent Sigmoid operations applied to the same input tensor into one kernel |
Frequently Asked Questions
Graph fusion is a critical compiler optimization for high-performance machine learning. This FAQ addresses common technical questions about how it works, its benefits, and its implementation across modern frameworks.
Graph fusion is a compiler optimization that automatically identifies and merges multiple, adjacent computational operators within a neural network's dataflow graph into a single, compound operation executed by a fused kernel. It works by analyzing the computational graph, applying pattern matching and fusion heuristics to find profitable subgraphs (called fusion groups), and then generating or selecting a unified kernel that performs the combined computation, thereby minimizing intermediate memory transfers and kernel launch overhead.
The Fusion Process
- Graph Analysis: The compiler (e.g., XLA, TVM, torch.compile) parses the model's computational graph.
- Pattern Matching: It identifies known, efficient patterns for fusion, such as
Conv -> BatchNorm -> ReLU. - Profitability Analysis: A cost model for fusion estimates the performance impact of merging candidate operators.
- Kernel Generation: For the selected fusion groups, the compiler generates a fused kernel (e.g., using CUDA or MLIR) or selects a pre-optimized one (like FlashAttention).
- Graph Rewriting: The original graph is rewritten, replacing the subgraph with the new fused operator.
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
Graph fusion is a compiler optimization that merges subgraphs of operators. These related concepts define the specific techniques, tools, and patterns that enable this process.
Operator Fusion
Operator fusion is the foundational graph-level optimization that merges adjacent computational nodes in a neural network's computational graph into a single, compound operation. Its primary goal is to minimize the overhead of writing and reading intermediate results to and from slow global memory (e.g., GPU HBM).
- Mechanism: The compiler identifies a chain of operations (e.g.,
matmul -> add -> relu) and replaces them with a single, custom operator. - Benefit: Eliminates multiple kernel launch latencies and reduces memory bandwidth pressure, which is often the bottleneck for inference.
- Example: Fusing a convolution, batch normalization, and ReLU activation into one kernel is a standard optimization in frameworks like TensorFlow (via XLA) and PyTorch (via
torch.compile).
Kernel Fusion
Kernel fusion is the low-level implementation of operator fusion, where multiple GPU or accelerator kernels are combined into a single, unified kernel. This occurs after the graph-level decision to fuse operators has been made.
- Core Challenge: Writing an efficient fused kernel requires expert-level knowledge of hardware memory hierarchies (registers, shared memory, L1/L2 cache) and parallelism models (warps, thread blocks).
- Compiler Role: Modern ML compilers like TVM and MLIR can automatically generate high-performance fused kernels, moving this task from manual coding to automated scheduling.
- Impact: Reduces kernel launch overhead, a significant latency source when executing thousands of small, sequential operations.
Fusion Compiler (XLA/TVM/MLIR)
A fusion compiler is a specialized compiler or compiler pass responsible for automatically performing graph and kernel fusion. These are critical infrastructure components in modern ML frameworks.
- XLA (Accelerated Linear Algebra): Google's compiler for TensorFlow and JAX. It performs ahead-of-time (AOT) or just-in-time (JIT) fusion by aggressively identifying fusible subgraphs and generating efficient code for TPUs, GPUs, and CPUs.
- Apache TVM: An open-source compiler stack that uses its scheduling language (AutoTVM, Ansor) to explore the search space of possible kernel fusions and optimizations for diverse hardware backends.
- MLIR (Multi-Level Intermediate Representation): Provides reusable infrastructure for building compilers. Its Linalg and Affine dialects offer powerful, pattern-based transformations for representing and performing fusion on computational graphs.
Fusion Heuristics & Cost Model
Fusion heuristics and cost models are the decision-making engines that determine which operator groups are profitable to fuse. A compiler cannot fuse all possible operators, as excessive fusion can lead to register spilling or reduced parallelism.
- Heuristics: Rule-based logic (e.g., "always fuse elementwise operations with their data-dependent producer").
- Cost Model: A predictive model that estimates the execution time or memory traffic of fused vs. unfused versions. It considers:
- Data dependency patterns.
- Operator arithmetic intensity (compute-bound vs. memory-bound).
- Hardware-specific parameters (memory bandwidth, cache sizes).
- Fusion Planner: The component that uses the cost model to construct an optimal fusion plan, often by exploring a constrained search space.
Vertical vs. Horizontal Fusion
These are two fundamental patterns for grouping operators within a computational graph.
- Vertical Fusion (Producer-Consumer): Merges operators that are sequentially dependent. This is the most common pattern, chaining operations to keep intermediate data in fast registers or cache.
- Example: Fusing a
layernormoperation with a subsequentlinearprojection.
- Example: Fusing a
- Horizontal Fusion (Parallel/Sibling): Merges independent operators that consume the same input tensor or operate in parallel. This increases workload per kernel and amortizes launch overhead.
- Example: Fusing the separate
q,k,vlinear projections at the start of a multi-head attention block into a single, batched matrix multiplication.
- Example: Fusing the separate
- Hybrid Approaches: Advanced compilers perform both types, often within the same subgraph, to maximize data locality and hardware utilization.
Canonical Fused Operators
These are hand-optimized, fused implementations of common neural network patterns. They serve as both performance targets for compilers and as manually crafted kernels for maximum speed.
- Fused Conv-BN-ReLU: The quintessential CNN fusion, combining Convolution, Batch Normalization, and ReLU Activation. It folds the BN parameters into the conv weights at runtime, making the normalization and activation effectively free.
- Fused Multi-Head Attention / FlashAttention: A revolutionary fused kernel that computes the entire attention mechanism in a single pass while minimizing reads/writes to high-bandwidth memory (HBM). FlashAttention uses IO-aware algorithms to recompute attention scores on-chip (SRAM), enabling training and inference with extremely long sequences.
- Fused LayerNorm + GeGLU/SiLU: Common in transformer FFN blocks, fusing the normalization and gated activation functions reduces memory traffic for a key, memory-bound operation.

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