Were RNNs All We Needed?

Leo Feng, Frederick Tung, Mohamed Osama Ahmed, Yoshua Bengio, Hossein Hajimirsadeghi · DOI

The Efficiency Bottleneck of Traditional RNNs

For decades, Recurrent Neural Networks (RNNs) like the LSTM (1997) and GRU (2014) were the standard for sequence modeling. However, the rise of the Transformer in 2017 shifted the landscape. The primary issue with traditional RNNs wasn't their performance, but their efficiency.

Traditional RNNs are inherently sequential: calculating the state at time $t$ requires the completed calculation for time $t-1$. This dependency makes them impossible to parallelize across modern GPUs during training. While Transformers solved this with parallel self-attention, they introduced quadratic computational complexity, making them prohibitively expensive for very long sequences. Researchers have recently asked: Can we modify classic RNNs to be parallelizable like Transformers while maintaining the linear scaling of recurrent models?

The Minimalist Approach: minLSTM and minGRU

The core innovation presented in recent research is a "back-to-basics" simplification of LSTMs and GRUs. By stripping away previous-state dependencies within the gates, the authors created minLSTM and minGRU.

Comparison of standard LSTM and the simplified minLSTM architecture.

The simplification involves several key steps:

  1. Dropping Dependencies: In a standard GRU or LSTM, gates depend on the previous hidden state ($h_{t-1}$). By making these gates depend only on the current input ($x_t$), the recurrence relation becomes linear: $v_t = a_t \odot v_{t-1} + b_t$.
  2. Parallel Scan: With a linear recurrence, the model can utilize a Parallel Scan algorithm. This allows hidden states for an entire sequence to be computed in $O(\log N)$ time rather than $O(N)$ sequential steps.
  3. Removing Range Restrictions: The tanh activation function was removed from candidate states. This simplifies the architecture and, when stacking multiple layers, does not negatively impact performance.
  4. Log-Space Implementation: To maintain numerical stability and prevent gradient issues, the authors derived versions of these models that operate in log-space.

Benchmarking Performance

The models were evaluated across a diverse range of benchmarks, including Selective Copying, the Chomsky Hierarchy for logical reasoning, and the Long Range Arena (LRA) for long-context modeling. They were also tested in Reinforcement Learning (D4RL) and character-level language modeling using the works of Shakespeare.

The results demonstrate that these minimal architectures are not just faster, but highly competitive. In the Selective Copying task, minGRU and minLSTM achieved nearly 100% accuracy, outperforming modern models like S4 and Hyena. In language modeling, they reached performance levels comparable to Transformers and Mamba while requiring significantly fewer training steps.

Results: Speed and Accuracy

The most striking result is the massive improvement in training efficiency. By enabling parallelization, the minimal RNNs overcome the primary hurdle that led to the decline of traditional recurrent models.

Runtime comparison showing the parallelization benefits of minGRU and minLSTM.

On a T4 GPU, for sequences of length 4096, minGRU and minLSTM were over 1300x faster to train than traditional GRUs and LSTMs. Furthermore, because they require fewer gates and no hidden-to-hidden weight matrices, these versions use between 13% and 38% of the parameters of their traditional counterparts.

Conclusion

The success of minLSTM and minGRU suggests that the complexity added to deep learning architectures over the last decade may not always be necessary. By modernizing "old" architectures with parallelization, researchers have found that RNNs might be all we needed for efficient, high-performance sequence modeling. These minimal RNNs could serve as a new foundational building block, potentially replacing more complex State-Space Models (SSMs) or Transformers in resource-constrained environments.

Summary updated

BibTeX
@misc{feng2024were,
  author = {Leo Feng and Frederick Tung and Mohamed Osama Ahmed and Yoshua Bengio and Hossein Hajimirsadeghi},
  title = {{Were RNNs All We Needed?}},
  year = {2024},
  eprint = {2410.01201},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.01201},
}
Figure