Skip to content

Commit 3702bc2

Browse files
committed
Minor changes to README
Clean up build + environment cpu tests for adversary
1 parent be81059 commit 3702bc2

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ install:
2525
- pip install cox requests
2626
- pip install git+https://github.com/RobustBench/robustbench
2727
- pip install pytest
28+
- pip install advertorch
29+
- pip install copt
2830

2931

3032
script:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
!! WARNING !! This library is in early development. Its API may change often for the time being.
77

8-
## Stochastic Constrained Algorithms
8+
## Stochastic Algorithms
99
We define stochastic optimizers in the `chop.stochastic` module. These follow PyTorch Optimizer conventions, similar to the `torch.optim` module.
1010

1111
### Examples:

chop/stochastic.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def __init__(self, params, constraint, lr=.1):
101101
@property
102102
@torch.no_grad()
103103
def certificate(self):
104+
"""A generator over the current convergence certificate estimate
105+
for each optimized parameter."""
104106
for groups in self.param_groups:
105107
for p in groups['params']:
106108
state = self.state[p]
@@ -157,6 +159,8 @@ def _lmo(u, x):
157159
@property
158160
@torch.no_grad()
159161
def certificate(self):
162+
"""A generator over the current convergence certificate estimate
163+
for each optimized parameter."""
160164
for groups in self.param_groups:
161165
for p in groups['params']:
162166
state = self.state[p]
@@ -240,8 +244,8 @@ def _lmo(u, x):
240244
@property
241245
@torch.no_grad()
242246
def certificate(self):
243-
"""For each parameter optimized, gives the current value of the
244-
estimated optimality certificate."""
247+
"""A generator over the current convergence certificate estimate
248+
for each optimized parameter."""
245249
for group in self.param_groups:
246250
for p in group['params']:
247251
state = self.state[p]

environment.yml

-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ dependencies:
77
- pandas
88
- pytorch
99
- cudatoolkit
10-
- jupyter
1110
- torchvision
12-
- pylint
13-
- pytest
14-
- rope
1511
- pip
1612
- pip:
1713
- tables
1814
- dill
19-
- copt
20-
- advertorch
2115
- easydict

examples/adversarial_robustness/attack_benchmark.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from chop.optim import minimize_frank_wolfe, minimize_pgd, minimize_pgd_madry, minimize_three_split
2-
from chop.utils import closure
3-
41
import torch
52
from tqdm import tqdm
63

74
import chop
5+
from chop.optim import minimize_frank_wolfe, minimize_pgd, minimize_pgd_madry, minimize_three_split
86
from chop.data import load_cifar10
97
from chop.adversary import Adversary
108

@@ -70,7 +68,6 @@ def prox(delta, step_size=None):
7068
step=2. / max_iter,
7169
max_iter=max_iter)
7270

73-
delta_split = torch.zeros_like(data, device=data.device)
7471
_, delta_split = adversary_split.perturb(data, target, model,
7572
criterion,
7673
use_best=False,

examples/training_constrained_net_on_mnist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# Project model parameters in the constraint set.
4747
constraint.make_feasible(model)
4848

49-
optimizer = chop.stochastic.MomentumFrankWolfe(model.parameters(), constraint, lr=.3)
49+
optimizer = chop.stochastic.FrankWolfe(model.parameters(), constraint, lr=lr, momentum=momentum)
5050

5151
# Training loop
5252
for epoch in range(nb_epochs):

tests/test_adversary.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def test_adversary_synthetic_data(algorithm, step_size, p):
3030
# Setup
3131
torch.manual_seed(0)
3232
use_cuda = torch.cuda.is_available()
33-
# device = torch.device("cuda" if use_cuda else "cpu")
34-
device = torch.device("cpu")
33+
device = torch.device("cuda" if use_cuda else "cpu")
3534

3635
data = torch.rand((1, 25, 25))
3736
target = torch.zeros(1).long()
@@ -93,12 +92,11 @@ def test_adversary_mnist(algorithm, step, p, model_filename):
9392

9493
use_cuda = torch.cuda.is_available()
9594
device = torch.device("cuda" if use_cuda else "cpu")
96-
# device = torch.device("cpu")
95+
device = torch.device("cpu")
9796

9897
model = LeNet5()
9998
model_path = os.path.join(TRAINED_MODEL_PATH, model_filename)
100-
model.load_state_dict(torch.load(model_path))
101-
model.to(device)
99+
model.load_state_dict(torch.load(model_path, map_location=device))
102100
model.eval()
103101

104102
criterion = nn.CrossEntropyLoss()

0 commit comments

Comments
 (0)