Dynamic Token Pruning in Plain Vision Transformers for Semantic Segmentation

Quan Tang, Bowen Zhang, Jiajun Liu, Fagui Liu, Yifan Liu

Introduction

Vision Transformers (ViTs) have established themselves as a dominant architecture in computer vision, particularly for high-level tasks. However, their computational demands remain a significant barrier to deployment. The quadratic complexity of the self-attention mechanism relative to the number of input tokens (image patches) makes ViTs especially resource-intensive for dense prediction tasks like semantic segmentation. While various pruning methods have been proposed for image classification, these often fail in segmentation contexts where every pixel requires a label. This paper introduces Dynamic Token Pruning (DToP), a novel approach that reduces computational costs by 20% to 35% while maintaining, and in some cases improving, segmentation accuracy.

The Challenge of Dense Prediction

In standard image classification, "uninformative" tokens—such as those representing a uniform background—can be discarded early in the network to save computation. Semantic segmentation, however, is a dense prediction task. Because the model must assign a semantic label to every single pixel, simply discarding tokens is not an option. Previous attempts to address this involved complex token reconstruction or clustering techniques, which often introduced significant computational overhead, offsetting the gains from pruning. The authors of DToP propose a more intuitive solution: identify "easy" regions of an image and finalize their predictions early, allowing the model to concentrate its remaining resources on "hard" regions, such as complex object boundaries.

Methodology: Dynamic Token Pruning (DToP)

DToP treats the segmentation process as a multi-stage "early exit" strategy, utilizing the following core components:

1. Stage-based Architecture

The researchers divide a standard ViT backbone into several discrete stages. This structure leverages auxiliary heads—components typically used only during training to improve gradient flow—to perform intermediate predictions during inference.

2. Difficulty Grading and Early Exit

At the conclusion of each stage, an auxiliary head predicts the class for every token. If the confidence score for a specific token exceeds a predefined threshold ($p_0$), the token is classified as "easy." Its prediction is finalized at that stage, and the token is "pruned" or halted, meaning it is excluded from all subsequent computational layers.

3. Context Preservation: The $k$-token Rule

A critical risk in pruning is the loss of global context. If all tokens representing a "sky" background are pruned in an early layer, the remaining tokens (e.g., a "tree") lose their spatial and semantic relationship to the sky, which can degrade the accuracy of deeper layers. To mitigate this, DToP implements a $k$-token rule: the model always retains the $k$ highest-confidence tokens for every detected category. These tokens act as representative anchors, ensuring the model maintains a global map of the scene for the remaining "hard" tokens.

4. Query Matching Auxiliary Block

To ensure the early-exit decisions are both accurate and efficient, the authors utilize a modified Attention-to-Mask (ATM) module. This lightweight auxiliary head is capable of grading token difficulty effectively without adding substantial overhead to the pipeline.

Experimental Results

The researchers evaluated DToP across three major semantic segmentation benchmarks: ADE20K (150 categories), COCO-Stuff-10K (171 categories), and Pascal Context (59 categories).

Efficiency and Accuracy

The results indicate that DToP provides a significant efficiency boost without the typical accuracy trade-offs:

  • Computational Gains: The method reduces GFLOPs by an average of 20% to 35%.
  • Performance Benchmarks: On the ADE20K dataset using a ViT-Base backbone, DToP achieved a 49.8% mIoU, slightly outperforming the baseline (49.7%) despite the reduced computation.
  • Scalability: The benefits scale to larger models. When applied to a ViT-Large (SegViT) backbone, DToP reduced GFLOPs from 617G to 412.8G with a negligible accuracy drop of only 0.5%.

Qualitative Analysis

Visualizations of the pruning process confirm that the model behaves as intended. It quickly identifies and exits the interiors of large, uniform objects (the "easy" parts) and focuses its computational budget on high-frequency details and object boundaries (the "hard" parts).

Conclusion and Future Work

DToP demonstrates that a coarse-to-fine processing strategy, mimicking human perception, can significantly optimize Vision Transformers for dense tasks. By recycling auxiliary heads as "gatekeepers," the method achieves a more efficient distribution of cognitive effort across an image.

However, a primary limitation remains: Hardware Optimization. While DToP reduces theoretical GFLOPs, current GPU software (such as CUDA) is optimized for fixed-size batch processing. Dynamic workloads, where each image in a batch has a different number of active tokens, do not yet see the full "wall-clock" speedup that the GFLOP reduction suggests. Future research will likely focus on bridging this gap between theoretical efficiency and real-world hardware performance.

Summary updated

BibTeX
@inproceedings{tang2023dynamic,
  author = {Quan Tang and Bowen Zhang and Jiajun Liu and Fagui Liu and Yifan Liu},
  title = {{Dynamic Token Pruning in Plain Vision Transformers for Semantic Segmentation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
}
Figure