Manuscript Offprint

arXiv:2610.20588

Your Transformer Is Secretly Elastic

Walter Simoncini, Dheeraj Varghese, Gertjan J. Burghouts, Cees G. M. Snoek

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Walter Simoncini1^{1}, Dheeraj Varghese1^{1}, Gertjan J. Burghouts2^{2}, Cees G.M. Snoek1^{1}

1^{1}University of Amsterdam 2^{2}TNO, Intelligent Imaging

Abstract. Scaling up transformers has produced models with broad capabilities, deployed across heterogeneous hardware and fluctuating workloads. Yet, model families offer only a few fixed sizes (e.g., S, B, L), forcing users to commit to a model based on hardware and latency constraints. This rigidity is often suboptimal under varying query loads. We introduce a retraining-free method that elastifies pre-trained transformers into a single model that adapts on-the-fly across a continuum of computational budgets. Our key contribution is a differentiable relaxation of the functional unit-ranking problem: unlike prior work, which optimizes a single importance weight per MLP block or attention head, we rank every individual MLP neuron and attention head jointly, on a common scale, by minimizing the model's loss under soft pruning across many sparsity targets, all at once. Across 27 vision and text transformer encoders ranging from 22M to 8B parameters, our method yields smooth degradation up to 60% sparsity and outperforms one-shot baselines under deep pruning. For example, pruning DINov3 ViT-H+/16 to 50% sparsity removes 427M parameters while reducing ImageNet-1k linear-probing accuracy by only 0.8%, without the need for weight correction or retraining. At 60% sparsity, a pruned AugReg ViT-B/16 model achieves up to 1.80× higher throughput and 1.26× lower single-query latency on an A100 GPU. Elastic models are produced in minutes, with construction time scaling sub-linearly with parameter count.

Correspondence: w.simoncini@uva.nl

Website

GitHub

Figure

Score Estimation

Score Parametrization

Soft Masking

Objective

Elastic Deployment

Figure

Figure 1 Differentiable soft pruning. Initial importance scores for MLP neurons and attention heads are transformed into learnable log-scores and median-centered by type, aligning their reference points without changing within-type rankings. At each optimization step, the joint ranking determines a threshold κb\kappa_b and soft mask MbM_b for each sparsity target b∈Bb \in \mathcal{B}. We run the same calibration batch through the frozen model under each mask, average losses across targets, and update only the log-scores. Mask gradients concentrate near each threshold, so multiple targets expose different regions of the ranking to useful gradients. The optimized ranking can then be hard-pruned to any inference budget without further optimization.

1 Introduction

Advances in pre-training recipes have enabled scaling frontier AI models to trillions of parameters, achieving impressive results in a variety of tasks. Their deployment spans applications with very different computational requirements, from offline processing to individual requests with strict latency limits. However, these varied requirements are poorly served by the few fixed model sizes typically released. Under fluctuating workloads, a model chosen for typical demand may be too expensive during a traffic peak, while a smaller model may sacrifice performance when more compute is available. Structured pruning (Li et al., 2017; Molchanov et al., 2019; Kwon et al., 2022; Khaki & Plataniotis, 2024; Berisha et al., 2025) can produce intermediate model sizes, but each pruned model is fixed to its target budget. Serving k budgets this way requires producing, storing, and switching between k pruned models as demand changes. For retrieval, separate indices may also be needed if embeddings from different pruned models are incompatible. Elastic inference instead lets a single model operate at different computational budgets chosen at inference time. Many existing methods require a specific nested architecture and training from scratch (Devvrit et al., 2024) or substantial fine-tuning (Valipour et al., 2023; Cai et al., 2024; Zhu et al., 2025; Taghibakhshi et al., 2025), which is costly for billion-parameter models. Choosing suitable data for fine-tuning can also be difficult when the model's pre-training distribution is unknown.

Simoncini et al. (2025) make pre-trained vision transformers elastic without retraining by optimizing importance scores across multiple computational budgets. Their evolutionary search adjusts one scaling factor per MLP block and attention head, allowing sparsity to be redistributed across the network while keeping the search tractable. However, this parameterization preserves the initial neuron ordering within each MLP block. Retaining an important neuron with a low initial score therefore requires retaining every higher-ranked neuron in that block. Building on their elastic formulation, we introduce differentiable soft pruning to recover more of this hidden elasticity by optimizing an individual importance score for every MLP neuron and attention head.

The key step is to replace hard truncation of the ranking with continuous masks, making the model's loss differentiable with respect to individual importance scores. Continuous masks are well established in differentiable pruning (Louizos et al., 2018; Xia et al., 2022, 2024), but each of these methods learns a single mask for a fixed sparsity target, typically also updating the model weights. We instead aim to improve the ranking using information from multiple sparsity targets while keeping the pre-trained weights frozen. Our hypothesis is that this joint optimization will yield better masks for any sparsity target. To this end, at each optimization step we determine a pruning cutoff in the current ranking for each selected sparsity target and soften the hard selection with a sigmoid mask. We average the resulting losses to jointly update an individual importance score for every MLP neuron and attention head. These updates reflect how units function together under pruning and allow neuron orderings to change within each block. Gradient descent makes this search tractable with any differentiable objective, including the model's original training loss. Because mask gradients are strongest near each cutoff, optimizing multiple budgets exposes different regions of the ranking to useful gradients. In our experiments, the jointly optimized ranking outperforms separate rankings optimized for individual targets. The resulting ranking also supports hard pruning at intermediate budgets without further optimization.

We evaluate 27 vision and text transformer encoders on image classification, semantic segmentation, text embedding, and retrieval. While the evaluated pruning baselines remain competitive under shallow pruning, our method improves the performance-compute trade-off across a range of sparsity levels, with the largest gains under deep pruning. For example, pruning DINOv3 ViT-H+/16 to 50% sparsity removes 427M parameters with only a 0.8% drop in ImageNet-1k linear probing accuracy, without weight correction or retraining. Furthermore, savings translate to speedups: AugReg ViT-B/16 reaches up to 1.80× dense throughput on an A100 at 60% sparsity.

References (80)