Skip to content

Add Example of IPAdapterScaleCutoffCallback to Docs - #10934

Merged
stevhliu merged 4 commits into
huggingface:mainfrom
ParagEkbote:Add-Example-of-Ip-Adapter-Callback
Mar 3, 2025
Merged

Add Example of IPAdapterScaleCutoffCallback to Docs#10934
stevhliu merged 4 commits into
huggingface:mainfrom
ParagEkbote:Add-Example-of-Ip-Adapter-Callback

Conversation

@ParagEkbote

@ParagEkboteParagEkbote commented Mar 1, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

When I was working on a previous PR, I noticed that there was no example showing the usage of IP Adapter Callback to the docs, I've added one in this PR.

1)Script for image without callback:

fromdiffusersimportAutoPipelineForText2Imagefromdiffusers.utilsimportload_imageimporttorchpipeline=AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
pipeline.set_ip_adapter_scale(0.6)
image=load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_adapter_diner.png")
generator=torch.Generator(device="cuda").manual_seed(2628670641)
images=pipeline(
prompt="a tiger sitting in a chair drinking orange juice",
ip_adapter_image=image,
negative_prompt="deformed, ugly, wrong proportion, low res, bad anatomy, worst quality, low quality",
num_inference_steps=50,
generator=generator,
).imagesimages[0].save("without_callback.png")

without_callback

  1. Script for image with callback:
fromdiffusersimportAutoPipelineForText2Imagefromdiffusers.callbacksimportIPAdapterScaleCutoffCallbackfromdiffusers.utilsimportload_imageimporttorchpipeline=AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_ip_adapter(
"h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin"
)
pipeline.set_ip_adapter_scale(0.6)
callback=IPAdapterScaleCutoffCallback(
cutoff_step_ratio=None, cutoff_step_index=5
)
image=load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_adapter_diner.png"
)
generator=torch.Generator(device="cuda").manual_seed(2628670641)
images=pipeline(
prompt="a tiger sitting in a chair drinking orange juice",
ip_adapter_image=image,
negative_prompt="deformed, ugly, wrong proportion, low res, bad anatomy, worst quality, low quality",
generator=generator,
num_inference_steps=50,
callback_on_step_end=callback,
).imagesimages[0].save("custom_callback_img.png")

with_callback2

For adding the images to the docs, do I have to upload them to this repository on the HF hub and link it back to the page? Please let me know and I will make the necessary changes.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Who can review?

@stevhliu

Comment threaddocs/source/en/using-diffusers/callback.md
@hlky

hlky commented Mar 1, 2025

Copy link
Copy Markdown
Contributor

Hi @ParagEkbote. Thanks for this contribution.

do I have to upload them to this repository on the HF hub and link it back to the page

Yes, create a Hub PR that uploads the images somewhere under diffusers, link the PR here and someone will merge it.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

hlky
hlky approved these changes Mar 2, 2025
@hlky
hlky requested a review from stevhliuMarch 2, 2025 15:31

@stevhliustevhliu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, thanks for including!

@stevhliu
stevhliu merged commit 982f9b3 into huggingface:mainMar 3, 2025
@ParagEkbote
ParagEkbote deleted the Add-Example-of-Ip-Adapter-Callback branch March 3, 2025 16:57
Sign up for freeto 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.

5 participants

@ParagEkbote@hlky@HuggingFaceDocBuilderDev@shethaadit@stevhliu