Abstract
Modern Transformer-based Large Language Models (LLMs) are characterized by significant overparameterization, which leads to substantial computational and memory overhead during training. While post-hoc methods like pruning and Parameter-Efficient Fine-Tuning (PEFT) address these inefficiencies after training, they do not mitigate the wastefulness of the initial training phase. This paper introduces Dynamic Layer Tying, a novel framework that utilizes Reinforcement Learning (RL) to dynamically determine weight-sharing patterns between Transformer layers during the training process. By allowing an RL agent to optimize the model architecture on the fly, this method reduces trainable parameters by up to 90% and peak memory consumption by over 60%, while frequently improving model performance through the regularization effects of weight sharing.
Introduction
The standard pipeline for developing state-of-the-art language models—training a massive architecture and subsequently shrinking it—is computationally expensive and memory-intensive. Research into model redundancy suggests that many layers in deep Transformers perform similar operations, yet traditional training treats every layer as an independent set of parameters. Existing solutions often rely on static, human-designed sharing patterns or post-training interventions.
Dynamic Layer Tying addresses the question: Can a model learn which layers are redundant while it is being trained from scratch? By treating the layer-sharing configuration as a sequential decision-making problem, the proposed method allows the architecture to evolve in response to the learning signal, leading to emergent efficiency.
Methodology
The Dynamic Layer Tying framework consists of two primary components: a Transformer network ($\mathcal{T}$) and a "driver" RL network ($Q$).
The RL Agent and Action Space
Every few hundred training iterations, the RL agent evaluates the current state of the Transformer and selects an action for each layer $i$. The agent has two primary choices:
- Independent Training: Layer $i$ maintains its own unique set of weights.
- Weight Tying: Layer $i$ copies the weights from a preceding layer $j < i$. Once tied, these layers share all future weight updates.
Transductive Sharing and Stability
The tying mechanism is transductive: if layer 10 is tied to layer 5, and layer 5 is already tied to layer 0, then layers 10, 5, and 0 all share the same parameter set. To ensure training stability despite these structural shifts, the model begins training with only the first layer active and gradually "unties" or replicates layers as directed by the RL agent.
Reward Function
The RL agent is optimized using standard Q-learning. Its reward is based on the negative perplexity of the Transformer on a validation batch. By maximizing this reward, the agent learns to identify sharing patterns that minimize loss while maintaining a compact parameter footprint.
Experimental Results
The method was evaluated across diverse benchmarks, including WikiText-103, the 1-Billion Words dataset, and GLUE, using GPT-2, BERT, and Vision Transformer (ViT) architectures.
Performance and Parameter Reduction
In large-scale language modeling, the dynamic approach significantly outperformed full-parameter baselines. On the 1-Billion Words dataset, a dynamically tied GPT-2 achieved a perplexity of 72.35 using only 203M trainable parameters. In contrast, the baseline GPT-2 (1.6B parameters) achieved a higher perplexity of 88.35. For BERT, the dynamic method enabled convergence on the same dataset (perplexity 215.50) where the standard baseline failed to converge entirely.
Computer Vision
The approach also generalized to the Vision Transformer (ViT) on CIFAR-10. The RL agent reduced the number of independent layers from 32 down to just 7, maintaining 99.5% of the baseline accuracy while drastically reducing the model's footprint.
Memory Efficiency
By sharing weights and gradients, the peak memory consumption during training was reduced by approximately 65%. For a 48-layer GPT-2, memory usage dropped from ~12.5 GB to ~4.5 GB, potentially allowing for the training of much larger models on consumer-grade hardware.
Discussion
The "Layer Zero" Phenomenon
A key insight from the RL agent's behavior is the frequent tying of multiple layers back to the initial layer (Layer 0). This suggests that the initial transformation of embeddings serves as a "universal" operation that remains highly effective throughout the network's depth. This global alignment likely contributes to the surprising stability of the model even as the RL agent shifts the architecture during training.
Emergent Regularization
The fact that tied models often outperform their full-parameter counterparts suggests that dynamic weight sharing acts as a powerful form of regularization. By forcing different stages of the network to share representations, the model is discouraged from over-fitting to specific noise in the training data, leading to better generalization.
Conclusion and Future Work
Dynamic Layer Tying demonstrates that RL can effectively design parameter-efficient architectures during the training process, offering a path toward more sustainable AI development. While the current implementation focuses on training from scratch, future research could explore applying this method to the fine-tuning of pre-trained models (e.g., in conjunction with LoRA) or utilizing more complex search strategies like Monte Carlo Tree Search (MCTS) to further optimize the sharing logic.
Summary updated