TL;DR
Dynamic Nested Depth (DND) is a post-training method that boosts Large Language Model (LLM) performance by identifying "difficult" tokens and giving them an extra "review" pass through existing transformer layers. By selectively allocating more computation to critical tokens while ignoring trivial ones, DND achieves significant accuracy gains (up to 2.6%) across dense and Mixture-of-Experts (MoE) models with a negligible increase in parameters and only ~6% extra computational overhead.
The Problem: Equal Time for Unequal Tokens
The standard "scaling law" for LLMs assumes that more parameters and more data inevitably lead to better performance. However, this brute-force scaling is computationally expensive. A key inefficiency in current architectures is that they treat every token equally. Whether processing a simple comma or a complex logical transition, the model spends the exact same amount of "thinking time" (layers) on it.
Previous attempts at "adaptive computation," such as token pruning or early exiting, usually focus on reducing work for easy tokens. DND takes the opposite approach: it identifies the most critical, high-uncertainty tokens and provides them with additional "nested" processing depth to ensure they are properly understood before the model moves on.
How Dynamic Nested Depth Works
DND introduces a "plug-and-play" architecture that can be integrated into off-the-shelf models during a supervised fine-tuning (SFT) phase.
- The Router: A simple linear layer is added at the end of specific transformer blocks. It assigns a "preference score" to each token to determine its difficulty.
- Token-Choice Routing: Unlike "expert-choice" routing (which picks the top $k$ tokens in a sequence), DND uses token-choice routing. Each token is evaluated independently against a threshold. This is crucial for auto-regressive models to prevent "information leakage" from future tokens during inference.
- Nested Processing: Selected tokens are packed into a compact sequence and fed back through the same transformer layer (sharing weights). This "review" pass allows the model to refine the hidden representations of difficult tokens without adding new transformer blocks.
- Normalized Fusion: The outputs of the "vanilla" pass and the "nested" pass are merged using a gating mechanism. This ensures the model retains its original pre-trained knowledge while incorporating the newly refined insights.
- Stability Strategies: To keep the selection process stable during training, the authors use two novel tricks:
- Router Controlling Loss: A dual-objective loss that encourages scores to spread out (distinguishability) while keeping them away from the "saturation" regions of the sigmoid function to avoid vanishing gradients.
- Threshold Control: An adaptive scheme that uses a buffer and Exponential Moving Average (EMA) to dynamically adjust the selection threshold, ensuring the model consistently reviews the target percentage of tokens (e.g., 20%).
Key Insights and Performance Gains
The authors evaluated DND across a massive suite of benchmarks covering General Knowledge, Mathematics, STEM, and Coding tasks. The models were fine-tuned using a high-quality SFT dataset of 1–2 million instances.
Why it works: * Entropy as a Signal: There is a strong correlation between "logit entropy" (the model's uncertainty about the next word) and selection frequency. DND naturally picks tokens where the model is "hesitating." * The "Review" Effect: After the nested pass, the logit entropy for selected tokens significantly decreases, proving that the extra computation helps the model become more certain. * Hierarchical Processing: Earlier layers tend to select essential nouns and entities, while deeper layers focus on abstract or syntactically critical components like mathematical operators and key verbs.
Results: * Dense Models: Boosted Qwen3-1.7B by 1.88%, Llama3.2-1B by 2.61%, and Gemma3-1B by 2.50% on average across all tasks. * MoE Models: Improved the Qwen3-30B-A3B by 0.87% on average, with particularly strong gains in coding (+2.05% on BFCL). * Reasoning Gains: On the difficult GPQA-Diamond benchmark, the performance boost was roughly 5% across the dense models. * Efficiency: Because the nested pass shares weights with the original layer, the parameter increase is nearly zero. The total FLOP increase is only ~6.27% for a 20% selection ratio, allowing models to maintain 91.6% to 93.1% of their original inference throughput.
Limitations and Future Work
Currently, DND is applied during the SFT stage, and its impact during initial pre-training or continual pre-training remains to be explored. Furthermore, while successful on auto-regressive LLMs, its applicability to other architectures (like diffusion models) is unknown. Finally, DND is currently applied to intermediate layers (excluding the first and last four); more sophisticated methods for choosing which layers should be "nested" could further optimize the performance-to-compute ratio.
Summary updated