Why 'DiffusionPipeline' doesn't have a __call__ method?

Every pipeline has a __call__ method which keeps them can call themselves as a function. But I can’t find __call__ method in class DiffusionPipeline.
I read DiffusionPipeline code and find nothing about __call__ method in this link:
In this link train_dreambooth.py
you can see that DiffusionPipeline do used call function, so that it can make a inference.
May someone can teach me about this, thanks a lot.
PS:sorry for my poor English

1 Like

If you use the from_pretrained method of the DiffusionPipeline like this:

from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")

The resulting pipe is not only an instance of the DiffusionPipeline class but also, in this case, an instance of the StableDiffusionXLPipeline class. You can verify this as follows:

from diffusers import StableDiffusionXLPipeline

isinstance(pipe, DiffusionPipeline) and isinstance(pipe, StableDiffusionXLPipeline)



This method internally instantiates an object of the StableDiffusionXLPipeline class, and similar to other pipelines, this class defines a __call__ method.

Please be aware that the DiffusionPipeline lacks also an __init__ method. Therefore, you cannot perform the following action to instantiate and use an object of only the DiffusionPipeline class:

pipe = DiffusionPipeline(...)

Instead, you are required to use the from_pretrained method, which returns an object from a class that defines a __call__ method.

I hope this was helpful, and fingers crossed I didn’t write any inaccuracies! :blush:

OK,thanks a lot! That’s really helpful!