Repository navigation
Raise a clear error when an SDXL UNet is used without added_cond_kwargs - #15501
Open
jimburtoft wants to merge 1 commit into
Open
jimburtoft wants to merge 1 commit into
jimburtoft wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
An SDXL UNet (
addition_embed_type="text_time") can be loaded intoStableDiffusionPipelinewith no error. The pipeline then fails at the first denoising step with an unhelpful error:The SD 1.x pipelines pass
added_cond_kwargs=None(or a dict with only IP-Adapter embeds). The UNet's check assumes a dict, so instead of raising its ownValueErrorit hits aTypeError. #4649 and #6996 report this traceback. Both were closed without a code change.This is easy to hit from the Hub: some repos ship an SDXL UNet with a
model_index.jsonthat namesStableDiffusionPipeline. For example,jd09876/miaomiao-haremgets about 11k downloads a month.This PR:
StableDiffusionPipeline,StableDiffusionImg2ImgPipelineandStableDiffusionInpaintPipelineraise in__init__when given atext_timeUNet, and name the SDXL pipeline to use instead. This is next to the existing__init__checks onunet.config.UNet2DConditionModel,UNetMotionModel,ControlNetModel,ControlNetUnionModelandUNetControlNetXSModeltreatadded_cond_kwargs=Nonelike a missing key. That makes every other caller get the model's existingValueError("... requires the keyword argumenttext_embeds...") instead of theTypeError. Other callers include ControlNet, PAG, LCM, depth2img, community pipelines and user code.StableDiffusionPipeline.from_pipe(sdxl_pipe)now raises at construction. Before, it built a pipeline that failed at its first step. AutoPipeline, the XL pipelines and single-file loading are unaffected.Tests
New tests:
test_rejects_sdxl_unetin the SD, img2img and inpaint pipeline tests (4 includingTestStableDiffusionSimpleInpaintPipeline).test_text_time_without_added_cond_kwargsin the UNet model tests.All 5 fail on
mainand pass with this PR:Regression run on CPU:
tests/pipelines/{stable_diffusion,stable_diffusion_xl,controlnet}/,tests/pipelines/pag/test_pag_sd{,xl}.py,tests/models/unets/test_models_unet_{2d_condition,motion,controlnetxs}.pyandtests/models/controlnets/. All pass excepttest_stable_diffusion_inpaint, which fails the same way onmainin my environment.ruff check,ruff format --checkandutils/check_copies.pyare clean.Self-review notes
I ran the
self-reviewskill. Changes made after it:Left for review:
__init__error on top of the model fix. It is redundant for correctness, but it gives the actionable "useStableDiffusionXLPipeline" message at load time.__init__check to them, to keep the diff small.Fixes #4649
Fixes #6996
Who can review?
@yiyixuxu @asomoza