PaCa-ViT: Learning Patch-to-Cluster Attention in Vision Transformers

Ryan Grainger, Thomas Paniagua, Xi Song, Naresh P. Cuntoor, Mun Wai Lee, Tianfu Wu

Introduction

Vision Transformers (ViTs) have set new benchmarks in computer vision, yet they face a fundamental scaling challenge: the quadratic complexity of self-attention. As image resolution increases, the cost of comparing every patch to every other patch grows exponentially, creating a "quadratic wall" for high-resolution tasks. Furthermore, raw image patches lack the inherent semantic meaning of word tokens in NLP. PaCa-ViT addresses these issues by introducing a Patch-to-Cluster (PaCa) attention mechanism that simplifies interactions and bridges the semantic gap.

The Patch-to-Cluster (PaCa) Mechanism

The core innovation of PaCa-ViT is the shift from patch-to-patch attention to patch-to-cluster attention. Instead of a dense $N \times N$ attention matrix, the model learns to group $N$ input patches into a small, fixed set of $M$ semantically meaningful clusters.

Comparison of attention mechanisms: Vanilla (quadratic), Reduced-Patch, and the proposed PaCa (linear) attention. PaCa enables direct visualization of cluster heatmaps for interpretability.

In this framework:

  • Queries remain patch-based ($N = H \times W$).
  • Keys and Values are compressed into $M$ clusters.
  • Complexity is reduced to $O(N \times M)$, which is linear with respect to the number of patches since $M$ is a small constant (e.g., $M=100$).

This approach not only improves efficiency but also provides "free" interpretability. By visualizing the cluster assignments, researchers can see exactly which parts of an image the model groups together—such as a dog's ear or a car's wheel—without requiring post-hoc explanation tools.

Architecture and Clustering Strategies

PaCa-ViT follows a hierarchical design similar to modern vision backbones, processing features through four stages of decreasing spatial resolution.

The hierarchical PaCa-ViT architecture and the detailed PaCa Block, featuring the clustering module and multi-head PaCa attention.

The model employs two primary clustering strategies:

  1. Onsite Clustering: A lightweight module (CNN or MLP) integrated directly into the Transformer block to generate cluster assignments from the input features.
  2. External Clustering: A parallel "teacher" network (often a lightweight CNN) that guides the clustering process, helping the Transformer capture the high-frequency spatial details that CNNs excel at.

Key Results and Performance

PaCa-ViT was evaluated across classification (ImageNet-1k), detection (MS-COCO), and segmentation (MIT-ADE20k) benchmarks, consistently outperforming established models like Swin Transformer and PVT.

  • ImageNet-1k Accuracy: PaCa-Small (22M parameters) achieved 83.1% top-1 accuracy, surpassing Swin-T (81.3%) and PVTv2-B2 (82.0%) with comparable or lower parameter counts.
  • Semantic Segmentation: On MIT-ADE20k, the PaCa-Base model reached an mIoU of 50.39, significantly higher than PVTv2-B5 (48.7).
  • Efficiency at Scale: Due to its linear complexity, PaCa-ViT maintains a much lower FLOP count than its predecessors as input resolution increases, making it ideal for dense prediction tasks.

Conclusion

PaCa-ViT represents a significant step forward in making Vision Transformers both efficient and interpretable. By treating image patches as members of semantic clusters rather than isolated tokens, the model achieves linear scaling and superior performance while offering a transparent look into its internal decision-making process. Future work may explore dynamic cluster filtering and self-supervised training to further refine these visual vocabularies.

Summary updated

BibTeX
@inproceedings{grainger2023paca,
  author = {Ryan Grainger and Thomas Paniagua and Xi Song and Naresh P. Cuntoor and Mun Wai Lee and Tianfu Wu},
  title = {{PaCa-ViT: Learning Patch-to-Cluster Attention in Vision Transformers}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
  doi = {10.1109/cvpr52729.2023.01781},
}
Figure