diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Handle `kwargs` and not serializable values as configuration attributes

Open pcuenca opened this issue 3 years ago • 1 comments

Context: #655.

A kwargs argument was added to schedulers in https://github.com/huggingface/diffusers/commit/d7dcba4a130a2eeecd46fc1d2ed244f54fd2a8f6 just to display a deprecation warning. kwargs was interpreted as a configurable attribute, but it could not be serialized. This broke:

  • Pipeline loading, via __repr__ in the warning message.
  • Pipeline saving.

We just added a quick fix, but there were other ideas to address it. @anton-l proposed the following in https://github.com/huggingface/diffusers/blob/534512bedb70ab6074fd4399a3ce15afc4394a37/src/diffusers/configuration_utils.py#L408

ignore = getattr(self, "ignore_for_config", [])
ignore.append("kwargs")

There is also another check in https://github.com/huggingface/diffusers/blob/534512bedb70ab6074fd4399a3ce15afc4394a37/src/diffusers/configuration_utils.py#L283

Perhaps we should do this in a more general way and prevent accepting attributes that cannot be serialized, informing the user about the problem. A similar thing happened for dtype and is bound to happen again.

My first approach would be to attempt a JSON serialization in register_to_config and go from there, but I'm not fully familiar with the details of the code. Any thoughts?

pcuenca avatar Sep 27 '22 18:09 pcuenca

I think the solution we have for now is good enough actually - what do you think @pcuenca ?

patrickvonplaten avatar Oct 05 '22 10:10 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 29 '22 15:10 github-actions[bot]

Sounds good.

pcuenca avatar Oct 30 '22 15:10 pcuenca