locuslab / fast_adversarial

[ICLR 2020] A repository for extremely fast adversarial training using FGSM
434 stars 92 forks source link

Inconsistent clamping behaviour between CIFAR and MNIST fgsm implementaitions #21

Closed max-kaufmann closed 2 years ago

max-kaufmann commented 2 years ago

In the implemenation of fgsm for mnist, you do not clamp the initatial perturbation - meaning you calculate gradient based on out of bounds data points:

delta = torch.zeroslike(X).uniform(-args.epsilon, args.epsilon).cuda() delta.requires_grad = True output = model(X + delta) loss = F.cross_entropy(output, y)

This contrasts with the CIFAR implementation, where this clamping is done:

# for j in range(len(epsilon)): delta[:, j, :, :].uniform_(-epsilon[j][0][0].item(), epsilon[j][0][0].item()) delta.data = clamp(delta, lower_limit - X, upper_limit - X)

Is this intended? Why was this choice made?

leslierice1 commented 2 years ago

This was not intentional, we just forgot to add the clamping for MNIST. You may need to adjust the alpha parameter for training MNIST if you do add the clamping.