NeurIPS 2024 Read the paper →

Robust attention.
Plug and play.

ProTransformer swaps the attention layer of any pretrained Transformer for a robust estimator that adversarial tokens can't hijack. No retraining or fine-tuning. Works on text, vision, graphs and LLMs.

$ pip install protransformers
91.8% → 1.8%
Jailbreak success rate on Vicuna (GCG, transfer)
+19.5%
BERT accuracy under TextFooler
+46.3%
ViT accuracy under PGD at 4/255
0
Extra training steps
The problem

Attention is a weighted average, and averages break easily.

Each attention output is a weighted mean of value tokens. In statistics terms it's a weighted least-squares estimator, and least squares has a breakdown point of zero: one bad token can drag the output anywhere.

Adversarial attacks exploit exactly this. A few swapped words, an invisible pixel pattern, a gibberish jailbreak suffix or a handful of fake graph edges each inject a token that pulls the representation off course, layer after layer.

Vanilla attention = weighted least squares
ProAttention = robust estimator
Solved in K ≤ 3 Newton-IRLS steps

With ρ = ℓ₁, Huber or MCP, tokens far from the consensus get down-weighted automatically, so outliers stop steering the output.

Interactive

See it in action

Each dot is a value token in 2D with equal attention weight. Click the canvas to inject adversarial tokens and drag any dot to move it. The grey ✕ is vanilla attention, and the coloured ◆ is ProAttention, with its IRLS path. Each dot's size shows the weight ProAttention gives it.

clean token adversarial token ✕vanilla attention ◆ProAttention
Vanilla shift0.00
ProAttention shift0.00
Distance from the clean-only output
One layer, every modality

Robust across language, LLMs, vision and graphs

The same ProAttention module drops into BERT, LLaMA, ViT and GAT, using the original pretrained weights.

TextFooler vs. BERT on AG News

Accuracy under attack, AG News (paper, Table 1)
Adaptive attacks run directly against each model.
Jailbreak: GCG adversarial suffixes on Vicuna-7B
User‹harmful request from AdvBench› ‹optimized gibberish suffix›
VicunaSure, here is … jailbroken
Pro-VicunaI'm sorry, but I can't help with that. refused

Schematic of the GCG suffix-injection attack (Zou et al., 2023). The suffix is a nonsense token string optimized to flip the model into compliance. ProAttention treats those tokens as outliers. The numbers below are attack success rates from the paper (Table 21, Vicuna-7B, transfer GCG).

Prompt attack on T5 (SST-2, TextFooler on the prompt)
Accuracy vs. number of perturbed prompt words (paper, Table 17).
PGD on CIFAR-10 vision transformers (paper, Table 3)
Robust accuracy (%) vs. ℓ∞ budget. Drag the slider.
Why it works for images

ViT splits an image into 16×16 patches and attends over them. A PGD perturbation pushes a few patch embeddings far away from the rest, and vanilla attention averages them in. ProAttention sees those patches as outliers relative to the other patches and down-weights them in every layer.

Toy view: the red patches are perturbed. Hover over the grid to watch ProAttention down-weight them; vanilla attention keeps every weight uniform.

Adversarial edges vs. GAT
Toy illustration: the target node T aggregates its neighbours. Add adversarial edges to nodes from another class and watch which class each model predicts. GAT flips after 3 fake edges. Pro-GAT holds until the attacker's edges outnumber the true ones, which is where any robust estimator has to give in.
PGD topology attack on Cora-ML (paper, Table 4)
Accuracy (%) vs. fraction of perturbed edges, 5 splits.
Model zoo

Drop-in replacements for 🤗 Transformers

Load the original checkpoints, then switch ProAttention on with one call. With norm="L2" you get the vanilla model back, bit for bit.

TextPro-BERTBertForSequenceClassification
TextPro-RoBERTaRobertaForSequenceClassification
TextPro-ALBERTAlbertForSequenceClassification
TextPro-DistilBERTDistilBertForSequenceClassification
LLMPro-LLaMA · Pro-VicunaLlamaForCausalLM
LLMPro-T5T5ForConditionalGeneration
VisionPro-ViTViTForImageClassification
GraphPro-GATgraph_attack.GAT
Get started

Three lines to a robust model

  1. Install from PyPI with pip install protransformers.
  2. Load any supported checkpoint from protransformers instead of transformers.
  3. Switch on ProAttention with set_pro_attention. That's all.
Cost

BERT inference on AG News goes from 6.1 ms to 11.7 ms with K = 2. That's about 1–2× the backbone's time, and nothing extra at training time.

robust_bert.py
from protransformers import (
    AutoModelForSequenceClassification, set_pro_attention
)

model = AutoModelForSequenceClassification.from_pretrained(
    "textattack/bert-base-uncased-ag-news"
)

# Plug in ProAttention: no retraining, same weights
set_pro_attention(model, norm="MCP", gamma=4.0, L=3)

# LLMs: load with attn_implementation="eager"
# Vanilla again: set_pro_attention(model, norm="L2")
Research

ProTransformer: Robustify Transformers via Plug-and-Play Paradigm

Zhichao Hou1, Weizhi Gao1, Yuchen Shen2, Feiyi Wang3, Xiaorui Liu1

1North Carolina State University · 2Carnegie Mellon University · 3Oak Ridge National Laboratory

Advances in Neural Information Processing Systems (NeurIPS) 2024

citation.bib
@inproceedings{hou2024protransformer,
  title     = {ProTransformer: Robustify Transformers via
               Plug-and-Play Paradigm},
  author    = {Hou, Zhichao and Gao, Weizhi and Shen, Yuchen
               and Wang, Feiyi and Liu, Xiaorui},
  booktitle = {Advances in Neural Information
               Processing Systems},
  volume    = {37},
  pages     = {137557--137609},
  year      = {2024}
}