Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/diffusers/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,19 @@ def from_config(cls, pretrained_model_name_or_path: Union[str, os.PathLike], ret
if "dtype" in unused_kwargs:
init_dict["dtype"] = unused_kwargs.pop("dtype")

# Return model and optionally state and/or unused_kwargs
model = cls(**init_dict)
return_tuple = (model,)

# Flax schedulers have a state, so return it.
if cls.__name__.startswith("Flax") and hasattr(model, "create_state") and getattr(model, "has_state", False):
state = model.create_state()
return_tuple += (state,)

if return_unused_kwargs:
return model, unused_kwargs
return return_tuple + (unused_kwargs,)
else:
return model
return return_tuple if len(return_tuple) > 1 else model

@classmethod
def get_config_dict(
Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/pipeline_flax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
loaded_sub_model, loaded_params = load_method(loadable_folder, _do_init=False)
params[name] = loaded_params
elif issubclass(class_obj, SchedulerMixin):
loaded_sub_model = load_method(loadable_folder)
params[name] = loaded_sub_model.create_state()
loaded_sub_model, scheduler_state = load_method(loadable_folder)
params[name] = scheduler_state
else:
loaded_sub_model = load_method(loadable_folder)

Expand Down
4 changes: 4 additions & 0 deletions src/diffusers/schedulers/scheduling_ddim_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class FlaxDDIMScheduler(SchedulerMixin, ConfigMixin):
stable diffusion.
"""

@property
def has_state(self):
return True

@register_to_config
def __init__(
self,
Expand Down
4 changes: 4 additions & 0 deletions src/diffusers/schedulers/scheduling_pndm_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class FlaxPNDMScheduler(SchedulerMixin, ConfigMixin):
stable diffusion.
"""

@property
def has_state(self):
return True

@register_to_config
def __init__(
self,
Expand Down