# DetectViT: Test-time Backdoor Detection for Vision Transformers via Inter-Head Attention Discrepancy

*Siquan Huang, Yijiang Li, Xingfu Yan, Ningzhi Gao, Leyu Shi, Ying Gao*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/151934) · [OpenReview](https://openreview.net/forum?id=WjAq71jgrz) · [Open on the map](../papers.html#p151934)

Category: [AI Safety, Security & Alignment](../pcat/16.md) › [Adversarial Attacks and Defenses](../pgroup/90.md) · Type: new method · Keywords: Vision Transformer backdoor detection, inter-head attention discrepancy, test-time detection, out-of-distribution calibration, multimodal model security

Areas: [Safety & Security](../areas/safety.md) › Adversarial Security › Out-of-Distribution Detection; [Evaluation & Benchmarks](../areas/evaluation.md) › Model Capability Diagnostics › Out-of-Distribution Detection

## Summary
DetectViT is a test-time backdoor detection method for Vision Transformers that leverages inter-head attention discrepancy patterns to identify backdoors without needing training data or model outputs.

## Explained to a 5-year-old
Computers use special glasses called Vision Transformers to look at pictures. Sometimes someone can hide a secret trick in those glasses that makes the computer see something wrong. The researchers noticed that when a trick is hidden, the way the computer pays attention to different parts of the picture gets weird. They created a way to check if the attention is weird, which tells us if the picture has a secret trick. This helps keep the computers safe so they don't make mistakes because of hidden tricks.

## Explained to a 5-year-old, longer
Computers can look at pictures using something called a Vision Transformer, which is like a set of eyes that focus on different parts. Sometimes people put a hidden secret, called a backdoor, into those eyes so the computer will see something wrong on purpose. The researchers found that when a backdoor is present, the way the eyes pay attention to the picture becomes strange. They noticed two kinds of strange attention: one where all eyes look at the same spot too much, and another where the eyes are very uneven in how they focus. They built a method that measures how consistent and how varied the attention is across the eyes. By comparing this measurement to a few safe pictures that have no backdoor, they can tell if a new picture has a hidden trick. This method does not need any extra training or the computer’s final answer, just the attention information already computed. It works on many different computer models and picture tasks, like recognizing objects or describing scenes. The method is fast and uses very little extra computer power.

## For a technical reader
DetectViT monitors the multi-head attention of Vision Transformers during inference, looking for abnormal spatial overlap and variance in attention concentration that indicate a backdoor. It computes two scores-inter-head consistency and inter-head entropy variance-and calibrates thresholds using a small out-of-distribution set. The method requires no training data, model outputs, or trigger knowledge, and it adds negligible overhead because it only uses existing attention weights.

## Problem
Backdoor attacks can be injected into third-party pretrained Vision Transformers, and existing test-time detection methods either rely on model predictions or embeddings, limiting their generality and adding computational cost.

## Method
The approach examines how backdoor triggers alter the multi-head attention mechanism, detecting two anomalous patterns-high inter-head spatial overlap and large variance in attention concentration-and computes an inter-head consistency score and an inter-head entropy variance score, calibrating thresholds with a small out-of-distribution set.

## Results
The approach achieves 100% true positive rate and 0.17% false positive rate on BadCLIP using as few as 64-128 OOD calibration samples, and it adds negligible computational overhead.

## Contributions
It identifies two attention hijacking patterns in ViTs, proposes a test-time detection method that needs no training data or model outputs, and demonstrates strong performance across multiple architectures and downstream tasks with minimal calibration data.

## Practical relevance
It enables safer deployment of pretrained Vision Transformers in real-world applications by detecting hidden backdoors without extra training or inference cost.

## Research questions this paper is counted under

- [How can we detect attention-manipulated inputs in vision-language models at test time?](../q/417.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/151934)
