-
-
Notifications
You must be signed in to change notification settings - Fork 430
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
Batch Size Optimization #486
Conversation
7872199
to
5ee2dfe
Compare
Just found out in |
I'm having trouble trying to implement batching for Stability SDK properly. It's able to accept a list of prompts, but I'm only able to get it to generate images based off the first one. I'll just leave it as simple iteration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, and it also worked on mps
. The only thing to look out for is huggingface/diffusers#1909, some schedulers don't handle a list of generators properly yet. Could it be adjusted to pass a single generator if the batch size is 1?
I believe that's all the necessary changes. I'll also note that upscaling doesn't use a list of generators when batching like other actions since I don't think seed reproducibility is as necessary there. |
* proof of concept * other actions * add package release workflow * Update .github/workflows/package-release.yml Co-authored-by: Carson Katri <[email protected]> * fix seamless axes * half precision * fix model download * half precision fixes inpainting, upscaling, depth with color * more half precision fixes * modify revision selection * remove obsolete patches * remove #486 upscale timing * validate snapshot before selection Co-Authored-By: Carson Katri <[email protected]> * tqdm update missing in pipelines * fix upscaling non-square images fixes #528 --------- Co-authored-by: Carson Katri <[email protected]>
I've seen great speed improvement when generating multiple images in batches. So far I've tested batch sizes of 2-5 and reduced run time by 26-39% using a GTX 1070 along with the default half precision and attention slicing optimizations.
It's implemented as a new speed optimization option that'll only go into effect if iterations or file batch are used. It'll split up the requested images into as many full batches that it can and do a smaller batch on any remaining at the end.
Progress
Stability SDKIssues
This feature may only be suitable for CUDA users right now.
https://huggingface.co/docs/diffusers/optimization/mps#known-issues
Only other downsides are extra memory usage and results aren't entirely deterministic.

Testing indicates that the deterministic nature isn't affected by the seeds or prompts of other images in the same batch. The same batch size with the same settings for any single or multiple images in it will result in the same image, only the batch size amount is causing the odd behavior. I'm uncertain if this is a bug in diffusers or this implementation yet.