Published · v0.2.0

We built TransformerLens for language models. Nobody did the same for vision.

MultiModalLens is a Python library that lets you look inside vision-language models. It inspects attention, alignment, and causal circuits across 20+ Hugging Face VLM architectures, with faithfulness checks built in so your heatmaps don't lie.

input image ATTENTION HEATMAP a photo of cat . head body paw tail
Residual-augmented attention rollout for CLIP on a cat photo — "cat" token attends strongly to the body and paw patches.
$ pip install multimodallens

Why this exists

TransformerLens gave researchers a way to look inside language models. Cache every activation, trace every attention head, run causal interventions with a few lines of code. It changed how the field debugs transformers.

But when the field moved to vision-language models, that toolkit hit a wall.

"Vision-language models expose rich internals: attentions, hidden states, embeddings. But interpretability tooling remains architecture-specific and difficult to operationalize." MultiModalLens Research Paper

The problem is structural. Every VLM family processes images differently:

Each architecture requires different extraction logic, different attention surgery, different faithfulness testing. Researchers were building one-off scripts for every model they wanted to debug. There was no unified tool.

MultiModalLens fills that gap. One adapterized framework. One debugging interface. Faithfulness checks included.

The timeline

2019 — BertViz popularizes interactive attention visualization for language transformers.

2022 — TransformerLens ships mechanistic interpretability as a first-class API for LLMs.

2023 — Jain & Wallace demonstrate "Attention is not Explanation." The field realizes heatmaps alone are not enough. Faithfulness testing becomes critical.

2023 — CLIP, BLIP-2, and LLaVA drive massive VLM adoption. Still no unified interpretability tooling.

2024 — The VLM ecosystem explodes: Qwen2-VL, InternVL, PaliGemma, Pixtral, Idefics3, and dozens more.

2025 — MultiModalLens v0.1.0 ships with the adapterized framework and faithfulness diagnostics.

2026 — v0.2.0 adds mechanistic probes, direct logit attribution, path patching, interactive dashboards, and a PyPI release.

How it works

The core design principle: isolate model-specific logic behind a single interface. The UI, CLI, and evaluation layers never see model-specific code.

INPUT Image + Text Prompt IMG + TXT AutoProcessor CORE ENGINE HookedVLM LensPipeline ActivationCache ADAPTER LAYER CLIPAdapter BLIP2Adapter LlavaAdapter GenericVLMAdapter NORMALIZED OUTPUT AnalysisResult  ·  Attention Maps  ·  Alignment  ·  Score  ·  Faithfulness  ·  Logits

The adapterized architecture. All model-specific logic is isolated behind the ModelAdapter interface.

Four canonical adapters implement the same load(), prepare(), analyze(), and score() interface:

The hook infrastructure is built on PyTorch's register_forward_hook, the same approach TransformerLens uses. It auto-discovers transformer layer paths by scanning model.named_modules(), so you never have to manually specify layer indices.

The two APIs

MultiModalLens exposes two ways to interact with models:

HookedVLM is the TransformerLens-style programmatic API. Load a model, run it with cache or hooks, access activations by name:

quickstart.py
from multimodallens import HookedVLM
from PIL import Image

vlm = HookedVLM.from_pretrained("openai/clip-vit-base-patch32", device="auto")

# Run with full activation cache
result, cache = vlm.run_with_cache(Image.open("cat.jpg"), "a photo of a cat")

# Access any layer's activations
layer_5 = cache["vision_encoder.layers.5"]

# Zero-ablate a layer on the fly
patched = vlm.run_with_hooks(
    image=Image.open("cat.jpg"),
    prompt="a photo of a cat",
    fwd_hooks=[("vision_encoder.layers.5", lambda t: t * 0.0)]
)

LensPipeline is the stateful orchestration layer used by the Gradio UI and CLI. It caches adapters, manages model loading, and runs the full analysis suite:

CLI
# Launch the interactive web UI
multimodallens ui

# Single analysis with JSON output
multimodallens analyze --model openai/clip-vit-base-patch32 --image photo.jpg --prompt "a dog"

# Batch evaluation over a dataset
multimodallens eval --dataset dataset.jsonl --model openai/clip-vit-base-patch32

Supported models

23 family aliases map to 4 canonical adapters, plus automatic inference from Hugging Face's AutoConfig:

AdapterFamiliesExample CheckpointsStatus
CLIPAdapter clip, siglip, siglip2, altclip, xclip, chinese_clip openai/clip-vit-base-patch32, google/siglip-base-patch16-224 Validated
BLIP2Adapter blip2, instructblip Salesforce/blip2-opt-2.7b, Salesforce/instructblip-vicuna-7b Partial
LlavaAdapter llava, llava_next, qwen2_vl, qwen2_5_vl, mllama, internvl, minicpmv, smolvlm, kosmos2, florence2 llava-hf/llava-1.5-7b-hf, Qwen/Qwen2-VL-2B-Instruct, meta-llama/Llama-3.2-11B-Vision Partial
GenericVLMAdapter idefics2, idefics3, paligemma, pixtral HuggingFaceM4/idefics2-8b, google/paligemma-3b-mix-224 Experimental

New VLM families can be added without writing adapter code. Define the vision tower path, projector path, language model path, and image token string in a MultimodalConfig and the generic adapter handles the rest.

The methodology

MultiModalLens is not just a visualization dashboard. It combines three complementary evidence channels to avoid over-reliance on any single explanation primitive.

Structural signal: attention

$$A'_l = \text{normalize}(A_l + I)$$ $$R = A'_L \cdot A'_{L-1} \cdot \ldots \cdot A'_1$$

Residual-augmented rollout propagates attention through all layers while accounting for skip connections. The resulting matrix R captures each token's total attention to every image patch across the full network depth. Reshaped to a patch grid, it becomes the heatmap overlay.

Representation signal: alignment

$$S_{ij} = \cos(t_i, v_j)$$ $$\text{salience}_i = \max_j S_{ij}$$

Token-patch cosine similarity in shared latent space. The alignment matrix S shows which text tokens attend to which visual patches. Per-token saliency scores identify the most grounding-relevant words.

Causal signal: faithfulness

Attention is not explanation. MultiModalLens verifies that heatmaps actually reflect causal importance through:

Mechanistic probes

Beyond visualization, MultiModalLens includes TransformerLens-style mechanistic probes:

The diagnostic tuple

For every (image, prompt) pair, MultiModalLens produces A (attention maps), S (alignment matrix), g (global score), and F (faithfulness metrics). Four convergent signals instead of one heatmap.

The library also includes weight processing utilities (LayerNorm folding, writing weight centering, unembedding centering) for cleaner decomposition, and a FactoredMatrix class for efficient OV/QK circuit analysis via SVD.

Your first analysis in three steps

  1. Installpip install multimodallens
  2. Load and run — three lines of Python:
    quickstart.py
    from multimodallens import HookedVLM
    vlm = HookedVLM.from_pretrained("openai/clip-vit-base-patch32")
    result = vlm.analyze("cat.jpg", "a photo of a cat")
  3. Read the output — you get attention maps, alignment scores, a global score, and faithfulness metrics. Four signals, not one heatmap.

Five tutorial notebooks cover everything from quickstart to model comparison. The GitHub repo has the full source, and the PyPI package is ready to install. For the theory behind the methodology, read the methodology document or the research paper draft.