Skip to content

Expanded init fields in StableDiffusionPipeline cause incompatibilities with many/most inherited pipelines #6969

Description

@vladmandic

Describe the bug

class StableDiffusionPipeline has its init section as:

    def __init__(
        self,
        vae: AutoencoderKL,
        text_encoder: CLIPTextModel,
        tokenizer: CLIPTokenizer,
        unet: UNet2DConditionModel,
        scheduler: KarrasDiffusionSchedulers,
        safety_checker: StableDiffusionSafetyChecker,
        feature_extractor: CLIPImageProcessor,
        image_encoder: CLIPVisionModelWithProjection = None,
        requires_safety_checker: bool = True,
    ):

and here image_encoder was recently introduced thus changing the class signature
but most community pipelines do not include init field for recently included image_encoder and thus order or params is wrong

for example, examples/community/regional_prompting_stable_diffusion.py has this in its init:

        super().__init__(
            vae,
            text_encoder,
            tokenizer,
            unet,
            scheduler,
            safety_checker,
            feature_extractor,
            requires_safety_checker,
        )

which means bool value from requires_safety_checker is going to be passed as image_encoder and pipeline will fail during initialization like this:

> diffusers/pipelines/pipeline_utils.py:546 in _fetch_class_library_tuple
AttributeError: 'bool' object has no attribute '__module__'

this is a conceptual problem with changing master class signature while all inherited classes pass args list as simple list.
i don't see a simple solution as going back is bad and going forward requires updates to a lot of pipelines.

but at the very basic, at least add error handling to _fetch_class_library_tuple so invalid type does not cause entire solution to crash.

Reproduction

load nearly any community pipeline or any pipeline inherited from StableDiffusionPipeline, but not updated to use new signature in its super().__init__ call

Logs

No response

System Info

diffusers==0.26.3

Who can help?

@yiyixuxu @DN6 @sayakpaul @patrickvonplaten

Activity

  1. sayakpaul commented on Feb 14, 2024

    @sayakpaul
    Member
  2. yiyixuxu commented on Feb 14, 2024

    @yiyixuxu
    Collaborator

    Hi @vladmandic
    It only breaks pipelines that inherit from StableDiffusionPipeline instead of DiffusionPipeine - all our pipelines should inherit from DiffusionPipeline.

    I don't consider this a breaking change for this reason. However would very much like to make the community pipelines work correctly again. We can ask the community to help refactor these PRs to use DiffusionPipeline as a base class instead - does this plan work for you?

    cc @sayakpaul @DN6 here
    do you guys have any good ideas?

    I think we should start to check the base classes for community pipeline PRs and don't merging in unless they use DiffusionPipeline

  3. sayakpaul commented on Feb 14, 2024

    @sayakpaul
    Member

    What you suggested is the best case here as it's the simplest.

  4. yiyixuxu commented on Feb 14, 2024

    @yiyixuxu
    Collaborator

    @vladmandic

    Is this something can be done in SD.Next for a temporary solution while we trying to update all the community pipelines to use DiffusionPipeline?

    but at the very basic, at least add error handling to _fetch_class_library_tuple so invalid type does not cause entire solution to crash.

  5. vladmandic commented on Feb 14, 2024

    @vladmandic
    ContributorAuthor

    thanks - i agree with action plan.
    i'll try monkey-patching _fetch_class_library_tuple from sdnext in the meantime.

  6. vladmandic commented on Feb 14, 2024

    @vladmandic
    ContributorAuthor

    i confirm that monkey-patching works as as stop-gap solution

    from diffusers.pipelines import pipeline_utils
    
    def hijack_register_modules(self, **kwargs):
        for name, module in kwargs.items():
            if module is None or isinstance(module, (tuple, list)) and module[0] is None:
                register_dict = {name: (None, None)}
            elif isinstance(module, bool):
                pass
            else:
                library, class_name = pipeline_utils._fetch_class_library_tuple(module)
                register_dict = {name: (library, class_name)}
            self.register_to_config(**register_dict)
            setattr(self, name, module)
    
    pipeline_utils.DiffusionPipeline.register_modules = hijack_register_modules
  7. github-actions commented on Mar 15, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  8. sayakpaul commented on Mar 15, 2024

    @sayakpaul
    Member

    I think this is not stale. @yiyixuxu can you confirm?

  9. removed
    staleIssues that haven't received updates
    on Mar 15, 2024
  10. github-actions commented on Apr 9, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  11. vladmandic commented on Apr 9, 2024

    @vladmandic
    ContributorAuthor

    ping.

  12. 9 remaining items

  13. removed
    staleIssues that haven't received updates
    on Nov 2, 2024
  14. github-actions commented on Nov 27, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  15. vladmandic commented on Nov 27, 2024

    @vladmandic
    ContributorAuthor

    ping to remove stale

  16. removed
    staleIssues that haven't received updates
    on Nov 27, 2024
  17. asomoza commented on Nov 27, 2024

    @asomoza
    Member

    added the wip so it doesn't get stale.

    Also added the contributions tags so if people want to contribute we would really appreciate it. This is a good first issue for new comers.

  18. Filippo-Venturini commented on Oct 31, 2025

    @Filippo-Venturini

    Is someone working on this? If not I can give it a chance, do you have a specific list of pipelines that need to be fixed?

  19. sayakpaul commented on Oct 31, 2025

    @sayakpaul
    Member

    Feel free to take it away.

  20. Filippo-Venturini commented on Oct 31, 2025

    @Filippo-Venturini

    I think this Issue can be closed as they refactored all the pipelines changing the base class to DiffusionPipeline here: #6984 (comment)

  21. added a commit that references this issue on Jun 25, 2026
    e00c4c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions