Skip a Layer or Loop It? Learning Program-of-Layers in LLMs

Ziyue Li, Yang Li, Tianyi Zhou

International Conference on Machine Learning 2026 · Oral

Overview

This talk introduces POLAR (Program-of-Layers), a novel inference-time framework that challenges the standard assumption that every input processed by a large language model must traverse the exact same sequence of layers from start to finish. Instead of enforcing a rigid, uniform computation graph where tokens pass sequentially through every layer from $1$ to $D$, the authors demonstrate that pre-trained, frozen LLMs inherently contain a vast library of hidden, valid computational paths. By treating individual layers or layer segments as callable functions, POLAR dynamically composes input-specific execution graphs—keeping, skipping, or repeating segments on the fly.

Watch on SlidesLive

Visual summary for Skip a Layer or Loop It? Learning Program-of-Layers in LLMs by Ziyue Li, Yang Li, Tianyi Zhou
Visual summary for Skip a Layer or Loop It? Learning Program-of-Layers in LLMs by Ziyue Li, Yang Li, Tianyi Zhou

Key moments

  1. 0:00 Introduction and motivation for program of layers in LLMs
  2. 2:00 Using Monte Carlo Tree Search as an analytic tool
  3. 4:00 Combining skipping and looping operations improves performance
  4. 6:00 Discovery of structured local patterns in layer programs
  5. 8:00 Results on accuracy, efficiency, and cross-domain generalization
  6. 10:00 Audience Q&A: Expert routing and residual connections

Skip a Layer or Loop It? Learning Program-of-Layers in LLMs

Speakers: Ziyue Li; Yang Li; Tianyi Zhou

Conference: ICML

YouTube: https://slideslive.com/39083652

Overview

This talk introduces POLAR (Program-of-Layers), a novel inference-time framework that challenges the standard assumption that every input processed by a large language model must traverse the exact same sequence of layers from start to finish. Instead of enforcing a rigid, uniform computation graph where tokens pass sequentially through every layer from $1$ to $D$, the authors demonstrate that pre-trained, frozen LLMs inherently contain a vast library of hidden, valid computational paths. By treating individual layers or layer segments as callable functions, POLAR dynamically composes input-specific execution graphs—keeping, skipping, or repeating segments on the fly.

The problem this work targets is rooted in the inefficiency of static compute allocation. Standard inference assumes all prompts require identical computational effort, forcing easy inputs to undergo over-computation while under-computing difficult inputs that would benefit from iterative, recurrent latent state refinement. POLAR resolves this tension by deploying a lightweight, learned predictor that maps inputs to custom layer programs. This approach achieves simultaneous gains in both task accuracy and inference efficiency without requiring any retraining or fine-tuning of the base LLM weights.

The implications for systems engineers and model deployers are substantial. By decoupling reasoning depth from static model architecture, inference engines can prune redundant calculations for simple queries and reallocate those FLOPs toward recursive latent refinement for complex tasks. Crucially, because the learned routing overhead is minimal, the dynamic scheduling of layers yields real-world latency reductions alongside accuracy improvements.

Background

▶ Watch: Introduction and motivation for program of layers in LLMs (0:00)

In standard transformer architectures, the forward pass follows a strict, linear pipeline: tokens flow sequentially through layer $1$, layer $2$, all the way to layer $D$. While structurally simple and stable, this rigidity introduces a fundamental mismatch with real-world workloads. Simple queries—such as factual lookups or basic syntax tasks—frequently contain sufficient information in early layers to generate the correct output token, rendering subsequent layers computationally wasteful. Conversely, complex reasoning tasks often require iterative refinement, yet they are artificially constrained by a single forward pass through a fixed depth.

Prior machine learning and systems research has attempted to address this through various forms of conditional execution, including dynamic layer skipping, token pruning, early exiting, and recurrent loop transformers. However, these existing approaches typically operate in isolation: skipping mechanisms reduce compute but strip away necessary reasoning depth for hard queries, while looping mechanisms increase compute indiscriminately across all inputs. Furthermore, many dynamic routing techniques require expensive retraining of the base model, introducing training instabilities and degrading out-of-distribution generalization.

The core challenge in the ML systems space is discovering alternative execution paths within a frozen model without incurring prohibitive search overhead during deployment. Pre-trained LLMs possess rich internal representations, but navigating the combinatorial explosion of potential layer sequences requires a principled diagnostic framework. The research team addresses this gap by separating the offline discovery of valid layer programs from the online prediction of input-specific programs.

Key Findings

▶ Watch: Combining skipping and looping operations improves performance (4:00)

The investigation into alternative layer programs yielded three primary empirical discoveries, validated across multiple models using the Dart Math benchmark suite (evaluated across five distinct mathematical reasoning difficulty levels, DM1 through DM5):

  • Complementarity of Skipping and Looping: Combining skipping and looping operations within the same execution program significantly outperforms strategies that rely on either operator exclusively. Loop-only strategies outperform skip-only strategies on difficult mathematical reasoning tasks because they provide necessary latent state refinements. However, the highest accuracy and efficiency gains across all models are achieved by programs that dynamically combine both: skipping layers to remove redundant compute for easy inputs, and looping layers to grant difficult inputs multiple passes through selective network segments.
  • Variable Depth vs. Task Difficulty: Full-depth inference is frequently neither the shortest valid computation path nor the most accurate. Analysis using Monte Carlo Tree Search (MCTS) revealed that for inputs where the base model is already correct, shorter programs (skipping segments) frequently yield the correct answer. Conversely, for inputs where the base model fails initially, a substantial fraction of discovered valid programs are deeper and recurrent, demonstrating that difficult queries benefit directly from extended compute allocation.
  • Local and Structured Program Space: Rather than exhibiting chaotic, arbitrary paths through the transformer stack, valid execution programs discovered by MCTS display strong local structure. Over 54% of discovered segments consist of a single layer, and more than two-thirds are restricted to lengths of one or two layers. Non-consecutive jumps (e.g., executing layer 1 followed immediately by layer 3) are extremely rare (under 3%). Furthermore, maximum recurrent depth for looped segments rarely exceeds $2$. This structural locality ensures that the search space for the predictor is compact and highly tractable.

Technical Deep Dive

▶ Watch: Discovery of structured local patterns in layer programs (6:00)

The architectural workflow of POLAR separates offline program discovery from online execution. During the offline phase, the system uses MCTS as an analytic diagnostic tool. Starting from the default root node representing the full $1$-to-$D$ pipeline, MCTS explores alternative program paths by mutating the sequence through keep, skip, and loop actions. These searches evaluate whether modified programs successfully solve the original task, thereby generating a corpus of valid supervision signals.

During the online phase, POLAR discards MCTS entirely, replacing the expensive search procedure with a lightweight program predictor. The base LLM remains entirely frozen. The predictor network operates via the following pipeline:

  1. Segmentation: The entire layer sequence of the base LLM is partitioned into predefined functional segments.
  2. Dynamic Routing: For a given input prompt, the lightweight predictor evaluates the input features and generates a discrete program specifying whether to keep, skip, or repeat each segment.
  3. Execution: The inference engine executes the model according to the generated program of layers.

Mathematically, if a model consists of segments $\{S_1, S_2, \dots, S_n\}$, a generated program $\mathcal{P}$ is an ordered sequence of function calls drawn from the library, allowing terms such as $\mathcal{P} = [S_1, S_2, S_2, S_3, \text{skip}(S_4), S_5]$.

The routing overhead introduced by the predictor is exceptionally small. Empirical benchmarks indicate that the predictor adds approximately $0.305$ milliseconds of overhead—representing roughly $0.8\%$ of total execution time in the evaluated settings—which equates to less than one-fourth of the computational cost required to execute a single standard transformer layer.

Experimental Setup & Results

▶ Watch: Results on accuracy, efficiency, and cross-domain generalization (8:00)

The evaluation of POLAR focuses on mathematical reasoning workloads using the Dart Math benchmark, categorized across five difficulty tiers (DM1 to DM5). The experiments assess multiple backbone LLMs to verify generalizability across model scales and architectures.

  • Accuracy and Efficiency Trade-offs: Evaluating pass-at-$K$ accuracy (where $K$ represents the number of predicted candidate programs generated for an input) demonstrates that increasing $K$ improves task performance. This confirms that maintaining diversity in generated programs allows the system to successfully identify valid execution paths for challenging prompts.
  • Layer Usage Distribution: Depth distribution analysis confirms that successful programs utilize significantly fewer unique layers than the standard static model pipeline. Efficiency gains do not stem from brute-force compute scaling, but rather from discovering alternative, shallower, yet highly effective execution paths.
  • Out-of-Distribution Generalization: When evaluated on out-of-distribution benchmarks in domains entirely unseen during training, the POLAR predictor consistently outperforms strong baseline models. This indicates that the predictor learns a robust, transferable policy for compute relocation rather than merely memorizing data-specific routing paths.
  • End-to-End Latency: Because POLAR bypasses multiple layers for the majority of routine inputs, the cumulative time saved by skipping segments far outweighs the $<1$ ms routing overhead of the predictor. Consequently, end-to-end inference latency decreases while task accuracy increases.

Practical Implications

▶ Watch: Audience Q&A: Expert routing and residual connections (10:00)

For infrastructure teams and model deployers, POLAR offers a compelling pathway to accelerate LLM inference without sacrificing model intelligence or requiring costly retraining pipelines.

  • Hardware and Serving Engine Integration: Deploying dynamic program-of-layers execution introduces new systems challenges, particularly regarding KV cache management. Because layers can be skipped or repeated recurrently, memory allocation policies for attention key-value caches must adapt to non-linear execution sequences. (As noted in the talk Q&A, managing KV cache allocation for skipped and looped layers in long-context generation remains an active area of ongoing research, with current implementations primarily validated on short-form answer generation).
  • Compute Budget Allocation: Rather than scaling model size uniformly, deployers can use POLAR to shift compute budgets dynamically based on prompt complexity. High-throughput serving systems can handle easy queries rapidly using shallow paths, reserving deeper, recurrent executions for difficult reasoning queries.
  • Model Training Paradigm: The finding that frozen pre-trained LLMs naturally contain functional sub-programs suggests that future base models could be explicitly pretrained with modular program-of-layers execution in mind, potentially yielding even more structured and efficient internal representations.

Key Takeaways

  • Pre-trained, frozen LLMs inherently contain multiple valid, hidden computational paths and layer programs beyond the standard fixed forward pass.
  • Layer skipping and recurrent looping are highly complementary operators; combining them yields superior performance by pruning redundant compute for easy inputs while allocating extra reasoning depth to hard inputs.
  • Valid execution programs display strong local structure (predominantly single- or two-layer segments with recurrence limited to a depth of $2$), making the search space compact.
  • Expensive offline program discovery via Monte Carlo Tree Search can be successfully distilled into a lightweight, online program predictor.
  • The POLAR predictor introduces negligible overhead ($<0.305$ ms, or $\approx 0.8\%$ of total runtime), enabling end-to-end latency reductions alongside improved accuracy and strong out-of-distribution generalization.

About the Speaker(s)

Authors: Ziyue Li, Yang Li, Tianyi Zhou.

Reviews

→ Top-rated talks at International Conference on Machine Learning 2026

All talks from International Conference on Machine Learning 2026