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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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