TL;DR
FlashRNN introduces a suite of hardware-optimized kernels for traditional Recurrent Neural Networks (RNNs) like LSTMs and GRUs, as well as modern variants like sLSTM. By leveraging kernel fusion and a custom integer constraint solver for auto-tuning, it achieves up to 50x speedups over standard PyTorch implementations, making state-tracking architectures competitive with Transformers on modern GPU hardware.
What Problem Does This Paper Address?
While Transformers dominate modern sequence modeling due to their massive parallelizability, they have a fundamental weakness: state-tracking. Tasks involving long-term logical reasoning or complex time-series often require a model to maintain and update a compressed "state" of the past, a feat RNNs excel at but Transformers struggle with.
However, RNNs have fallen out of favor because they are inherently sequential—each step depends on the previous one. On modern GPUs, which are designed for parallel workloads, this sequential nature makes RNNs incredibly slow and "memory-bound." Most existing RNN implementations suffer from high I/O overhead, constantly moving data between slow global memory (HBM) and fast on-chip caches. FlashRNN aims to bridge this performance gap, proving that RNNs can be fast if we optimize how they interact with hardware.
Methods
The authors employ several advanced systems-level techniques to accelerate RNNs:
- Kernel Fusion: Instead of executing matrix multiplications and activation functions as separate steps (which forces the GPU to write intermediate results back to slow memory), FlashRNN fuses them into a single "persistent" kernel. This allows recurrent weights and hidden states to stay in the fastest possible memory—the registers—across multiple time steps.
- Head-wise Parallelization: Borrowing a concept from Transformers, FlashRNN supports block-diagonal recurrent matrices. This splits the large hidden state into multiple independent "heads" that can be processed in parallel across different GPU execution units.
- ConstrINT (Integer Constraint Satisfaction): Optimizing a kernel requires picking the perfect "tiling" sizes (how much data to process at once). These sizes must satisfy complex hardware constraints (e.g., "does this fit in the 256KB SRAM of an H100?"). The authors developed
ConstrINT, a library that automatically solves these mathematical constraints to tune the kernel for any specific GPU architecture.
Datasets
The researchers evaluated FlashRNN across three main areas:
- Runtime Benchmarking: Synthetic tests measuring speed across various batch sizes, sequence lengths, and hidden dimensions on NVIDIA H100 and A100 GPUs.
- Language Modeling: Training a 165M parameter model on 15 billion tokens of the SlimPajama dataset to compare training throughput and validation perplexity against Transformers.
- State Tracking (Parity Task): A synthetic benchmark requiring the model to count the parity of bits in a sequence, specifically testing the ability to extrapolate to sequences much longer than those seen during training.
Key Insights and Ideas
- RNNs are I/O Bound, not just Sequential: The "slowness" of RNNs isn't just the sequential loop; it's the cost of reloading weights from HBM at every single time step. By keeping weights in registers, FlashRNN taps into memory bandwidth that is orders of magnitude higher than standard global memory.
- The "State-Tracking" Advantage: The paper demonstrates that while Transformers and even modern State Space Models (like Mamba) fail at simple state-tracking tasks like Parity (staying near 50% accuracy), traditional RNNs and sLSTMs achieve 100% accuracy.
- Hardware-Awareness is Portable: Through the
ConstrINTlibrary, the authors show that we don't need to manually rewrite CUDA code for every new GPU generation. We can model the hardware as a set of constraints and let a solver find the optimal execution strategy.
Key Results
- Massive Speedups: FlashRNN kernels achieved up to 50x speedups over vanilla PyTorch RNN implementations.
- Superior Scaling: The fused CUDA kernels allow for 40x larger hidden sizes than standard Triton implementations by more efficiently managing the register file.
- Efficiency at Scale: In language modeling tasks, FlashRNN-based models were only about 25% slower than highly optimized FlashAttention-based Transformers, a significantly smaller gap than previously thought possible for sequential models.
Limitations and Future Work
- Triton vs. CUDA: The Triton implementation, while easier to write, cannot currently match the performance of the hand-written CUDA kernels because it lacks fine-grained control over GPU registers.
- Hopper Features: The current version does not yet utilize the newest hardware features of the NVIDIA Hopper (H100) architecture, such as asynchronous memory copies (TMA) or specialized inter-SRAM communication.
- Numerical Precision: The authors noted slight numerical deviations compared to NVIDIA's closed-source cuDNN library. While these didn't hurt model convergence in their tests, they suggest further investigation into the impact of register-level accumulation on long-term numerical stability.
Summary updated