Skip to content

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

"""


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