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

Siquan Huang, Yijiang Li, Xingfu Yan, Ningzhi Gao, Leyu Shi +1 more
11/18/2026
cs.CVcs.CR
transformer-attention

Official code: siquanhuang/DetectViT (1 star, Python, MIT, last commit 2026-05-06).

Abstract

Vision Transformers (ViTs) now underpin the visual encoders of most multimodal models, but this success comes at a cost: relying on third-party pretrained checkpoints leaves these systems open to backdoor attacks. Existing test-time detection methods rely on either the predicted label or intermediate embeddings, limiting their applicability across diverse tasks and incurring substantial computational overhead.

Show full abstract

In this work, we study how backdoor triggers affect the multi-head attention mechanism of ViTs and identify two distinct anomalous patterns: $\textit{complete attention hijacking}$, causing the attention to exhibit abnormally high inter-head spatial overlap, and $\textit{partial attention hijacking}$, causing an abnormally large variance in the concentration of the attention distribution. Motivated by these findings, we propose $\textbf{DetectViT}$, a test-time backdoor detection method that requires neither training data, model outputs, nor any prior knowledge of the trigger. DetectViT quantifies the two hijacking phenomena via an inter-head consistency score and an inter-head entropy variance score, with thresholds estimated from a small out-of-distribution (OOD) calibration set drawn from an arbitrary source. Across four representative attacks, diverse architectures (DeiT, CLIP, and LLaVA), and downstream tasks (image classification and captioning), DetectViT substantially outperforms all baselines with as few as 64--128 OOD calibration samples, achieving a true positive rate of $100\%$ and a false positive rate of $0.17\%$ on BadCLIP. Notably, it introduces negligible additional overhead by relying solely on attention weights already computed during inference. Code is available at: https://github.com/siquanhuang/DetectViT.

View on arXivView PDF

Code Implementations(1)

MIT

The source code of paper “DetectViT: Test-time Backdoor Detection for Vision Transformers via Inter-Head Attention Discrepancy”

10Python, ShellApr 29, 20266 months agoMIT

Similar Papers

Cite this paper

@article{huang2026detectvit,
  title  = {DetectViT: Test-time Backdoor Detection for Vision Transformers via Inter-Head Attention Discrepancy},
  author = {Siquan Huang and Yijiang Li and Xingfu Yan and Ningzhi Gao and Leyu Shi and Ying Gao},
  year   = {2026},
  eprint = {2611.23770},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2611.23770v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2611.23770.svg)](https://codeofpaper.com/paper/2611.23770)

Discussion