Dr.LLM: Dynamic Layer Routing in LLMs

Ahmed Heakl, Martin Gubri, Salman Khan, Sangdoo Yun, Seong Joon Oh

TL;DR

Dr.LLM is a retrofittable framework that equips frozen, pretrained Large Language Models (LLMs) with lightweight, per-layer routers that dynamically decide whether to skip, execute, or repeat a transformer block. By training these routers using offline Monte Carlo Tree Search (MCTS) as explicit supervision, Dr.LLM simultaneously improves model accuracy and reduces computational cost without altering the base model's weights.

What Problem Does This Paper Address?

Standard LLMs process every token through a fixed, static stack of transformer layers. This "one-size-fits-all" approach is highly inefficient: it wastes compute on simple queries (like basic grammar or factual retrieval) and provides insufficient processing depth for complex reasoning tasks (like multi-step math or logic).

While prior "adaptive-depth" methods have tried to solve this, they usually suffer from severe drawbacks:

  1. Accuracy Trade-offs: They often degrade model accuracy in exchange for speed.
  2. High Overhead: They require massive retraining of the base model or architectural modifications.
  3. Inference Bottlenecks: Some rely on expensive search algorithms during inference, making them impractical to deploy at scale.

Dr.LLM addresses these challenges by creating a lightweight, plug-and-play routing mechanism that can be added to any existing, frozen LLM.

Methods

Dr.LLM introduces a three-step approach to achieve budget-aware, dynamic layer routing:

  1. Lightweight Router Architecture: Each transformer block is paired with a tiny Multi-Layer Perceptron (MLP) router. Instead of making a decision per token (which disrupts key-value caching), the router looks at a sequence-level summary using windowed mean pooling over the hidden states. It then outputs logits for three possible actions: skip, execute, or repeat the current layer.
Overview of Dr.LLM layer-wise routing and router internals.
  1. Path Supervision via MCTS: To train these routers without modifying base weights, the authors use an offline, length-aware Monte Carlo Tree Search (MCTS). For a small set of training prompts, MCTS explores different layer configurations to find the shortest execution path that preserves or improves the model's correct answer.
Length-aware MCTS algorithm used to discover optimal layer execution paths.
  1. Robust Training Regime: Because the vast majority of layers should be executed normally, the training data is heavily imbalanced. The authors employ focal loss with class-rebalancing weights to force the routers to learn the rare but critical skip and repeat actions. During training, teacher forcing ensures stable optimization.

Datasets

  • Training / In-Domain Evaluation: The routers were trained on a compact dataset of only 4,000 MCTS-optimized paths derived from the ARC (AI2 Reasoning Challenge, focusing on logic) and DART-Math (Difficulty-Aware Rejection Tuning, focusing on mathematics) datasets.
  • Out-of-Domain Evaluation: To test generalization, the authors evaluated Dr.LLM on eight diverse benchmarks: MMLU, GSM8k, AIME24, TruthfulQA, SQuADv2, GPQA Diamond, PIQA, and AGIEval.

Key Insights and Ideas

  • Transformer Computation Phases: The learned routing policies reveal a highly structured, intuitive division of labor across LLM layers. As visualized in the paper's routing analysis, early layers are almost always executed to build stable representations; middle layers exhibit high redundancy and are frequently skipped; and late layers are often repeated to perform iterative refinement ("slow thinking") for difficult tasks.
  • State-Driven, Not Semantic-Driven: Through ablation studies (replacing hidden states with initial input embeddings), the authors proved that the routers genuinely learn from the internal, evolving state of the model rather than just memorizing shallow question patterns or keywords.
  • The Power of Consensus: A common worry with per-layer routing is that different sequences in a batch will want different paths, destroying batch processing efficiency. Crucially, the authors found an 80–89% decision consensus across different sequences. This high agreement allows sequences to be grouped into microbatches efficiently, actually increasing overall GPU throughput.
Throughput increases significantly as inter-prediction routing consensus approaches 100%.

Key Results

  • Simultaneous Accuracy and Efficiency Gains: On ARC and DART, Dr.LLM improved accuracy by up to +3.4%p while saving an average of 5 layers per example.
Figure 1: Dr.LLM improves ac- curacy while reducing computa- tion. Number of layers used per example vs. accuracy on ARC and DART, averaged on six models.
  • Wall-Clock Speedups: Dr.LLM achieved a 15.3% wall-time reduction on 1k-token generation runs, with the router computation adding less than 1% overhead.
  • Strong Out-of-Domain Generalization: When evaluated on completely unseen tasks (like MMLU and GSM8k), the router-equipped models maintained their efficiency gains with an average accuracy drop of only 0.85%p, significantly outperforming prior state-of-the-art routing methods by up to +7.7%p.

Limitations and Future Work

  • Offline Search Cost: Generating the initial training data via MCTS requires a substantial number of offline forward passes (~961k in this study). While this is a one-time cost, scaling the data generation to massive datasets could be resource-intensive.
  • Synchronization Constraints: Although mitigated by high consensus, the microbatching strategy still requires per-layer synchronization when a repeat action occurs, which could pose engineering challenges in highly distributed, multi-GPU production environments.
  • Action Space Bounds: The current implementation caps modifications at a single repeat per block and a maximum of two consecutive skips. Expanding this action space could unlock further optimization but would exponentially increase the MCTS search space.

Summary updated

BibTeX
@inproceedings{heakl2026dr,
  author = {Ahmed Heakl and Martin Gubri and Salman Khan and Sangdoo Yun and Seong Joon Oh},
  title = {{Dr.LLM: Dynamic Layer Routing in LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=3ow7tq0O3l},
}
Figure