Skip to content

DummyObjects are impeding PyCharm #1479

Closed

Description

@keturn

I'm subclassing StableDiffusionPipeline (because it seems like that's the intended way to make a DiffusionPipeline that is still able to take advantage of StableDiffusionPipeline's methods to enable attention slicing, decode latents, etc.), and I've noticed a distinct lack of help from the IDE when it comes to attributes and arguments that I know this class has.

I think that's because when I hit "go to definition" of the StableDiffusionPipeline I'm using as a superclass, it brings me to this

class StableDiffusionPipeline(metaclass=DummyObject):
_backends = ["torch", "transformers"]
def __init__(self, *args, **kwargs):
requires_backends(self, ["torch", "transformers"])
@classmethod
def from_config(cls, *args, **kwargs):
requires_backends(cls, ["torch", "transformers"])
@classmethod
def from_pretrained(cls, *args, **kwargs):
requires_backends(cls, ["torch", "transformers"])

no defined arguments to the class __init__, no indication that it's an ancestor of DiffusionPipeline, no __call__ method, none of the documentation or type hits that you've so diligently included in your code.

Should I be importing directly from the full path diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline instead of diffusers.StableDiffusionPipeline?

If so, please remove the diffusers.StableDiffusionPipeline stunt double so that I'm not presented with two options when autocompleting and left to probably pick the wrong one.

Activity

  1. keturn commented on Nov 30, 2022

    @keturn
    ContributorAuthor

    If so, please remove the diffusers.StableDiffusionPipeline stunt double so that I'm not presented with two options when autocompleting and left to probably pick the wrong one.

    It's actually worse than that, it seems PyCharm assumes the one higher-up in the namespace is the right one, why wouldn't it be? so it doesn't even give me the option of picking the right one. It's always the wrong one and I have to manually correct it.

  2. vvsotnikov commented on Nov 30, 2022

    @vvsotnikov
    Contributor

    +1, this negatively affects my performance as well :( The workaround I'm currently using is to provide an explicit type hint upon an instantiation of a pipeline:
    image

  3. d8ahazard commented on Dec 1, 2022

    @d8ahazard
    Contributor

    So, it's not just me then? :P

  4. patrickvonplaten commented on Dec 2, 2022

    @patrickvonplaten
    Contributor

    Thanks for the issue! We should indeed look into this :-)

    I'm not using PyCharm, but @anton-l @patil-suraj I think you've noticed similar problems?

    Also cc @sgugger if I remember correctly we had a similar issue in transformers a while back - do you remember how we fixed it? :-)

  5. self-assigned this
    on Dec 2, 2022
  6. anton-l commented on Dec 2, 2022

    @anton-l
    Member

    Found the transformers solution, didn't know it was already addressed there: huggingface/transformers#16578
    Assigning to myself as the only pycharm user on the team 😅

  7. pcuenca commented on Dec 2, 2022

    @pcuenca
    Member

    Assigning to myself as the only pycharm user on the team 😅

    The same thing happens to me in VSCode :) Happy to learn that there's a solution!

  8. sgugger commented on Dec 5, 2022

    @sgugger
    Contributor

    Yes, the PR mentioned above fixes all editors normally, and will make them point to the dummy objects when the framework is not installed, and the real ones when it is :-)

  9. anton-l commented on Dec 8, 2022

    @anton-l
    Member

    Should be fixed now, and scheduled for this week's release!

  10. added a commit that references this issue on Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions