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

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 this issue Jun 8, 2023 · 3 comments

Comments

@tanlingp
Copy link

tanlingp commented Jun 8, 2023

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
Copy link
Owner

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
Copy link

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
Copy link
Owner

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.

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

3 participants