Introduction
A persistent challenge in deep learning is the trade-off between the parallel efficiency of Transformers and the robust algorithmic reasoning of Recurrent Neural Networks (RNNs). While Transformers dominate natural language processing, they are notoriously poor at "length extrapolation"—the ability to perform a task on a long sequence after being trained only on shorter ones. For example, a Transformer trained on 40-bit strings for the PARITY task (determining if a bitstring has an even number of 1s) typically fails when tested on 500-bit strings. Conversely, RNNs handle such tasks with ease by maintaining a persistent state, but their sequential nature prevents the massive parallelization required for modern hardware.
This paper introduces RegularGPT, a novel Transformer variant that bridges this gap. By rethinking "working memory" as a structure built along the depth dimension rather than the temporal dimension, RegularGPT achieves perfect algorithmic extrapolation while maintaining the parallel efficiency of the Transformer architecture.
The RegularGPT Architecture
RegularGPT is built upon three architectural pillars designed to simulate the recursive reasoning of a parallel scan algorithm:
- Sliding-Dilated-Attention: Unlike standard self-attention where every token attends to every other token, RegularGPT groups tokens into non-overlapping chunks of size $C$. As information moves deeper into the network, the "dilation" increases. This creates a tree-like hierarchy where information from distant parts of the sequence is recursively merged in higher layers.
- Adaptive-Depth: To ensure that every token can eventually interact with every other token, the number of layers ($L$) is dynamically scaled based on the sequence length ($T$), specifically $L = \log_C T$. This ensures the model has sufficient "thinking time" to process longer inputs.
- Weight-Sharing: To generalize to sequences longer than those seen in training, RegularGPT shares weights across its layers. This effectively transforms the network's depth into a form of recurrence. When faced with a longer test sequence, the model simply executes more layers using the same learned parameters.
By combining these elements, RegularGPT implements a Parallel Scan—a classic computer science technique used to parallelize sequential operations. This allows the model to achieve a computational complexity of $O(T \log T)$, which is theoretically superior to the $O(T^2)$ complexity of standard Transformers for very long sequences.
Theoretical and Empirical Insights
Working Memory as a Routing Path
The core innovation of RegularGPT is the realization that working memory does not need to be a "state" passed through time, as in an RNN. Instead, it can be a "routing path" through the layers of a network. Through Principal Component Analysis (PCA) of the model's internal representations, the authors discovered that RegularGPT’s feed-forward layers actually cluster into distinct "states." In effect, the model learns to construct a Finite State Automaton (FSA) within its depth.
Algorithmic Superiority
The model was evaluated on several regular language benchmarks, including PARITY, Modular Arithmetic, and Tomita Grammars. While vanilla Transformers' accuracy on the PARITY task drops to approximately 50% (random guessing) when sequence lengths increase beyond the training window, RegularGPT maintains 100% accuracy. It significantly outperformed other extrapolation-friendly models, such as Transformer-XL, on complex logical tasks.
Natural Language Performance
Beyond logic puzzles, RegularGPT was tested on the OpenWebText2 dataset to evaluate its performance in real-world language modeling. The model was trained on sequences of 512 tokens and tested on lengths up to 8192. RegularGPT achieved perplexity scores comparable to or better than state-of-the-art methods like ALiBi and T5. Interestingly, the model "rediscovered" the importance of locality in natural language, confirming that local biases are essential for effective language extrapolation.
Limitations and Future Work
While RegularGPT represents a significant step forward, several areas for improvement remain:
- Chunk Size: The current model uses a fixed chunk size ($C$). Future iterations might benefit from a data-driven or flexible chunk size to better capture the diverse patterns in natural language.
- Capacity vs. Recurrence: Weight-sharing enables extrapolation but can limit the model's total expressive capacity. While the authors mitigated this by increasing layer width, finding the optimal balance between recurrence and depth is an ongoing research question.
- Scaling: The experiments were conducted on models up to 123M parameters. Validating the architecture at the billion-parameter scale is necessary to determine its viability for large-scale foundation models.
Conclusion
RegularGPT demonstrates that the divide between parallel processing and recursive reasoning is not absolute. By structuring working memory through depth and utilizing weight-sharing, it is possible to create models that are both computationally efficient and capable of perfect algorithmic extrapolation. This architecture offers a promising path toward more robust and scalable reasoning in both formal and natural languages.
Summary updated