Just-In-Time Fusion (JIT Fusion) is a compiler optimization performed during model execution, not ahead of time. It dynamically analyzes the runtime computational graph—often with specific input tensor shapes and hardware context—to identify and fuse sequences of primitive operations into single, optimized fused kernels. This contrasts with static Ahead-of-Time Fusion (AOT Fusion), offering adaptability to variable inputs and execution environments. The primary goal is to minimize kernel launch overhead and reduce costly intermediate memory transfers between global GPU memory and on-chip caches.
Glossary
Just-In-Time Fusion (JIT Fusion)

What is Just-In-Time Fusion (JIT Fusion)?
Just-In-Time Fusion (JIT Fusion) is a dynamic runtime optimization technique in deep learning compilation where decisions about which computational operators to combine, and the generation of the corresponding fused kernel, are deferred until model execution.
The JIT fusion process is managed by a fusion compiler or runtime, such as those in PyTorch's torch.compile (via the Inductor backend) or JAX's XLA. A fusion planner uses fusion heuristics and a cost model to determine fusion profitability, deciding whether combining operators like elementwise operations or a Conv-BN-ReLU pattern will yield a net performance gain. By generating tailored kernels at runtime, JIT fusion optimizes for both memory-bound and compute-bound workloads, directly reducing inference latency and improving hardware utilization.
Core Mechanisms of JIT Fusion
Just-In-Time Fusion is a dynamic compilation strategy where operator fusion decisions and kernel generation are deferred until runtime, allowing optimizations to be tailored to the specific input shapes, data types, and hardware context of each execution.
Dynamic Graph Capture & Profiling
The first phase of JIT Fusion involves capturing the computational graph of a model as it executes with real input data. A runtime profiler analyzes this graph, collecting metrics like:
- Tensor shapes and strides
- Operator execution frequency
- Memory access patterns
- Data dependencies This live profiling data provides the concrete context that static, Ahead-of-Time (AOT) compilers must estimate, enabling more accurate fusion decisions.
Runtime Fusion Planning
A fusion planner uses the profiled graph to construct an optimal fusion plan. Unlike static fusion, this planner can make decisions based on the actual runtime environment. Key considerations include:
- Fusion Profitability: Weighing reduced kernel launch overhead and improved data locality against potential downsides like increased register pressure.
- Hardware-Specific Heuristics: Applying different fusion rules for an NVIDIA A100's Tensor Cores versus an AMD MI250X's Matrix Cores.
- Input-Dependent Optimizations: Fusing loops differently for a batch size of 1 (real-time inference) versus a batch size of 128 (offline processing).
On-the-Fly Kernel Generation
Once a fusion plan is created, the JIT compiler generates highly specialized kernels for the identified fusion groups. This involves:
- Code Generation: Emitting low-level GPU code (e.g., CUDA, HIP) or intermediate representation (IR) for the fused operation sequence.
- Automatic Tuning: Performing micro-optimizations like loop unrolling, memory coalescing, and shared memory allocation based on the exact tensor shapes.
- Caching: Storing the generated kernel in a runtime cache keyed by the graph signature and input specs. Subsequent calls with identical patterns execute the cached kernel, amortizing compilation cost.
Integration with Execution Engines
JIT Fusion is not a standalone process; it integrates deeply with a framework's execution runtime. Key integration points are:
- Graph Interception: The runtime must intercept operator calls (e.g., PyTorch's
torch.nn.Module.forward) to capture the graph before dispatching to unoptimized kernels. - Kernel Dispatch: A dispatcher routes execution to either a pre-compiled library kernel (e.g., cuDNN) or a newly JIT-fused kernel.
- Memory Management: The fused kernel must operate within the framework's allocator, often requiring careful management of intermediate tensor lifetimes to avoid leaks.
Trade-offs: Flexibility vs. Overhead
JIT Fusion introduces a fundamental trade-off between optimization flexibility and runtime overhead.
Advantages:
- Adaptability: Optimizes for unpredictable input shapes or dynamic control flow.
- Portability: A single model definition can be optimized for diverse backend hardware at runtime.
- Incremental Optimization: Can re-optimize based on observed production workloads.
Disadvantages:
- Compilation Latency: The 'cold start' cost of profiling and code generation for the first run.
- Increased Complexity: Requires a sophisticated runtime compiler integrated into the inference server.
- Cache Management Overhead: Managing and invalidating a cache of generated kernels.
Real-World Implementations
JIT Fusion is a core optimization in modern ML compilers and frameworks.
- PyTorch's
torch.compile: Uses a JIT compiler (Inductor) to fuse PyTorch operations into efficient Triton or CUDA kernels. - TensorFlow/XLA: While often AOT, its JIT compilation mode for TPUs and GPUs performs runtime fusion based on the actual graph.
- Apache TVM's VM: Employs a virtual machine that can JIT-compile and fuse operators using its AutoTVM or Ansor auto-schedulers.
- NVIDIA's TensorRT: Uses a JIT layer to fuse operators and generate kernels specifically for the GPU it's running on, optimizing for the exact SM architecture.
How Just-In-Time Fusion Works
Just-In-Time Fusion (JIT Fusion) is a runtime optimization technique that dynamically combines multiple computational operators into a single, efficient kernel during model execution.
Just-In-Time Fusion (JIT Fusion) is a runtime optimization where a compiler dynamically decides which operators to fuse and generates the corresponding fused kernel during model execution, not ahead of time. This approach allows the optimization to adapt to the specific input shapes, data types, and hardware context present at inference, enabling more aggressive and context-aware fusion than static, ahead-of-time methods. It is a core component of modern JIT compilers like torch.compile in PyTorch 2.x.
The process begins with the graph capture of a model's computational operators. A fusion planner then analyzes this graph using fusion heuristics and a cost model to identify profitable fusion groups, such as consecutive elementwise operations. The compiler's backend (e.g., Inductor for PyTorch) subsequently generates a single, optimized fused kernel for each group. This eliminates kernel launch overhead and reduces costly intermediate memory transfers, directly improving latency and throughput for inference optimization.
JIT Fusion in Major Frameworks
Just-In-Time Fusion is implemented differently across major deep learning frameworks, each with its own compiler stack and optimization philosophy. This section explores the core JIT fusion engines powering modern AI inference.
JIT Fusion vs. Ahead-of-Time (AOT) Fusion
A comparison of two primary strategies for implementing operator and kernel fusion, highlighting their trade-offs in flexibility, performance, and deployment complexity.
| Feature / Metric | Just-In-Time (JIT) Fusion | Ahead-of-Time (AOT) Fusion |
|---|---|---|
Optimization Timing | Dynamic, at runtime (or first execution) | Static, during compilation before deployment |
Input Shape Flexibility | ||
Hardware Context Awareness | ||
Compilation Overhead | Incurred at runtime (warm-up latency) | Incurred once during build (zero runtime overhead) |
Deployment Artifact | Original model graph + fusion compiler | Single, pre-fused executable binary |
Portability | High (adapts to target device) | Low (tied to specific hardware/software target) |
Profiling & Adaptive Optimization | ||
Debugging Complexity | Higher (runtime code generation) | Lower (static, predictable execution) |
Typical Use Case | Interactive development, dynamic inputs, multi-platform serving | Edge deployment, latency-critical production, fixed hardware |
Frequently Asked Questions
Just-In-Time Fusion (JIT Fusion) is a dynamic runtime optimization technique where decisions about which neural network operators to combine and the generation of the corresponding fused kernel are deferred until model execution. This approach tailors optimizations to the specific input data shapes and the immediate hardware context.
Just-In-Time Fusion (JIT Fusion) is a runtime optimization technique where a compiler or runtime system dynamically decides which adjacent computational operators in a neural network graph to combine and generates the corresponding fused kernel during model execution, rather than during a separate, static compilation phase. This allows the optimization to adapt to the specific input tensor shapes, data types, and hardware characteristics present at inference time. The primary goal is to reduce kernel launch overhead and minimize intermediate memory transfers by executing multiple operations within a single, optimized GPU or accelerator kernel launch. It represents a shift from static, ahead-of-time (AOT) compilation to a more flexible, adaptive optimization strategy.
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
Just-In-Time Fusion is one technique within a broader compiler optimization strategy. These related concepts define the mechanisms, tools, and decisions that enable efficient kernel generation.
Kernel Fusion
A low-level compiler optimization that combines multiple computational kernels (e.g., for ReLU, addition, scaling) into a single, unified GPU kernel. The primary goal is to reduce kernel launch overhead and improve data locality by keeping intermediate results in fast registers or shared memory instead of writing them back to global memory.
Operator Fusion
A graph-level optimization that merges adjacent computational operators (nodes) in a neural network's computational graph into a single, compound operation. This minimizes intermediate memory transfers between layers. For example, fusing a Convolution, Batch Normalization, and ReLU activation into one Conv-BN-ReLU operator.
Ahead-of-Time Fusion (AOT)
The static compilation strategy where fusion decisions and kernel generation are performed before runtime. This produces a pre-optimized, fused executable for a specific target hardware (e.g., a specific GPU architecture). AOT fusion trades runtime flexibility for maximum optimization and minimal startup latency.
Fusion Compiler
A specialized compiler or compiler pass responsible for automatically performing fusion optimizations. Key examples include:
- XLA (Accelerated Linear Algebra): Used by TensorFlow/JAX for aggressive fusion.
- TVM: Uses its scheduling language to generate high-performance fused kernels.
- MLIR: Employs dialects like Linalg to represent and transform graphs for fusion.
Fusion Heuristics & Cost Model
The rule-based or predictive algorithms a compiler uses to decide fusion profitability. A cost model estimates the performance impact of fusing a group of operators by analyzing:
- Data dependencies and memory access patterns.
- Potential increase in register pressure.
- Trade-off between reduced launch overhead and lost parallelism.
- Whether the workload is memory-bound or compute-bound.
Fused Multi-Head Attention
A canonical example of a highly beneficial fused kernel. It combines the entire attention mechanism—query/key/value projection, scoring, softmax, and weighted aggregation—into a single GPU launch. Optimized implementations like FlashAttention go further by being IO-aware, strategically recomputing scores on-chip to minimize costly memory reads/writes to high-bandwidth memory (HBM).

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