-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Improve post-processing performance #10159
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
Improve post-processing performance #10159
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Thanks for your contribution @soof-golan! Can you run |
* Use multiplication instead of division * Avoid splitting and re-stacking tensors to reduce memory bandwidth and CPU-GPU syncs
f94fd19
to
61fc97b
Compare
@hlky Done! |
|
||
# De-normalizing a batch and selectively torch.stack'ing the results turns out to be | ||
# significantly faster than performing a lot of smaller denormalizations | ||
denormalized = self.denormalize(images) |
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.
I think there is some context to that, each image in the batch may have a different value for do_normalize
for sd1.5, see the code here
diffusers/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Line 1075 in 6131a93
image = self.image_processor.postprocess(image, output_type=output_type, do_denormalize=do_denormalize) |
Since most of the new pipelines (sdxl, sd3, flux), we do not pass the do_normalize
from the pipeline, i.e. do_normalize is None
here , see SDXL https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py#L1304 ,
and we already did this so it will be batch processed for all the new pipelines already, I think this line is sufficient here
if do_denormalize is None:
return self.denormalize(images) if self.config.do_normalize else images
image = torch.stack( | ||
[self.denormalize(image[i]) if do_denormalize[i] else image[i] for i in range(image.shape[0])] | ||
) | ||
image = self._denormalize_conditionally(image, do_denormalize) |
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.
if do_denormalize is None:
image = self.denormalize(images) if self.config.do_normalize
else:
image = torch.stack(
[self.denormalize(image[i]) if do_denormalize[i] else image[i] for i in range(image.shape[0])]
)
Closed by #10170 |
What does this PR do?
Fixes: #10158
VaeImageProcessor.denormalize