WindVChen / DiffAttack

An unrestricted attack based on diffusion models that can achieve both good transferability and imperceptibility.
Apache License 2.0
115 stars 9 forks source link

Your code currently operates one image at a time, is it possible to adjust the batch_size operation? I look forward to hearing from you! #6

Open tanlingp opened 1 year ago

tanlingp commented 1 year ago

Your code currently operates one image at a time, is it possible to adjust the batch_size operation? I look forward to hearing from you!

WindVChen commented 1 year ago

Hi @tanlingp ,

In theory, we can of course generate adversarial images in batches. However, since this method currently requires backpropagation through multiple diffusion steps, many intermediate calculation graphs are stored, so even if only a single image is processed, the memory usage is approximately 16GB. Thus with only my current equipment (a single Rtx3090), I'm afraid I am not able to test turning the code into batches.

However, if you have multiple GPUs or more memory, the most straightforward way I recommend is to use multiprocessing to process batches of images. It's easy and doesn't require modifying the core code.

Hope this helps.

yujinhanml commented 8 months ago

Hi @WindVChen,

This article proposes the Segment-wise Forwarding-Backwarding algorithm to address the memory issue in computational graphs, aiming to improve the efficiency of DiffAttack.

WindVChen commented 8 months ago

Hi @yujinhan98,

Thank you for sharing the article. I appreciate your insight in addressing the memory issue with Segment-wise Forwarding-Backwarding. However, it seems that this approach might prolong the optimization time, which might still fail to speed up the generation of the adversarial examples.

While I haven't delved into all the intricacies of the article, Segment-wise Forwarding-Backwarding seems akin to the commonly used gradient checkpointing trick. This method involves recalculating computational graphs during the backpropagation phase, leading to increased processing time, contingent on the number of checkpoints set.

@tanlingp's intention, I think, is to expedite the generation of adversarial examples by leveraging batch processing. Given the longer processing time per input associated with Segment-wise Forwarding-Backwarding (despite its reduced memory usage), it may not significantly enhance the speed, which is the primary concern here.

Nonetheless, I appreciate your contribution. Many thanks for sharing your insights.

Best regards.