Manuscript Offprint

arXiv:2610.13858

LapMerge: Differentiable Exact-Budget Token Merging in Linear Time

Magdalena Trędowicz, Aleksandra Nowak, Tomasz Steifer, Łukasz Struski, Szymon Płotka, Jacek Tabor

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

Magdalena Trędowicz 1^{1} Aleksandra Nowak 1^{1} Tomasz Steifer 2,3^{2,3}

Łukasz Struski 1^{1} Szymon Plotka 1^{1} Jacek Tabor 1,3^{1,3}

1^{1}Jagiellonian University in Kraków

2^{2}Institute of Fundamental Technological Research, Polish Academy of Sciences

3^{3}Centre for Credible AI, Warsaw University of Technology

magdalena.tredowicz@doctoral.uj.edu.pl

LAPMERGE

Figure

Laplace kernels equal-area segments soft-merge to N

Figure 1: Overview of the standard LapMerge pipeline. Given an ordered sequence of M input tokens, LapMerge produces exactly N budget-exact, soft-merged output tokens. A learned scorer assigns each input token a mass, represented as a Laplace kernel. The summed density is scanned cumulatively and partitioned into N equal-mass segments, each of which is collapsed into a single output token. The resulting N tokens are then processed by a Transformer classifier. The right-most panel shows a real histopathology slide with the learned scorer weights overlaid on the tissue; opacity indicates the importance attributed to each patch. These same scores determine the token merging and can therefore be read as a learned routing-mass map: a direct view of where the model allocates its token budget.

ABSTRACT

Modern vision and language models process ever longer token sequences, and reducing them is the main lever on downstream cost. Token compression, however, faces a fundamental trade-off: selecting tokens discards information, while existing merging methods preserve it only through pairwise token-to-token matching or MN token-to-output interactions. We introduce LapMerge, a differentiable merging operator that resolves this trade-off for ordered sequences: a learned mass distribution partitions the sequence into exactly N equal-mass segments under a Laplace-kernel density, and prefix/suffix scans aggregate each segment, so both the forward and the backward pass run in O(M+N)\mathcal{O}(M + N) time. This combination – an exact output budget, end-to-end differentiability, and linear cost – is precisely what previous reducers trade off against one another. The budget can be changed without changing operator parameters, and the learned mass doubles as a token-level map of where the budget is allocated. Across vision and vision-language tasks, LapMerge matches or improves on strong token reducers while being up to two orders of magnitude faster at large sequence lengths; it is particularly effective when token order reflects spatial or temporal locality, and works both as a drop-in reduction module and as a trainable architectural component.

1 INTRODUCTION

Modern vision, language, and multimodal encoders increasingly operate on long token sequences. High-resolution images yield hundreds of patches, documents can contain thousands of tokens, and videos produce long spatiotemporal traces. While efficient attention implementations reduce the memory-access overhead of Transformer computation (Dao et al., 2022), they do not change the fundamental dependence of computation on sequence length. With a frozen encoder, the key efficiency problem is to reduce the number of tokens processed while preserving the information the downstream task needs.

A large body of work addresses this problem through token reduction. Existing approaches predominantly follow one of two strategies: pruning or merging. Pruning estimates the importance of individual tokens and retains only a subset, discarding the remainder (Rao et al., 2021; Liang et al., 2022; Fayyaz et al., 2022). This makes pruning computationally attractive: token scores are computed in a single pass, and selecting the top-N tokens requires no interaction between input and output tokens. Its limitation is information loss – pruning suits settings where the relevant evidence is concentrated in a small number of tokens, but can be brittle when the prediction depends on multiple weak cues distributed across the input.

Merging takes the opposite approach, aggregating tokens into a smaller set of representations rather than discarding them (Ryoo et al., 2021; Renggli et al., 2022; Bolya et al., 2023; Tran et al., 2024). This can preserve information distributed across many tokens. However, existing learned merging mechanisms generally require computing token-to-token or token-to-output interactions. For example, PatchMerger (Renggli et al., 2022) and TokenLearner (Ryoo et al., 2021) construct learned aggregation weights over the input tokens, while Perceiver (Jaegle et al., 2021)-style architectures use cross-attention between a fixed set of latent queries and the input sequence. Such global aggregation explicitly evaluates MN token-to-output interactions. When the output budget is a fixed fraction of the input, N=ρMN = \rho M, this becomes quadratic in M; even when N is fixed, the method still carries an MN interaction cost.

This raises a natural question: can token reduction preserve information from all M inputs while producing exactly N outputs without an explicit M×NM \times N interaction? We answer this by exploiting sequence order. LapMerge learns a scalar mass at each position and uses its cumulative distribution to partition the sequence into N contiguous, equal-mass regions, each producing one output token. This structured assignment replaces unrestricted token-to-output interactions with prefix/suffix scans, yielding O(M+N)\mathcal{O}(M + N) cost in both forward and backward passes for given masses and ordered positions; producing the masses with the soft top-k router used in our experiments (Struski et al., 2025) adds an O(Mlog⁡M)O(M \log M) sort, which Fast LapSum (Struski et al., 2026) makes expected-linear and pointwise sigmoid or softplus routing avoids entirely. The resulting outputs are convex combinations of their inputs, with a log-space implementation ensuring numerical stability at long sequence lengths. Figure 1 gives an overview of the method.

The key inductive bias is locality: nearby positions are preferentially aggregated together. This makes LapMerge particularly suited to spatially or temporally ordered tokens, while offering less advantage when sequence order is unrelated to semantic structure. In practice, the operator is implemented in native PyTorch, optionally accelerated with CUDA, and scales to sequences of more than 10710^{7} tokens. Our main contributions:

• We introduce LapMerge, a token merging operator that combines three properties prior reducers trade off against one another: an exact output budget of N tokens, end-to-end differentiability with closed-form gradients, and O(M+N)\mathcal{O}(M + N) cost in both passes.

• We show that LapMerge is versatile: a training-free drop-in that improves a released vision-language pipeline, and a trainable component in from-scratch and frozen-backbone models.

• Across vision and vision-language benchmarks, LapMerge matches or improves on strong token reducers at equal budgets while scaling beyond 10710^{7}-token inputs, up to two orders of magnitude faster than matched SDPA poolers.

References (55)

  • Flamingo: a visual language model for few-shot learning
  • Divprune: Diversity-based visual token pruning for large multimodal models
  • Qwen2.5-VL Technical Report
  • Longformer: The Long-Document Transformer
  • Fast differentiable sorting and ranking
  • Token merging: Your ViT but faster
  • An image is worth 1/2 tokens after layer 2: Plug-and-play inference acceleration for large vision-language models
  • Diffrate : Differentiable compression rate for efficient vision transformers
  • Nature medicine, 30(3):850–862, 2024b
  • Generating Long Sequences with Sparse Transformers
  • Rethinking attention with performers
  • Differentiable patch selection for image recognition
  • Funnel-transformer: Filtering out sequential redundancy for efficient language processing
  • Flashattention: Fast and memory-efficient exact attention with io-awareness
  • Adaptive token sampling for efficient vision transformers
  • Stochastic optimization of sorting networks via continuous relaxations
  • Mamba: Linear-Time Sequence Modeling with Selective State Spaces
  • Efficiently modeling long sequences with structured state spaces
  • Diffprune: differentiable information throttling for token pruning in vision-language models (opens arXiv in a new tab)
  • The model knows which tokens matter: Automatic token selection via noise gating
  • Removing speaker information from speech representation using variable-length soft pooling (opens arXiv in a new tab)
  • Attention-based deep multiple instance learning
  • Perceiver: General perception with iterative attention
  • Transformers are rnns: Fast autoregressive transformers with linear attention
  • Nature medicine, 25(7):1054–1056, 2019
  • 3D object representations for fine-grained categorization
  • Set transformer: A framework for attention-based permutation-invariant neural networks
  • Dual-stream multiple instance learning network for whole slide image classification with self-supervised contrastive learning
  • Evaluating object hallucination in large vision-language models
  • Not all patches are what you need: Expediting vision transformers via token reorganizations
  • Learning long-range spatial dependencies with horizontal gated recurrent units
  • Cancer cell, 33(4):721–735, 2018
  • Data-efficient and weakly supervised computational pathology on whole-slide images
  • Learning word vectors for sentiment analysis
  • Token pooling in vision transformers for image classification
  • ListOps: A diagnostic dataset for latent tree learning
  • SoftSort: A continuous relaxation for the argsort operator
  • The ACL anthology network corpus
  • DynamicViT: Efficient vision transformers with dynamic token sparsification
  • Learning to merge tokens in vision transformers (opens arXiv in a new tab)
  • Tokenlearner: Adaptive space-time tokenization for videos
  • LLaVA-PruMerge: Adaptive token reduction for efficient large multimodal models
  • TransMIL: Transformer based correlated multiple instance learning for whole slide image classification
  • LapSum: One method to differentiate them all: Ranking, sorting and top-k selection
  • Fast LapSum: Exact differentiable top-k at million scale (opens arXiv in a new tab)
  • Feature re-embedding: Towards foundation model-level performance in computational pathology
  • Long range arena: A benchmark for efficient transformers
  • Accelerating transformers with spectrum-preserving token merging
  • A large-scale multicentric study
  • important tokens
  • Visionzip: Longer is better but not necessary in vision language models
  • Mambamil: Enhancing long sequence modeling with sequence reordering in computational pathology
  • Dtfd-mil: Double-tier feature distillation multiple instance learning for histopathology whole slide image classification
  • Visionselector: End-to-end learnable visual token compression for efficient multimodal llms
  • highlighted tokens