diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Incorrect type annotations on `StableDiffusionPipeline`

Open tasercake opened this issue 3 years ago • 3 comments

Describe the bug

StableDiffusionPipeline::__call__ has some parameters annotated as Optional when they really aren't (i.e. they shouldn't be None)

A potential fix would be to just remove the Optional annotation on these parameters, as in this commit: https://github.com/tasercake/diffusers/commit/7a5c37a95f62e3b2923076f9becb4c2780fd425b

Alternatively, we could handle None values at runtime by setting defaults inside the __call__ body. IMO this would lead to the least surprising behaviour – I would expect that passing height=None would just use the default height, whereas it currently raises an exception.

Reproduction

from diffusers import StableDiffusionPipeline

# Load pretrained pipeline
pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True)

# Call with `height` = None
results = self.stable_diffusion_pipeline(["A corgi in a field"], height=None)
# Raises "TypeError(unsupported operand type(s) for %: 'NoneType' and 'int')"

Logs

No response

System Info

Ubuntu 20.04, diffusers 0.2.4

tasercake avatar Sep 26 '22 03:09 tasercake

Good point! Would you like to open a PR to add it? :-)

patrickvonplaten avatar Sep 27 '22 11:09 patrickvonplaten

I'd be happy to!

Which approach do you think would be better – removing the Optional annotations, or using default values when None is passed?

tasercake avatar Sep 29 '22 06:09 tasercake

IMO removing Optional is the better choice here

patrickvonplaten avatar Sep 29 '22 18:09 patrickvonplaten

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.

github-actions[bot] avatar Oct 26 '22 15:10 github-actions[bot]