Abstract
Optimizing deep learning models is generally performed in two steps: (i) high-level graph optimizations such as kernel fusion and (ii) low level kernel optimizations such as those found in vendor libraries. This approach often leaves significant performance on the table, especially for the case of recursive deep learning models. In this paper, we present Cortex, a compiler-based approach to generate highly-efficient code for recursive models for low latency inference. Our compiler approach and low reliance on vendor libraries enables us to perform end-to-end optimizations, leading to up to 14X lower inference latencies over past work, across different backends.
Introduction
Recursive deep learning models, such as TreeLSTMs and DAG-RNNs, are powerful tools for processing data with inherent hierarchies, such as parse trees in natural language or spatial relations in images. However, these models are notoriously difficult to optimize for high-performance inference. Current frameworks like PyTorch or DyNet typically rely on "black-box" vendor libraries (e.g., cuDNN or MKL). While these libraries are highly tuned for standard operations, they treat operations as isolated kernels, creating three major bottlenecks for recursive models: poor coverage for niche variants, isolation that prevents kernel fusion, and significant dynamic overhead due to input-dependent control flow.
Methodology
Cortex shifts the optimization strategy from utilizing pre-compiled libraries to compiling the model logic directly. The core of this approach is the Irregular Loop Intermediate Representation (ILIR), which bridges the gap between recursive definitions and hardware-efficient iterative loops.
The Cortex pipeline involves several critical stages:
- Lowering Recursion to Loops: Cortex identifies a key property (P.1) of these models: control flow depends on connectivity (e.g., tree shape) rather than computed data. This allows the compiler to "linearize" recursion into efficient iterative loops.
- Data Structure Linearization: At runtime, pointer-based structures are flattened into arrays. This transformation makes the data "GPU-friendly" and facilitates efficient dynamic batching.
- End-to-End Optimizations: With a global view of the computation, Cortex performs aggressive kernel fusion to keep data in fast on-chip registers. It also employs model persistence, maintaining weights in the GPU's scratchpad memory throughout the recursive traversal.
Evaluation and Results
The framework was evaluated using several representative recursive models, including TreeFC, DAG-RNN, TreeGRU, TreeLSTM, and MV-RNN. Benchmarks were conducted on the Stanford Sentiment Treebank across various hardware backends, including Nvidia GPUs, Intel CPUs, and ARM CPUs.
Cortex consistently outperformed state-of-the-art frameworks like DyNet, Cavs, and PyTorch. Key results include:
- Latency Reduction: Cortex achieved up to 14X lower inference latency compared to previous work.
- Operational Intensity: On GPUs, Cortex-generated kernels demonstrated significantly higher operational intensity, validating the effectiveness of its kernel fusion and model persistence strategies.
- Memory Efficiency: Cortex utilized substantially less GPU memory by avoiding the need to store every intermediate tensor for the entire duration of the recursive pass.
Discussion and Future Work
A significant finding is the "black box" penalty associated with vendor libraries. While they offer high performance for standard ops, they hinder the cross-operation optimizations essential for the small, frequent operations in recursive models. Additionally, the overhead of data structure linearization on the host CPU was found to be negligible (often <2% of total runtime).
Future work will address the complexity of optimizations for Directed Acyclic Graphs (DAGs), manage register pressure from aggressive fusion, and extend these compiler techniques to the backward pass for training.
Summary updated