Training Recurrent Neural Networks (RNNs) on long sequences has historically been bottlenecked by a massive memory footprint. To train an RNN using Backpropagation Through Time (BPTT), the system must cache every hidden state produced during the forward pass to compute gradients during the backward pass. For a sequence of 1,000 steps, this means storing 1,000 states. With high-dimensional models like LSTMs, this requirement quickly exceeds the VRAM of high-end GPUs.
Traditionally, researchers mitigated this by truncating backpropagation or using simple checkpointing heuristics (e.g., saving every $n$-th state and recomputing the rest). However, these heuristics are rarely optimal for a specific, fixed memory budget. This paper introduces a novel approach using dynamic programming to find the mathematically optimal strategy for balancing memory usage against computation time, allowing researchers to fit long sequences into limited GPU memory.
Dynamic Programming for Memory Management
The core innovation is treating memory management as an optimization problem solvable via Dynamic Programming (DP). The algorithm recursively divides the sequence to find the optimal execution policy. Given $t$ time steps and $m$ memory slots, the DP solver identifies an optimal "split point" $y$. It calculates the cost of reaching that point, storing the state, and then solving the two resulting sub-problems.
The authors propose three variations of this memorization strategy:
- BPTT-HSM (Hidden State Memorization): Stores only the hidden states. To obtain internal gradients, it performs an extra forward step from the saved hidden state.
- BPTT-ISM (Internal State Memorization): Stores the full internal state of the RNN core. This consumes more memory per slot but saves a forward computation during the backward pass.
- BPTT-MSM (Mixed State Memorization): A generalized version that decides whether to store a hidden state or an internal state based on which minimizes the total computational cost.
Because the memory budget is typically known in advance (e.g., a fixed 12GB of VRAM), the DP solver can pre-calculate the perfect execution policy before training even begins, ensuring a tight fit for any user-defined memory constraint.
Performance and Trade-offs
The paper formalizes the "Recomputation Tax": the ability to trade a marginal increase in computation time (re-running forward passes) for a massive reduction in memory footprint. Unlike previous checkpointing methods that relied on fixed intervals (like saving every $\sqrt{t}$ steps), this approach is provably optimal for any given memory budget and is architecture-agnostic, applying equally well to simple RNNs, LSTMs, or complex Differentiable Neural Computers.
Evaluations using synthetic benchmarks (an LSTM mapping 256 inputs to 256 outputs) and theoretical asymptotic bounds demonstrate massive savings. For a sequence length of 1,000, the algorithm reduces memory usage by 95% compared to standard BPTT. This dramatic reduction comes at a minimal cost, increasing training time by only 33% per iteration. In practical scenarios, this slight delay is a worthwhile trade-off to enable the training of models that would otherwise exceed hardware limits.
Limitations and Future Work
While highly effective, the approach has a few limitations:
- Chain-only Topology: The current DP formulation assumes the computation graph is a simple chain, typical for RNNs. It does not natively handle more complex, branching graphs like Transformers or ResNets without modification.
- DP Overhead: The DP solver requires a small pre-computation step before training begins.
- Fixed Cost Assumption: The model assumes the costs of forward and backward passes are constant multiples of each other. Hardware-specific optimizations (like cuDNN kernels) might slightly alter these ratios in practice.
Future work could extend this optimal checkpointing logic to more general computational graphs, potentially bringing similar memory efficiencies to non-recurrent architectures.
Summary updated