Zhichao Hou1 · MohamadAli Torkamani2 · Hamid Krim1 · Xiaorui Liu1
1North Carolina State University 2Amazon Web Services
▶ Open the interactive project page: launch attacks on a neuron, replay the three paradigms, and attack the released model in your browser.
Important
ICLR 2025 Spotlight. Can a well-trained model be reprogrammed to become robust to adversarial perturbations without changing its parameters? We show that every linear feature transformation is a least-squares estimator. Replacing it with a robust least-absolute-deviation estimator, Nonlinear Robust Pattern Matching (NRPM), recovers substantial robustness from the very same weights. Three reprogramming paradigms then trade a little compute for more robustness.
- 2025 Accepted to ICLR 2025 as a Spotlight ⭐
- 2024-10 Preprint released on arXiv.
-
A new view of representation learning. The linear pattern matching inside MLPs, convolutions and attention,
$z=\sum_d a_d x_d$ , is the closed-form solution of$\min_z \sum_d (z/D - a_d x_d)^2$ . The quadratic loss explains why it is so sensitive to perturbation. -
NRPM, a robust drop-in replacement. NRPM solves
$\min_z \sum_d |z/D - a_d x_d|$ with unrolled Newton-IRLS iterations,
The iterations come with a loss-descent guarantee (Lemma 3.1), and the influence of any single input is bounded (Theorem 3.2).
-
Robustness reprogramming in three paradigms. Each layer outputs
$\lambda, z_{\text{LPM}} + (1-\lambda), z_{\text{NRPM}}$ and reuses the pre-trained weights.
| Paradigm | What is trained | Cost | Result |
|---|---|---|---|
| 1 | nothing; one fixed |
zero | good robustness, plug-and-play |
| 2 | only the layer-wise |
slight | strong robustness |
| 3 |
|
acceptable | best robustness and clean accuracy |
The project page is built around live demos computed from this repository.
The page also includes an influence-function explorer and an attack lab. The lab has 12 MNIST digits, each attacked white-box against both models, with a live view of the hidden-layer embeddings. To view the page locally:
cd docs && python -m http.server 8000 # then open http://localhost:8000git clone https://github.com/chris-hzc/Robustness-Reprogramming.git
cd Robustness-Reprogramming
conda create -n reprogram python=3.10 -y && conda activate reprogram
pip install -r requirements.txt # pick the torch build that matches your CUDAMNIST and CIFAR-10 are downloaded automatically to ./data on first use.
nrpm.py is a self-contained reference implementation (about 100 lines, no dependency on the rest of the repo).
It swaps every nn.Linear for an NRPMLinear that shares the original weights:
import nrpm
model = MyTrainedModel()
model.load_state_dict(torch.load("weights.pth"))
nrpm.reprogram(model, paradigm=1, lmbd=0.7, K=1) # Paradigm 1: zero-cost, nothing is trained
nrpm.set_lambda(model, 0.5) # sweep lambda (1.0 = original model, 0.0 = pure NRPM)
nrpm.reprogram(model, paradigm=2) # Paradigm 2: only layer-wise lambdas require grad
nrpm.reprogram(model, paradigm=3) # Paradigm 3: lambdas and weights require grad
print(nrpm.lambdas(model)) # inspect learned lambdasWith lmbd=1.0 the reprogrammed model reproduces the original outputs exactly. Robust convolutions use the same estimator over unfolded patches, see models/conv2d.py.
Pre-trained backbones are included in checkpoints/:
| Checkpoint | Backbone | Dataset | Used by |
|---|---|---|---|
mlp3_mnist_model.pth |
MLP 784–256–64–10 | MNIST | mnist_mlp.py |
lenet_mnist_model.pth |
LeNet | MNIST | mnist_lenet.py |
tinyresnet18_cifar10_model.t7 |
ResNet-18 (width / 8) | CIFAR-10 | train_cifar10_resnet.py, test_cifar10_resnet.py |
# Paradigm 1: plug in NRPM with a fixed lambda and evaluate FGSM at eps = 0 ... 0.3
python mnist_mlp.py --lmbd 0.7
# Other attacks: --attack L2 | L1 | L0
python mnist_mlp.py --lmbd 0.7 --attack L2
# Paradigms 2 & 3: adversarial fine-tuning from the pre-trained MLP
python mnist_mlp.py --train_mode 1 --adv_train True --epsilon 0.3 --paradigm 1 # tune lambda only (paper: Paradigm 2)
python mnist_mlp.py --train_mode 1 --adv_train True --epsilon 0.3 --paradigm 2 # tune everything (paper: Paradigm 3)Logs are written to mnist_result/. Note that inside the scripts, --paradigm 1/2 refers to the fine-tuning mode, which corresponds to Paradigms 2/3 in the paper. Paradigm 1 is the default evaluation mode (--train_mode 0).
python mnist_lenet.py --lmbd 0.3 # lambda in [0, 1]; 1.0 recovers the vanilla LeNetpython train_cifar10_resnet.py --resnet 18 --paradigm 1 # adversarial fine-tuning of lambda only
python train_cifar10_resnet.py --resnet 18 --paradigm 2 # adversarial fine-tuning of all parameters
python test_cifar10_resnet.py --resnet 18 --attack PGD # PGD | FGSM | PGDL2 | AA (AutoAttack)python scripts/export_demo.py --data ./data # attack lab + hero: docs/static/data/mnist_demo.json
python scripts/export_paradigms.py --data ./data # paradigm replay: docs/static/data/paradigms.json (~5 min on one GPU)Adversarial robustness on CIFAR-10 with ResNet-18 (Table 5, accuracy %):
| Method | Natural | PGD | FGSM | C&W | AA | DeepFool | SPSA | Avg |
|---|---|---|---|---|---|---|---|---|
| PGD-AT | 80.90 | 44.35 | 58.41 | 46.72 | 42.14 | 14.81 | 62.92 | 44.89 |
| TRADES-2.0 | 82.80 | 48.32 | 51.67 | 40.65 | 36.40 | 25.91 | 64.29 | 44.54 |
| MART | 79.03 | 48.90 | 60.86 | 45.92 | 43.88 | 25.63 | 56.55 | 46.96 |
| AWP | 81.20 | 51.60 | 55.30 | 48.00 | 46.90 | 26.25 | 61.37 | 48.24 |
| DYNAT | 82.34 | 52.25 | 65.96 | 52.19 | 45.10 | 28.72 | 67.97 | 52.03 |
| Paradigm 3 (ours) | 80.43 | 57.23 | 70.23 | 64.07 | 52.60 | 36.50 | 67.56 | 58.03 |
3-layer MLP on MNIST under FGSM (Table 1, accuracy %):
| Method | Natural | ε = 0.1 | ε = 0.2 | ε = 0.3 |
|---|---|---|---|---|
| Normal-train | 90.8 | 2.6 | 0.0 | 0.0 |
| Adv-train | 76.4 | 57.6 | 35.0 | 9.1 |
| Paradigm 1 (λ = 0.7) | 89.7 | 43.5 | 16.9 | 9.2 |
| Paradigm 2 | 81.5 | 61.2 | 33.7 | 20.1 |
| Paradigm 3 | 86.1 | 75.8 | 58.7 | 39.8 |
See the paper for LeNet, ResNet-10/34, MLP-Mixer, SVHN, ImageNet10, certified robustness and ablations.
Robustness-Reprogramming/
├── nrpm.py # minimal plug-in NRPM layer + reprogram() helper
├── mnist_mlp.py # MLP experiments (Tables 1–2)
├── mnist_lenet.py # LeNet experiments (Figures 3–5)
├── train_cifar10_resnet.py # ResNet fine-tuning (Paradigms 2–3)
├── test_cifar10_resnet.py # ResNet evaluation: PGD / FGSM / C&W / AutoAttack
├── models/ # robust convolution (conv2d.py), ResNet variants with NRPM layers
├── autoattack/ # AutoAttack (Croce & Hein, 2020), vendored
├── checkpoints/ # pre-trained backbones
├── scripts/ # export_demo.py, export_paradigms.py: data for the web demos
├── docs/ # project page (GitHub Pages, served from /docs)
└── assets/ # README figures and demo GIFs
If you find this work useful, please cite our ICLR 2025 Spotlight paper:
@inproceedings{hou2025robustness,
title = {Robustness Reprogramming for Representation Learning},
author = {Hou, Zhichao and Torkamani, MohamadAli and Krim, Hamid and Liu, Xiaorui},
booktitle = {The Thirteenth International Conference on Learning Representations (ICLR)},
year = {2025},
note = {Spotlight},
url = {https://arxiv.org/abs/2410.04577}
}Zhichao Hou and Xiaorui Liu are supported by the NSF National AI Research Resource Pilot Award, an Amazon Research Award, the NCSU Data Science Academy Seed Grant Award, and the NCSU Faculty Research and Professional Development Award.
The AutoAttack implementation in autoattack/ is from fra31/auto-attack.



