Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for indiscriminate attack #2

Open
Cascol-Chen opened this issue May 27, 2024 · 1 comment
Open

Code for indiscriminate attack #2

Cascol-Chen opened this issue May 27, 2024 · 1 comment

Comments

@Cascol-Chen
Copy link

Cascol-Chen commented May 27, 2024

It's a really nice work that reminds the adversarial vulnerability of TTA.

I want to ask for the source code of indiscriminate attack. You have provided a reply for this in another issues, which changes the loss function in generate_attacks function to the following.

loss = nn.CrossEntropyLoss(reduction='none')(out[:-source], y[:-source]).clamp(min=0,max=5)
loss = loss.sum()
adv.data = (adv + alpha*adv.grad.detach().sign()).clamp(-epsilon,epsilon)

Nevertheless, I find that this loss cannot provide gradients for adv when I pass the original ViT into the generate_attacks function (since adv modify out[-source:], i.e., the latter inputs). Meanwhile, when I pass the Tented model into the generate_attacks function, RuntimeError occurs, "Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling .backward() or autograd.grad() the first time."

Could you provide more explanations on how to conduct indiscriminate attack? Or is the attack only available on BN models?

@tongwu2020
Copy link
Member

Hi,

Which torch version do you use? Could you try loss.backward(retain_graph=True) ?

Best,
Tong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants