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

Fix AutoPipeline from_pipe where source pipeline is missing target pipeline's optional components #10400

Merged
merged 4 commits into from
Jan 2, 2025

Conversation

hlky
Copy link
Collaborator

@hlky hlky commented Dec 27, 2024

What does this PR do?

Flux IPAdapter introduced optional components feature_extractor and image_encoder to FluxPipeline, the changes have not yet been replicated to Img2Img/Inpaint pipelines, when checking for missing modules in from_pipe we consider the target pipeline's expected_modules and the source pipeline's _optional_components, we should also consider the target pipeline's optional components.

from diffusers import FluxPipeline, AutoPipelineForInpainting, AutoPipelineForText2Image
import torch

pipe = FluxPipeline.from_pretrained(
  "black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16
)
pipe = AutoPipelineForInpainting.from_pipe(pipe)
pipe = AutoPipelineForText2Image.from_pipe(pipe)
File Untitled-8:8
      7 pipe = AutoPipelineForInpainting.from_pipe(pipe)
----> 8 pipe = AutoPipelineForText2Image.from_pipe(pipe)

File diffusers/src/diffusers/pipelines/auto_pipeline.py:534, in AutoPipelineForText2Image.from_pipe(cls, pipeline, **kwargs)
    531 missing_modules = set(expected_modules) - set(pipeline._optional_components) - set(text_2_image_kwargs.keys())
    533 if len(missing_modules) > 0:
--> 534     raise ValueError(
    535         f"Pipeline {text_2_image_cls} expected {expected_modules}, but only {set(list(passed_class_obj.keys()) + list(original_class_obj.keys()))} were passed"
    536     )
    538 model = text_2_image_cls(**text_2_image_kwargs)
    539 model.register_to_config(_name_or_path=pretrained_model_name_or_path)

ValueError: Pipeline <class 'diffusers.pipelines.flux.pipeline_flux.FluxPipeline'> expected {'tokenizer_2', 'tokenizer', 'text_encoder', 'image_encoder', 'vae', 'scheduler', 'transformer', 'feature_extractor', 'text_encoder_2'}, but only {'tokenizer_2', 'tokenizer', 'text_encoder', 'vae', 'scheduler', 'transformer', 'text_encoder_2'} were passed

Fixes #10399

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.

@yiyixuxu @vladmandic

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

@siddhant230
Copy link

siddhant230 commented Dec 29, 2024

Hey @hlky , I was able to run the Text2imagepipeline without any issues, haven't tested on GPU (as I am GPU poor). But, AutoPipelineForText2Image.from_pipe() is able to load from inpainting pipeline.

As for the code, I was able to find "target pipeline's optional components" included along with other components as you mentioned in the description.

Thanks for the PR.

@@ -528,7 +528,12 @@ def from_pipe(cls, pipeline, **kwargs):
if k not in text_2_image_kwargs
}

missing_modules = set(expected_modules) - set(pipeline._optional_components) - set(text_2_image_kwargs.keys())
missing_modules = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think maybe

missing_modules = set(expected_modules) - set(text_2_image_cls._optional_components) - set(text_2_image_kwargs.keys())

Because if one component is optional for the other pipe (the pipe as in .from_pipe(pipe)) but it's not optional for the target pipe (text_2_image here) - it is still missing, no?

Just a thought: I didn't run any tests, I think it might a bug we had and was able to get away with this because the _optional_componentes is usually the same among different tasks for the same model group

so please let me know if it is the case:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, thanks

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.

thanks!

@yiyixuxu yiyixuxu merged commit c28db0a into huggingface:main Jan 2, 2025
12 checks passed
yiyixuxu added a commit that referenced this pull request Jan 2, 2025
…pipeline's optional components (#10400)

* Optional components in AutoPipeline

* missing_modules

---------

Co-authored-by: YiYi Xu <[email protected]>
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.

Flux failures using from_pipe
4 participants