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

adding callback_on_step_end for StableDiffusionLDM3DPipeline #7149

Merged
merged 5 commits into from
Mar 4, 2024

Conversation

rootonchair
Copy link
Contributor

What does this PR do?

Fixes #7136

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@rootonchair
Copy link
Contributor Author

rootonchair commented Feb 29, 2024

Test script

import torch
from diffusers import StableDiffusionLDM3DPipeline

def callback_dynamic_cfg(pipe, step_index, timestep, callback_kwargs):
    # adjust the batch_size of prompt_embeds according to guidance_scale
    if step_index == int(pipe.num_timesteps * 0.4):
        prompt_embeds = callback_kwargs["prompt_embeds"]
        prompt_embeds = prompt_embeds.chunk(2)[-1]

        # update guidance_scale and prompt_embeds
        pipe._guidance_scale = 0.0
        callback_kwargs["prompt_embeds"] = prompt_embeds
    return callback_kwargs

pipe = StableDiffusionLDM3DPipeline.from_pretrained("Intel/ldm3d-4c")
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
generator = torch.Generator()
generator.manual_seed(42)
output = pipe(prompt, generator=generator, callback_on_step_end=callback_dynamic_cfg, callback_on_step_end_tensor_inputs=['prompt_embeds'])
rgb_image, depth_image = output.rgb, output.depth
rgb_image[0].save("astronaut_ldm3d_rgb.jpg")
depth_image[0].save("astronaut_ldm3d_depth.png")

@sayakpaul sayakpaul requested a review from yiyixuxu March 1, 2024 06:53
@HuggingFaceDocBuilderDev

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.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great! thanks!
think we are just missing some #copied from

@@ -59,6 +59,64 @@
"""


def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #copied from?

return noise_cfg


def retrieve_timesteps(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a #Copied from

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will

@rootonchair rootonchair requested a review from yiyixuxu March 3, 2024 15:00
@yiyixuxu yiyixuxu merged commit 2ca2642 into huggingface:main Mar 4, 2024
15 checks passed
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

Successfully merging this pull request may close these issues.

adding callback_on_step_end for StableDiffusionLDM3DPipeline
4 participants