Visual Attention Exploration in Vision-Based Mamba Models

Junpeng Wang, Chin-Chia Michael Yeh, Uday Singh Saini, Mahashweta DasarXiv 2025

TL;DR

This paper introduces a visual analytics tool to demystify the "attention" mechanisms within vision-based Mamba models, which offer linear complexity compared to the quadratic cost of Transformers. The researchers reveal that the specific sequence in which a model scans image patches fundamentally dictates its attention patterns, and they demonstrate that these patterns evolve from simple spatial correlations in early layers to complex, content-driven features in later stages.

What Problem Does This Paper Address?

While State Space Models (SSMs) like Mamba have gained traction for their efficiency, their behavior in vision tasks remains a "black box." Unlike Vision Transformers (ViT), which use global self-attention to let every patch "see" every other patch simultaneously, Mamba models process image patches sequentially.

To handle 2D images, Mamba flattens them into 1D sequences. This creates a significant challenge: the model’s ability to understand spatial relationships is heavily dependent on the order of that sequence. Researchers lacked tools to visualize how these patches interact across different blocks and stages, leaving two major questions unanswered:

  1. Are attention patterns consistent across different blocks within the same stage?
  2. How does the spatial distribution of attention change as data moves deeper into the network?

Methods

The authors developed a visual analytics tool featuring two primary components:

  • Scatterplot View: Uses dimensionality reduction (PCA, t-SNE, or UMAP) to project high-dimensional attention matrices into 2D space. This allows researchers to see if different blocks or patches cluster together, indicating similar attention behaviors.
  • Patch View: A spatial grid representing the original image. When a user selects a cluster in the scatterplot or a specific patch in the grid, the tool highlights corresponding spatial relationships and attention strengths.
Figure 1: Our visual exploration tool contains two visualization components. The Scatterplot view on the left shows the dimensionality reduction results. The Patch view on the right shows the patch layout and highlights the patches of interest.

The study specifically analyzes VMamba, which uses a "four-way cross-scan" to preserve spatial locality by scanning the image in four different directions (top-down, bottom-up, left-right, right-left).

Figure 2: The four-way cross-scan in VMamba [10].

Datasets

The models analyzed were trained on the ImageNet dataset (approximately 1.28 million training images). For the visual analysis and pattern exploration, the authors used a subset of 1,000 test images to generate aggregated, content-agnostic attention profiles.

Key Insights and Ideas

  • Scan Order is Destiny: The most striking finding is that a patch primarily attends to its "preceding" patches in the scan sequence. Because Mamba is inherently sequential (like an RNN), the "history" it carries determines what it focuses on.
  • Complementary Teamwork: Blocks within the same stage do not replicate each other. Instead, they exhibit significantly different, often complementary attention patterns. This diversity allows the model to selectively focus on different regions of an image across the stage.
  • The Spatial-to-Semantic Hierarchy: The model follows a clear evolutionary path. In early stages (Stage 0 and 1), attention is highly local and spatially correlated—patches look at their immediate neighbors. By Stage 3, these patterns break down into more diverse, content-dependent clusters, mirroring how CNNs and Transformers move from edge detection to object recognition.
  • Scan Flexibility: The researchers tested alternative scan orders—Diagonal, Morton (Z-order), and Spiral. They found that the model is surprisingly robust; as long as the scan covers the image effectively, the model adapts its attention to follow that specific path without losing significant accuracy.
Visualization of how attention patterns evolve and cluster across the four stages of the VMamba model.

Key Results

  • Performance Parity: VMamba models trained with new scan orders (Diagonal, Morton, Spiral) achieved accuracy levels (≥82.6% on ImageNet) comparable to the original cross-scan implementation.
  • Visual Confirmation of Locality: The tool successfully identified that the Morton (Z-order) scan preserves local spatial clusters better than simpler scans, which was reflected in the tighter clustering of attention patterns in the Scatterplot view.
  • Inter-Block Diversity: As shown in Figure 4, blocks within the same stage form distinct, isolated clusters in the projection space, proving that each block learns a unique way of processing the sequence.
Dimensionality reduction results showing distinct attention clusters for different blocks within the same stage.

Limitations and Future Work

The authors acknowledge that their current analysis focuses on content-agnostic patterns by averaging attention over 1,000 images. While this reveals the "architectural bias" of the model, it doesn't show how the model reacts to specific objects in a single image (e.g., attending to a dog's ears vs. the background).

Future work aims to:

  1. Integrate views for content-relevant attention patterns to diagnose model behavior on specific, problematic images.
  2. Scale the tool to handle even more complex Mamba variants with deeper architectures and more intricate scanning strategies.

Summary updated

BibTeX
@misc{wang2025visual,
  author = {Junpeng Wang and Chin-Chia Michael Yeh and Uday Singh Saini and Mahashweta Das},
  title = {{Visual Attention Exploration in Vision-Based Mamba Models}},
  year = {2025},
  eprint = {2502.20764},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.20764},
}
Figure