Skip to content

About

[ICLR 2025 Spotlight] Robustness Reprogramming for Representation Learning: make a trained network robust to adversarial attacks without changing its parameters.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Repository files navigation

Robustness Reprogramming for Representation Learning

ICLR 2025 Spotlight

Zhichao Hou1 · MohamadAli Torkamani2 · Hamid Krim1 · Xiaorui Liu1

1North Carolina State University 2Amazon Web Services

Project Page arXiv Paper

Project page: a live white-box attack where the original model is fooled and the reprogrammed model, with the same weights, stays correct
▶ 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.

News

  • 2025 Accepted to ICLR 2025 as a Spotlight ⭐
  • 2024-10 Preprint released on arXiv.

Highlights

LPM vs. NRPM

  • 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,

$$ z^{(k+1)} = D\cdot\frac{\sum_d w_d^{(k)} a_d x_d}{\sum_d w_d^{(k)}},\qquad w_d^{(k)} = \frac{1}{|a_d x_d - z^{(k)}/D|}. $$

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.

Three robustness reprogramming paradigms

Paradigm What is trained Cost Result
1 nothing; one fixed $\lambda$ for all layers zero good robustness, plug-and-play
2 only the layer-wise ${\lambda_l}$ slight strong robustness
3 ${\lambda_l}$ and the weights, for a few epochs acceptable best robustness and clean accuracy

Interactive demos

The project page is built around live demos computed from this repository.

One neuron, two estimators. An attacker controls 3 of 10 inputs. LPM weighs every edge equally and is dragged away. NRPM thins the corrupted edges and stays near the clean output.

LPM vs NRPM neuron under attack
Three paradigms, replayed. This is a real fine-tuning run from the released MLP (scripts/export_paradigms.py). Paradigm 2 learns λ ≈ [0.5, 0.0, 0.0] with frozen weights. Paradigm 3 also nudges the weights by about 5%.

Three paradigms fine-tuning replay

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:8000

Installation

git 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 CUDA

MNIST and CIFAR-10 are downloaded automatically to ./data on first use.

Quick start: reprogram your own model

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 lambdas

With lmbd=1.0 the reprogrammed model reproduces the original outputs exactly. Robust convolutions use the same estimator over unfolded patches, see models/conv2d.py.

Reproducing the paper

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

MLPs on MNIST (Table 1, Table 2)

# 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).

Convolutions on MNIST (Figure 3, Figure 5)

python mnist_lenet.py --lmbd 0.3            # lambda in [0, 1]; 1.0 recovers the vanilla LeNet

ResNets on CIFAR-10 (Table 4, Table 5)

python 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)

Rebuilding the project page demos

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)

Main results

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.

Repository structure

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

Citation

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}
}

Acknowledgements

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.

About

[ICLR 2025 Spotlight] Robustness Reprogramming for Representation Learning: make a trained network robust to adversarial attacks without changing its parameters.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages