TAPIOCA: Why Task- Aware Pruning Improves OOD model Capability

Krish Sharma, Omar Naim, Soumadeep Saha, Vinija Jain, Aman Chadha, Nicholas Asher

TL;DR

Task-aware layer pruning doesn't help models on data they already know well; instead, it acts as a targeted corrective mechanism for out-of-distribution (OOD) data. By removing specific layers that amplify geometric distortions in internal representations under distribution shift, pruning realigns OOD inputs with the model's learned task geometry, boosting performance without any retraining.

What Problem Does This Paper Address?

Recent work has revealed a counterintuitive phenomenon: dropping entire layers from Large Language Models (LLMs) at inference time can actually improve performance on specific tasks, even without any retraining. This method, known as Task-Aware Layer Elimination (TALE), challenges the traditional deep learning paradigm that deeper networks are inherently better.

However, why and when this happens has remained a mystery. This paper investigates the underlying mechanisms of task-aware pruning, answering a crucial question: What are these dropped layers actually doing, and why does deleting them help?

Figure 1: Weight-space-defined functions for different tasks (Ti, Tj), applied to data from different distributions (ID, OOD), characterize task-specific geometries; ID data for Ti give rise to a task- adapted geometry; OOD data give rise to a distorted geometry, which task-aware layer pruning can correct.

Methods

The authors investigate task-aware pruning using a two-pronged approach:

  1. Controlled Synthetic Environment: They train a 12-layer transformer from scratch on in-context linear regression tasks. This setup allows them to explicitly define and manipulate the boundary between in-distribution (ID) and out-of-distribution (OOD) data.
  2. Large Language Models: They validate their findings at scale using fine-tuned math and code expert models based on Llama 3.1 (8B) and GPT-OSS (120B).

To uncover the underlying mechanics, they analyze the internal representational geometry of the models, specifically tracking layer-wise hidden-state norms and pairwise token distances. They also fit local linear surrogates to individual layers to isolate their mathematical behavior and perform causal interventions—such as scaling down residual updates or inserting inverse surrogate matrices—to prove that geometric distortion directly drives performance degradation.

Datasets

  • Synthetic Regression Data: Linear functions sampled from uniform distributions ($U(-\sigma, \sigma)$), alongside structurally complex, non-smooth functions (Runge and Weierstrass functions) to test severe distribution shifts.
  • Math Domain: Models are fine-tuned on NuminaMath-CoT and evaluated on MATH500 (In-Distribution) and MMLU Math / BoolQ (Out-of-Distribution).
  • Code Domain: Models are fine-tuned on Code Alpaca and evaluated on MMLU High School CS and MMLU College CS as OOD benchmarks.

Key Insights and Ideas

  • Pruning Gains are OOD-Specific: Pruning provides zero benefit on in-distribution data. For ID data, every layer performs necessary refinements, and pruning hurts accuracy. It is only under distribution shift that certain layers become liabilities.
  • Distribution Shift Distorts Internal Geometry: When a model processes OOD data, its internal representations drift away from the clean, task-adapted geometry observed with ID data. This drift manifests as distorted pairwise token distances and inflated norms.
  • Layers as Distribution-Dependent Amplifiers: A layer's behavior is not fixed; it depends on the input. A layer that acts as a benign refinement for ID data can turn into a chaotic, high-gain, low-rank amplifier when fed OOD data, severely compounding geometric distortions as information flows deeper into the network.
  • Alignment, Not Just Suppression: Pruning does not simply act as a regularizer to suppress high activation norms. Depending on the direction of the distribution shift, pruning can contract or expand representation profiles to realign the OOD data with the model's expected task geometry.
Figure 3: Pruning realigns OOD representations toward the in-distribution geometry. Top: regression-task results for L2 median distance from the final token to prior tokens. (a) The model is trained on U(−1, 1) and tested on U(1, 2): OOD distances inflate to ∼385, and TALE contracts them toward the ID trajectory. (b) With train/test roles reversed, pruning expands OOD distances toward the ID baseline, showing that TALE matches the task-specific geometry rather than merely suppressing activations. Bottom: Llama 8B L2 distances from the final token to preceding tokens, using 200 MATH500 and 200 MMLU prompts. (c) Median and (d) average distances diverge between MMLU (OOD) and MATH500 (ID) after layer 14; removing layers {10, 21, 22, 24, 25} contracts the OOD trajectory toward the ID baseline and improves MMLU accuracy by +7.4 points. Figure 17 shows the same pattern with L1 distances.

Key Results

  • Synthetic Tasks: On $U(-2,2)$ OOD data, task-aware pruning successfully dropped the mean squared error (MSE) of the base model from 0.0405 to 0.0344.
  • LLM Math Specialists: For the Llama 3.1 8B math specialist, pruning yielded a +7.4 point absolute gain on MMLU Math (OOD) while leaving the 87.5% score on MATH500 (ID) completely untouched. For the massive GPT-OSS 120B model, pruning delivered an identical +7.0 point absolute gain on MMLU Math.
  • Causal Evidence: By gradually attenuating a harmful layer's residual contribution ($\alpha \to 0$) without removing it entirely, the authors observed a smooth, monotonic improvement in OOD accuracy. This directly proves that the magnitude of the layer's residual update causally impacts performance under distribution shift.

Limitations and Future Work

  • Operationalizing ID/OOD: Defining a clean split between ID and OOD for pretrained LLMs is difficult because their training data is massive and opaque. The authors use fine-tuning tasks as a proxy for the true in-distribution data.
  • Linear Approximations: The linear surrogate matrices used for causal analysis are local approximations and do not fully capture the complex, non-linear dynamics of transformer blocks.
  • Generality of Pruning Methods: The study focuses heavily on the TALE method. Further research is required to see if these geometric insights apply broadly to other structural and unstructured pruning techniques.

Summary updated

BibTeX
@inproceedings{sharma2026tapioca,
  author = {Krish Sharma and Omar Naim and Soumadeep Saha and Vinija Jain and Aman Chadha and Nicholas Asher},
  title = {{TAPIOCA: Why Task- Aware Pruning Improves OOD model Capability}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=jT0H1Gve0C},
}
Figure