Papers
Topics
Authors
Recent
Search
2000 character limit reached

Only Token Mean Loss in Vision Transformers

Updated 15 December 2025
  • Only Token Mean Loss (OTM) is a metric that quantifies the importance of individual tokens in Vision Transformers by measuring the change in cross-entropy loss when a token is masked.
  • It employs a supervised feature selection approach by generating pseudo-labels using a loss differential threshold (ρ) and training a dedicated MLP filter to prune less critical tokens.
  • Empirical results on DeiT models demonstrate that OTM filtering reduces compute (FLOPs and latency) while maintaining competitive accuracy.

The only token mean loss (OTM), also termed delta-loss (ΔL), is a metric quantifying the marginal influence of individual tokens on the loss function of a fixed-weights Vision Transformer (ViT) model. Specifically, OTM is used to assess the importance of patch tokens in visual input sequences by measuring the change in cross-entropy loss induced by masking each token in isolation, thus enabling principled data-driven token filtering prior to self-attention. This approach frames token selection as a supervised feature-selection problem and yields efficient, accurate filtered ViTs through a single token pruning stage before any attention computation (Wang et al., 2023).

1. Formal Definition of Only Token Mean Loss

Let X={x1,,xN}X=\{x_1,\dots,x_N\} be the set of NN patch tokens for an input image, with xiRdx_i\in\mathbb{R}^d, where dd is the token embedding dimension. Given a pretrained ViT backbone Transformer()\text{Transformer}(\cdot), compute the network output y^=Transformer(X)\hat{y}=\text{Transformer}(X) and let L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y) denote the loss on the original (unmasked) image-label pair (X,y)(X, y). For each token ii, generate a masked input Xi={x1,,xi1,0,xi+1,,xN}X_{-i}=\{x_1,\dots,x_{i-1}, 0, x_{i+1},\dots,x_N\}, i.e., with NN0 replaced by zero. The masked loss is NN1. The per-token delta-loss (OTM) is

NN2

A high positive NN3 indicates that masking NN4 significantly increases the loss, thus NN5 is important; near-zero or negative NN6 implies NN7 is expendable. The expected OTM across the data distribution NN8 is

NN9

computed in practice as the sample mean over the training set (Wang et al., 2023).

2. Token Labeling, Feature Construction, and Filter Architecture

OTM is leveraged for token selection using a two-stage pipeline:

a) Token Labeling: For every image in the training set, obtain xiRdx_i\in\mathbb{R}^d0 via a standard forward pass. For each token xiRdx_i\in\mathbb{R}^d1, mask it, recompute xiRdx_i\in\mathbb{R}^d2, and set a pseudo-label:

  • xiRdx_i\in\mathbb{R}^d3 if xiRdx_i\in\mathbb{R}^d4,
  • xiRdx_i\in\mathbb{R}^d5 otherwise, where the threshold xiRdx_i\in\mathbb{R}^d6 (typically xiRdx_i\in\mathbb{R}^d7) is selected via tuning on validation data.

b) Feature for Each Token: To distinguish tokens in visually similar regions, a global image feature xiRdx_i\in\mathbb{R}^d8 is computed. The input to the filter MLP is xiRdx_i\in\mathbb{R}^d9.

c) Token-Filter MLP: The MLP consists of three fully connected layers: dd0, with ReLU activations after the first two layers and a sigmoid activation for output. The final output dd1 is interpreted as the predicted probability of dd2 being important.

d) Loss to Train MLP: Binary cross-entropy loss is used:

dd3

with the ViT backbone weights held fixed during this phase.

3. Token Filtering Algorithm and Inference Workflow

The methodology is operationalized through two main algorithms (cf. paper pseudocode):

Algorithm Input Output
Token Labeling Pretrained Transformer, training set dd4, threshold dd5 Token pseudo-labels dd6
Filter Training Training tokens dd7, pseudo-labels dd8 MLP filter parameters dd9

Token Labeling: For each image, after a forward pass for Transformer()\text{Transformer}(\cdot)0, each token is masked, losses recomputed, and OTM thresholded to produce hard labels.

Filter Training: For each minibatch, global token features are pooled and concatenated to individual tokens, MLP predictions computed, and binary cross-entropy minimized until convergence.

Inference: At test time (and during fine-tuning), all input tokens are passed once through the trained MLP filter. Tokens with Transformer()\text{Transformer}(\cdot)1 below a cutoff are zeroed and dropped for all downstream computation. The filtering is performed once, prior to any self-attention, reducing the computational burden on subsequent layers from Transformer()\text{Transformer}(\cdot)2 to Transformer()\text{Transformer}(\cdot)3, where Transformer()\text{Transformer}(\cdot)4 is the number of retained tokens (Wang et al., 2023).

4. Theoretical Context: Feature Selection Perspective

OTM constitutes a direct, "wrapper"-style metric for token utility, analogous to marginal contribution, Shapley-value, or leave-one-out feature-importance in traditional feature selection. By construction, tokens whose masking yields negligible change in ViT loss are considered dispensable. Empirical analysis demonstrates that, for standard vision tasks (e.g., ImageNet1K), the majority of image tokens exhibit Transformer()\text{Transformer}(\cdot)5, with a small subset dominating the network’s decisional performance. This suggests efficacy in discarding most tokens without significant adverse effect on predictive accuracy (Wang et al., 2023).

5. Empirical Performance and Comparative Results

Key empirical results on ImageNet1K using DeiT-based backbones:

  • Backbone: DeiT-T (Transformer()\text{Transformer}(\cdot)6 top-1, Transformer()\text{Transformer}(\cdot)7 Gflops baseline)
    • Filtered (DL-ViT-T, Transformer()\text{Transformer}(\cdot)8): FLOPs reduced by Transformer()\text{Transformer}(\cdot)9 to y^=Transformer(X)\hat{y}=\text{Transformer}(X)0 G; throughput +y^=Transformer(X)\hat{y}=\text{Transformer}(X)1 to y^=Transformer(X)\hat{y}=\text{Transformer}(X)2 img/s; top-1 drops y^=Transformer(X)\hat{y}=\text{Transformer}(X)3 to y^=Transformer(X)\hat{y}=\text{Transformer}(X)4.
  • Backbone: DeiT-S (y^=Transformer(X)\hat{y}=\text{Transformer}(X)5 top-1, y^=Transformer(X)\hat{y}=\text{Transformer}(X)6 Gflops baseline)
    • Filtered (DL-ViT-S, y^=Transformer(X)\hat{y}=\text{Transformer}(X)7): FLOPs reduced by y^=Transformer(X)\hat{y}=\text{Transformer}(X)8 to y^=Transformer(X)\hat{y}=\text{Transformer}(X)9 G; throughput +L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)0 to L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)1 img/s; top-1 at L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)2 (–L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)3).

Comparison to Dynamic-ViT, A-ViT, and E-ViT indicates that DL-ViT offers the best trade-off of accuracy, FLOPs, and latency under comparable conditions.

Ablation studies underscore the necessity of the OTM-driven MLP filter: substituting the filter with a randomly initialized or random-drop mechanism yields a drastic accuracy loss (e.g., L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)4 top-1 with a random MLP versus L=CrossEntropy(y^,y)\mathcal{L}=\text{CrossEntropy}(\hat{y}, y)5 with OTM-filtered selection), demonstrating the centrality of faithful ΔL-based pseudo-labeling.

6. Significance and Practical Integration

The OTM metric facilitates lightweight, accurate token pruning in ViTs through a purely post-hoc, data- and backbone-driven labeling strategy applicable to pretrained models. The approach obviates the need for end-to-end retraining from scratch, and requires only a single filtering module pre-attention, providing substantial FLOPs and latency gains with minimal accuracy degradation. Empirical evidence confirms that the vast majority of tokens can be safely eliminated under this regime, with retained performance closely tracking the unpruned baseline (Wang et al., 2023). A plausible implication is that principled, loss-driven feature attribution may generalize to other transformer modalities beyond vision.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Only Token Mean Loss (OTM).