-
Notifications
You must be signed in to change notification settings - Fork 6.1k
add models for T2I-Adapter-XL #4696
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
Conversation
We add T2I-Adapter-XL models to support the control on SDXL. |
@MC-E this looks good to me! Do we have any checkpoints that we can test this with? |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
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.
Very cool and minimal. just left two small comments.
@MC-E I tried loading an existing checkpoint here: https://colab.research.google.com/gist/sayakpaul/e9ed999df5714a6c9bb9c0a06cc9922a/scratchpad.ipynb. But I am currently facing issues. Could you look into it? |
It seems that all the key prefixes have an additional "adapter."? |
@MC-E I did the following: final_state_dict = {f"adapter.{k}": v for k, v in state_dict_new.items()}
xl_adapter = T2IAdapter(adapter_type="full_adapter_xl", downscale_factor=16)
xl_adapter.load_state_dict(final_state_dict) It leads to: RuntimeError: Error(s) in loading state_dict for T2IAdapter:
size mismatch for adapter.conv_in.weight: copying a param with shape torch.Size([320, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([320, 768, 3, 3]). Anything I am missing out on? |
Please follow the configs here https://github.com/TencentARC/T2I-Adapter/tree/XL/configs/inference; The number of input channels for OpenPose is three times that of others. |
I am using canny here: from huggingface_hub import hf_hub_download
repo_id = "TencentARC/T2I-Adapter"
filepath = "models_XL/adapter-xl-canny.pth"
state_dict_path = hf_hub_download(repo_id=repo_id, filename=filepath) |
@sayakpaul The input channels need to be 1. It seems that you set it as 3 |
Happy to assist you. Feel free to ask any questions:) |
Yup, that fixed it :) |
@MC-E I created this conversion script for easy sharing and distribution: https://gist.github.com/sayakpaul/9a888466865bc0844d8979a2b2821c63. Let's add this maybe to the Also, since you have already incorporated the feedback provided by @patil-suraj, I think for newer checkpoints (assuming we would use these blocks) we won't require any conversion. |
I think the next step would be to:
Pt 2 mostly involves:
We can add a new pipeline for this: Let me know if you face any difficulties here. Then in a follow-up PR, we can add the training script to start our full-length experiments. |
@sayakpaul The XL pipeline is added. The hf models are uploaded at: https://huggingface.co/Adapter/t2iadapter/tree/main |
@sayakpaul The test code is: import torch
from diffusers import (
T2IAdapter,
StableDiffusionXLAdapterPipeline,
DDPMScheduler,
)
from diffusers.utils import load_image
sketch_image = load_image('https://huggingface.co/Adapter/t2iadapter/resolve/main/sketch.png')
model_id = 'stabilityai/stable-diffusion-xl-base-1.0'
adapter = T2IAdapter.from_pretrained("Adapter/t2iadapter", subfolder='sketch_sdxl_1.0',torch_dtype=torch.float16, adapter_type="full_adapter_xl")
scheduler = DDPMScheduler.from_pretrained(model_id, subfolder="scheduler")
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
model_id, adapter=adapter, torch_dtype=torch.float16, variant="fp16", scheduler=scheduler
)
pipe.to('cuda')
generator = torch.manual_seed(42)
sketch_image_out = pipe(prompt='a photo of a dog in real world, high quality', negative_prompt='extra digit, fewer digits, cropped, worst quality, low quality', image=sketch_image, generator=generator, guidance_scale=7.5).images[0]
sketch_image_out.save('sketch_image_out.png') |
@MC-E thanks for providing the code snippet and for your contributions! A couple of things:
|
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
Outdated
Show resolved
Hide resolved
@MC-E I think you accidentally borked the commit history. It shouldn't be like that. |
In order to resolve conflicts, I perform a rebase on this PR:( |
Thanks for your amazing contribution! |
Thank you for your help:) |
Okay, thanks:) |
* T2I-Adapter-XL * update * update * add pipeline * modify pipeline * modify pipeline * modify pipeline * modify pipeline * modify pipeline * modify modeling_text_unet * fix styling. * fix: copies. * adapter settings * new test case * new test case * debugging * debugging * debugging * debugging * debugging * debugging * debugging * debugging * revert prints. * new test case * remove print * org test case * add test_pipeline * styling. * fix copies. * modify test parameter * style. * add adapter-xl doc * double quotes in docs * Fix potential type mismatch * style. --------- Co-authored-by: sayakpaul <[email protected]>
* T2I-Adapter-XL * update * update * add pipeline * modify pipeline * modify pipeline * modify pipeline * modify pipeline * modify pipeline * modify modeling_text_unet * fix styling. * fix: copies. * adapter settings * new test case * new test case * debugging * debugging * debugging * debugging * debugging * debugging * debugging * debugging * revert prints. * new test case * remove print * org test case * add test_pipeline * styling. * fix copies. * modify test parameter * style. * add adapter-xl doc * double quotes in docs * Fix potential type mismatch * style. --------- Co-authored-by: sayakpaul <[email protected]>
What does this PR do?
Fixes # (issue)
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
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.