Papers
Topics
Authors
Recent
Search
2000 character limit reached

Were RNNs All We Needed?

Published 2 Oct 2024 in cs.LG and cs.AI | (2410.01201v3)

Abstract: The introduction of Transformers in 2017 reshaped the landscape of deep learning. Originally proposed for sequence modelling, Transformers have since achieved widespread success across various domains. However, the scalability limitations of Transformers - particularly with respect to sequence length - have sparked renewed interest in novel recurrent models that are parallelizable during training, offer comparable performance, and scale more effectively. In this work, we revisit sequence modelling from a historical perspective, focusing on Recurrent Neural Networks (RNNs), which dominated the field for two decades before the rise of Transformers. Specifically, we examine LSTMs (1997) and GRUs (2014). We demonstrate that by simplifying these models, we can derive minimal versions (minLSTMs and minGRUs) that (1) use fewer parameters than their traditional counterparts, (2) are fully parallelizable during training, and (3) achieve surprisingly competitive performance on a range of tasks, rivalling recent models including Transformers.

Citations (2)

Summary

  • The paper introduces minLSTM and minGRU, simplified RNNs that remove state dependencies in gates to allow full parallel training.
  • The methodology eliminates non-linear range restrictions and leverages parallel prefix scan, achieving up to 1361× faster training on long sequences.
  • Empirical results demonstrate competitive performance in language modeling, selective copying, and reinforcement learning despite an 88% increase in memory usage.

The paper simplifies traditional Recurrent Neural Networks (RNNs), specifically Long Short-Term Memory (LSTM) networks and Gated Recurrent Units (GRUs), to create minimal versions named minLSTMs and minGRUs that can be parallelized during training. These simplified models use fewer parameters than their traditional counterparts while achieving competitive performance on various sequence modeling tasks.

The paper begins by revisiting the landscape of sequence modeling, dominated by RNNs for two decades before the advent of Transformers. The inherent sequential nature of RNNs limited parallelization, making them computationally inefficient for long sequences. Transformers, introduced in 2017, enabled parallel training through self-attention but suffer from quadratic computational complexity with respect to sequence length. This limitation has sparked renewed interest in parallelizable recurrent models that scale more efficiently. Recent methods such as state-space models, linearized attention, and linear recurrent neural networks have shown promise in addressing these scalability issues.

The authors focus on LSTMs and GRUs as early examples of input-dependent recurrent models. By removing dependencies on previous states from the gates of these models, they enable parallel training. Further simplification leads to minLSTMs and minGRUs, which use fewer parameters, are fully parallelizable, and achieve competitive performance. Implementations of minGRU and minLSTM are provided in plain PyTorch.

The paper reviews traditional RNNs, highlighting their suitability for tasks involving sequential data but also noting the challenges related to vanishing and exploding gradients. The LSTM is defined by the following equations:

  • Γo=σ(Wioxt+Uhoht−1+bo)\Gamma_o = \sigma(W_{io}x_t + U_{ho}h_{t-1} + b_o)
    • Γo\Gamma_o is the output gate.
    • σ\sigma is the sigmoid function.
    • WioW_{io} is the weight matrix for the input xtx_t.
    • UhoU_{ho} is the weight matrix for the previous hidden state ht−1h_{t-1}.
    • bob_o is the bias vector for the output gate.
  • Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)
    • Γf\Gamma_f is the forget gate.
    • Γo\Gamma_o0 is the weight matrix for the input Γo\Gamma_o1.
    • Γo\Gamma_o2 is the weight matrix for the previous hidden state Γo\Gamma_o3.
    • Γo\Gamma_o4 is the bias vector for the forget gate.
  • Γo\Gamma_o5
    • Γo\Gamma_o6 is the input gate.
    • Γo\Gamma_o7 is the weight matrix for the input Γo\Gamma_o8.
    • Γo\Gamma_o9 is the weight matrix for the previous hidden state σ\sigma0.
    • σ\sigma1 is the bias vector for the input gate.
  • σ\sigma2
    • σ\sigma3 is the candidate cell state.
    • σ\sigma4 is the hyperbolic tangent function.
    • σ\sigma5 is the weight matrix for the input σ\sigma6.
    • σ\sigma7 is the weight matrix for the previous hidden state σ\sigma8.
    • σ\sigma9 is the bias vector for the candidate cell state.
  • WioW_{io}0
    • WioW_{io}1 is the cell state.
    • WioW_{io}2 denotes element-wise multiplication.
  • WioW_{io}3
    • WioW_{io}4 is the hidden state.

The GRU, a simplification of the LSTM, uses only two gates and a single state. The GRU equations are:

  • WioW_{io}5
    • WioW_{io}6 is the update gate.
    • WioW_{io}7 is the weight matrix for the input WioW_{io}8.
    • WioW_{io}9 is the weight matrix for the previous hidden state xtx_t0.
    • xtx_t1 is the bias vector for the update gate.
  • xtx_t2
    • xtx_t3 is the reset gate.
    • xtx_t4 is the weight matrix for the input xtx_t5.
    • xtx_t6 is the weight matrix for the previous hidden state xtx_t7.
    • xtx_t8 is the bias vector for the reset gate.
  • xtx_t9
    • UhoU_{ho}0 is the candidate hidden state.
    • UhoU_{ho}1 is the weight matrix for the input UhoU_{ho}2.
    • UhoU_{ho}3 is the weight matrix for the previous hidden state UhoU_{ho}4.
    • UhoU_{ho}5 is the bias vector for the candidate hidden state.
  • UhoU_{ho}6

The paper reviews the parallel prefix scan algorithm and its application in computing recurrence relations of the form UhoU_{ho}7.

The methodology section details the simplification of GRUs and LSTMs to enable training via parallel scan. For the minGRU, the first step involves dropping previous state dependencies from the gates. The GRU's hidden state recurrence is UhoU_{ho}8, where UhoU_{ho}9 and ht−1h_{t-1}0. To enable parallel scan, the dependencies on ht−1h_{t-1}1 are removed, simplifying the equations to ht−1h_{t-1}2 and ht−1h_{t-1}3.

The second step involves dropping the range restriction of candidate states. The hyperbolic tangent function, which restricts the range of hidden states, is removed, further simplifying the model. The resulting minGRU equations are ht−1h_{t-1}4, ht−1h_{t-1}5, and ht−1h_{t-1}6. The minGRU requires ht−1h_{t-1}7 parameters, compared to GRU's ht−1h_{t-1}8.

For the minLSTM, the first step involves dropping previous state dependencies from the gates. Similar to the minGRU, the hidden state dependencies are removed from the input, forget, and candidate cell state equations. The second step involves dropping the range restriction of candidate states, removing the hyperbolic tangent function. The third step involves simplifying the scaling of the output by dropping the output gate. The resulting minLSTM equations are ht−1h_{t-1}9, bob_o0, bob_o1, and bob_o2. The minLSTM requires bob_o3 parameters compared to LSTM's bob_o4.

The paper then presents empirical results, comparing the minimal versions with their traditional counterparts and modern sequence models. The runtime for sequence lengths of bob_o5 for minLSTM, minGRU, and Mamba were bob_o6, bob_o7, and bob_o8 milliseconds respectively. For a sequence with length bob_o9, the runtime were Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)0, Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)1, and Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)2 respectively. For a sequence length of Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)3, minGRUs and minLSTMs were Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)4 and Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)5 faster per training step than GRUs and LSTMs on a T4 GPU. The improvement is even more significant as sequences grow in length with minGRUs and minLSTMs being Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)6 and Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)7 faster for a sequence length of Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)8. The minimal variants use Γf=σ(Wifxt+Uhfht−1+bf)\Gamma_f = \sigma(W_{if}x_t + U_{hf}h_{t-1} + b_f)9 more memory compared to their traditional counterparts. minLSTM and minGRU are able to solve the Selective Copying task, achieving performance comparable to S6 and surpassing other modern baselines. In reinforcement learning tasks, minLSTM and minGRU outperform Decision S4 and achieve performance competitive with Decision Transformer, Aaren, and Mamba. In language modeling tasks, minGRU, minLSTM, Mamba, and Transformers achieved comparable test losses of Γf\Gamma_f0, Γf\Gamma_f1, Γf\Gamma_f2, and Γf\Gamma_f3 respectively.

The related work section provides an overview of recent efficient recurrent sequence models, categorized into deep state-space models, recurrent versions of attention, and parallelizable RNNs.

The paper concludes by highlighting the parallel training enabled by removing gate dependencies on previous states. The minimal versions offer fewer parameters, full parallelizability, and competitive performance. The authors suggest a reevaluation of simpler foundational models like LSTM and GRU.

The limitations section acknowledges the hardware constraints that impacted the scale of the experiments, including the use of older GPUs with limited memory. Gradient accumulation was used to accommodate memory limitations, reducing the effective batch size and slowing down training.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We found no open problems mentioned in this paper.

Tweets

Sign up for free to view the 54 tweets with 3372 likes about this paper.

HackerNews

  1. Were RNNs all we needed? (516 points, 260 comments) 

Reddit

  1. Were RNNs All We Needed? (4 points, 1 comment) 
  2. Were RNNs All We Needed? (3 points, 2 comments) 
  3. Were RNNs All We Needed? (2 points, 0 comments) 
  4. Were RNNs All We Needed? (1 point, 1 comment) 
  5. Were RNNs all we needed? (1 point, 0 comments)