-
Notifications
You must be signed in to change notification settings - Fork 6.6k
set_scheduler method
#1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set_scheduler method
#1247
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
src/diffusers/pipeline_utils.py
Outdated
| ) | ||
|
|
||
| scheduler_config = current_scheduler.config | ||
| scheduler_init_dict, _ = scheduler_class.extract_init_dict(scheduler_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extracts the required config of the new scheduler from the old config @keturn
|
Thanks for following up on how to set a scheduler! Your earlier comment advising against setting the scheduler after pipeline initialization made got me worried, because that is a very common thing to want to do. but I must say, there's a lot going on here, and I'm not sure what to make of most of it. def set_scheduler(self, scheduler_type=Union[str, SchedulerType, Dict[str, str], Dict[str, SchedulerType]]):I'm easily overwhelmed by these types of function signatures with the Union of many different types with different dimensionalities. Even when they have parameter documentation, as this one does, it's difficult to explain all those different modes at once under a single parameter. I recently learned that Python 3 has single-dispatch generic functions now, as of Python 3.4 (or maybe 3.7 to get automatic use of type annotations). That might be worth considering if you do want to support such very different inputs, as then the documentation for the But after reading through this implementation and its tests a couple times, I think I'm starting to get the idea. You're addressing two use cases:
Alternate proposal:
Key features:
Other notesscheduler compatibility
I admit it made a mess when I tried to use IPNDMScheduler as a drop-in replacement for PNDMScheduler -- I guess they are not compatible -- but overall I don't think the assignment after pipeline initializationWe started talking about this based on the comment that we shouldn't reassign the pipeline's scheduler property after the pipeline's been initialized, but after all this, it comes down to: scheduler = scheduler_class(**scheduler_init_dict)
setattr(self, component_name, scheduler)--which seems to be doing just that? Maybe we don't need a special setter method for this at all, and we could do with something more like: pipeline.scheduler = EulerDiscreteScheduler.from_config(current_scheduler.config) |
|
Thanks for the comments @keturn, they are really nice. Regarding the "Alternate Proposal":
pipeline.set_scheduler(EulerDiscreteScheduler)or b) pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)is better for UX. The reason why I advocate against setting the scheduler as shown in b) is because it'll currently lead to errors. The problem here is that not every scheduler needs all configurations from other schedulers. E.g.: When I do: pipeline.scheduler = EulerDiscreteScheduler.from_config("runwayml/stable-diffusion-v1-5", subfolder="scheduler")then some parameters in the original config will be "destroyed", e.g. the parameter pipeline.scheduler.configdoes not include the pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)would led to errors. We could mitigate this problem by saving additional "hidden" parameters in the config. So either way we'll need some more functionality. The question is just whether the API: a) pipeline.set_scheduler(EulerDiscreteScheduler)or just: b) pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)is nicer. Maybe b) is actually the nicer API in the end as it doesn't require users to learn a new method. @patil-suraj @pcuenca @anton-l @keturn what do you think? |
|
BTW, the second use case is not urgent now, but cascaded diffusion models like Google's Imagen have multiple upscaling diffusion pipelines which each need a different scheduler. But this case could also be nicely covered by the API 1b) - just set multiple schedulers: pipe.scheduler1 = ...
pipe.scheduler2 = ... |
|
The more I think about this PR, the more I want to more or less start from scratch and instead use it to make the following changes: #1268 . Curious to hear any feedback. |
As someone who uses diffusers heavily: I love this! Although if you do:
|
|
Closing this one and going for the better "from_config" refactor ! |
|
Closing in favor of #1286 |
This PR introduces a new
set_schedulerAPI to make it easier to switch schedulers in existing pipelines.You can use it as follows: