diffusers
diffusers copied to clipboard
Incorrect type annotations on `StableDiffusionPipeline`
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
Good point! Would you like to open a PR to add it? :-)
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?
IMO removing Optional is the better choice here
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.