• Stars
    star
    1,291
  • Rank 36,430 (Top 0.8 %)
  • Language
    Jupyter Notebook
  • License
    GNU Lesser Genera...
  • Created almost 6 years ago
  • Updated about 1 year 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
148
star
2

private-data-generation

A toolbox for differentially private data generation
Python
127
star
3

scaleformer

Python
117
star
4

SLAPS-GNN

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

de-simple

Diachronic Embedding for Temporal Knowledge Graph Completion
Python
81
star
6

flora-opt

This is the official repository for the paper "Flora: Low-Rank Adapters Are Secretly Gradient Compressors" in ICML 2024.
Python
66
star
7

continuous-time-flow-process

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

ranksim-imbalanced-regression

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

lite_tracer

a light weight experiment reproducibility toolset
Python
39
star
10

pommerman-baseline

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

mma_training

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

TSC-Disc-Proto

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

MMoEEx-MTL

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

mtmfrl

Multi Type Mean Field Reinforcement Learning
Python
28
star
15

CP-VAE

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

cross_domain_coherence

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

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
18

DT-Fixup

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

rate_distortion

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

PROVIDE

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

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
13
star
22

continuous-latent-process-flows

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

code-gen-TAE

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

ssl-for-timeseries

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

OOS-KGE

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

ConR

Contrastive Regularizer
Python
6
star
27

nflow-cdf-approximations

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

IMLE

Code for differentially private Implicit Maximum Likelihood Estimation model
C
5
star
29

keyphrase-generation

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

towards-better-sel-cls

Python
5
star
31

latent-bottlenecked-anp

Python
5
star
32

BMI

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

StayPositive

Python
4
star
34

tree-cross-attention

Python
4
star
35

eval_dr_by_wsd

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

autocast-plus-plus

[ICLR'24] AutoCast++: Enhancing World Event Prediction with Zero-shot Ranking-based Context Retrieval
Python
3
star
37

perturbed-forgetting

Training SAM, GSAM, ASAM with standard and OBF perturbations
Python
3
star
38

group-feature-importance

Group feature importance
Python
2
star
39

ProbForest

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

raps

Code for the paper "Causal Bandits without Graph Learning"
Jupyter Notebook
2
star
41

meta-tpp

PyTorch-Lightning implementation of Meta Temporal Point Processes
Python
2
star
42

sasrec-ccql

PyTorch code of "Robust Reinforcement Learning Objectives for Sequential Recommender Systems"
Python
2
star
43

adaflood

Python
1
star
44

monotonicity-mixup

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

robust-gan

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

DynaShare-MTL

PyTorch Implementation of DynaShare: Task and Instance Conditioned Parameter Sharing for Multi-Task Learning
Python
1
star
47

dcf

Python
1
star