• Stars
    star
    1,273
  • Rank 35,717 (Top 0.8 %)
  • Language
    Jupyter Notebook
  • License
    GNU Lesser Genera...
  • Created over 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Toolbox for Adversarial Robustness Research

advertorch logo

Build Status

advertorch text is a Python toolbox for adversarial robustness research. The primary functionalities are implemented in PyTorch. Specifically, AdverTorch contains modules for generating adversarial perturbations and defending against adversarial examples, also scripts for adversarial training.

Latest version (v0.2)

Installation

Installing AdverTorch itself

We developed AdverTorch under Python 3.6 and PyTorch 1.0.0 & 0.4.1. To install AdverTorch, simply run

pip install advertorch

or clone the repo and run

python setup.py install

To install the package in "editable" mode:

pip install -e .

Setting up the testing environments

Some attacks are tested against implementations in Foolbox or CleverHans to ensure correctness. Currently, they are tested under the following versions of related libraries.

conda install -c anaconda tensorflow-gpu==1.11.0
pip install git+https://github.com/tensorflow/cleverhans.git@336b9f4ed95dccc7f0d12d338c2038c53786ab70
pip install Keras==2.2.2
pip install foolbox==1.3.2

Examples

# prepare your pytorch model as "model"
# prepare a batch of data and label as "cln_data" and "true_label"
# ...

from advertorch.attacks import LinfPGDAttack

adversary = LinfPGDAttack(
    model, loss_fn=nn.CrossEntropyLoss(reduction="sum"), eps=0.3,
    nb_iter=40, eps_iter=0.01, rand_init=True, clip_min=0.0, clip_max=1.0,
    targeted=False)

adv_untargeted = adversary.perturb(cln_data, true_label)

target = torch.ones_like(true_label) * 3
adversary.targeted = True
adv_targeted = adversary.perturb(cln_data, target)

For runnable examples see advertorch_examples/tutorial_attack_defense_bpda_mnist.ipynb for how to attack and defend; see advertorch_examples/tutorial_train_mnist.py for how to adversarially train a robust model on MNIST.

Documentation

The documentation webpage is on readthedocs https://advertorch.readthedocs.io.

Coming Soon

AdverTorch is still under active development. We will add the following features/items down the road:

  • more examples
  • support for other machine learning frameworks, e.g. TensorFlow
  • more attacks, defenses and other related functionalities
  • support for other Python versions and future PyTorch versions
  • contributing guidelines
  • ...

Known issues

FastFeatureAttack and JacobianSaliencyMapAttack do not pass the tests against the version of CleverHans used. (They use to pass tests on a previous version of CleverHans.) This issue is being investigated. In the file test_attacks_on_cleverhans.py, they are marked as "skipped" in pytest tests.

License

This project is licensed under the LGPL. The terms and conditions can be found in the LICENSE and LICENSE.GPL files.

Citation

If you use AdverTorch in your research, we kindly ask that you cite the following technical report:

@article{ding2019advertorch,
  title={{AdverTorch} v0.1: An Adversarial Robustness Toolbox based on PyTorch},
  author={Ding, Gavin Weiguang and Wang, Luyu and Jin, Xiaomeng},
  journal={arXiv preprint arXiv:1902.07623},
  year={2019}
}

Contributors

  • Gavin Weiguang Ding
  • Luyu Wang
  • Xiaomeng Jin
  • Laurent Meunier
  • Alexandre Araujo
  • Jérôme Rony
  • Ben Feinstein
  • Francesco Croce
  • Taro Kiritani

More Repositories

1

noise_flow

Noise Flow: Noise Modeling with Conditional Normalizing Flows
Python
141
star
2

private-data-generation

A toolbox for differentially private data generation
Python
118
star
3

scaleformer

Python
102
star
4

SLAPS-GNN

PyTorch code of "SLAPS: Self-Supervision Improves Structure Learning for Graph Neural Networks"
Python
82
star
5

de-simple

Diachronic Embedding for Temporal Knowledge Graph Completion
Python
80
star
6

continuous-time-flow-process

PyTorch code of "Modeling Continuous Stochastic Processes with Dynamic Normalizing Flows" (NeurIPS 2020)
Python
41
star
7

ranksim-imbalanced-regression

[ICML 2022] RankSim: Ranking Similarity Regularization for Deep Imbalanced Regression
Python
40
star
8

lite_tracer

a light weight experiment reproducibility toolset
Python
39
star
9

pommerman-baseline

Code for the paper "Skynet: A Top Deep RL Agent in the Inaugural Pommerman Team Competition"
Python
37
star
10

mma_training

Code for the paper "MMA Training: Direct Input Space Margin Maximization through Adversarial Training"
Python
35
star
11

TSC-Disc-Proto

Discriminative Prototypes learned by Dynamic Time Warping (DTW) for Time Series Classification (TSC)
Python
30
star
12

MMoEEx-MTL

PyTorch Implementation of the Multi-gate Mixture-of-Experts with Exclusivity (MMoEEx)
Python
30
star
13

mtmfrl

Multi Type Mean Field Reinforcement Learning
Python
27
star
14

CP-VAE

On Variational Learning of Controllable Representations for Text without Supervision https://arxiv.org/abs/1905.11975
Roff
27
star
15

cross_domain_coherence

A Cross-Domain Transferable Neural Coherence Model https://arxiv.org/abs/1905.11912
Python
24
star
16

bre-gan

Code for ICLR2018 paper: Improving GAN Training via Binarized Representation Entropy (BRE) Regularization - Y. Cao · W Ding · Y.C. Lui · R. Huang
Jupyter Notebook
20
star
17

DT-Fixup

Optimizing Deeper Transformers on Small Datasets https://arxiv.org/abs/2012.15355
Python
15
star
18

rate_distortion

Evaluating Lossy Compression Rates of Deep Generative Models
Python
14
star
19

PROVIDE

PROVIDE: A Probabilistic Framework for Unsupervised Video Decomposition (UAI 2021)
Python
13
star
20

continuous-latent-process-flows

Code, data, and pre-trained models for the paper "Continuous Latent Process Flows" (NeurIPS 2021)
Python
12
star
21

code-gen-TAE

Code generation from natural language with less prior and more monolingual data
Python
12
star
22

OOS-KGE

PyTorch code of “Out-of-Sample Representation Learning for Multi-Relational Graphs” (EMNLP 2020)
Python
11
star
23

ssl-for-timeseries

Self Supervised Learning for Time Series Using Similarity Distillation
Python
10
star
24

efficient-vit-training

PyTorch code of "Training a Vision Transformer from scratch in less than 24 hours with 1 GPU" (HiTY workshop at Neurips 2022)
Python
10
star
25

latent-bottlenecked-anp

Python
6
star
26

nflow-cdf-approximations

Official implementation of "Efficient CDF Approximations for Normalizing Flows"
Python
6
star
27

keyphrase-generation

PyTorch code of “Diverse Keyphrase Generation with Neural Unlikelihood Training” (COLING 2020)
Python
5
star
28

BMI

Better Long-Range Dependency By Bootstrapping A Mutual Information Regularizer https://arxiv.org/abs/1905.11978
Python
5
star
29

IMLE

Code for differentially private Implicit Maximum Likelihood Estimation model
C
4
star
30

StayPositive

Python
4
star
31

towards-better-sel-cls

Python
4
star
32

eval_dr_by_wsd

Evaluating quality of dimensionality reduction map with Wasserstein distances
Jupyter Notebook
3
star
33

group-feature-importance

Group feature importance
Python
2
star
34

ProbForest

Differentiable relaxations of tree-based models.
Python
2
star
35

ConR

Contrastive Regularizer
Python
2
star
36

robust-gan

On Minimax Optimality of GANs for Robust Mean Estimation
Python
1
star
37

raps

Code for the paper "Causal Bandits without Graph Learning"
Jupyter Notebook
1
star
38

monotonicity-mixup

Code of "Not Too Close and Not Too Far: Enforcing Monotonicity Requires Penalizing The Right Points"
Python
1
star