@@ -91,9 +91,6 @@ class ConfigMixin:
9191 def register_to_config (self , ** kwargs ):
9292 if self .config_name is None :
9393 raise NotImplementedError (f"Make sure that { self .__class__ } has defined a class name `config_name`" )
94- kwargs ["_class_name" ] = self .__class__ .__name__
95- kwargs ["_diffusers_version" ] = __version__
96-
9794 # Special case for `kwargs` used in deprecation warning added to schedulers
9895 # TODO: remove this when we remove the deprecation warning, and the `kwargs` argument,
9996 # or solve in a more general way.
@@ -462,7 +459,7 @@ def extract_init_dict(cls, config_dict, **kwargs):
462459 unused_kwargs = {** config_dict , ** kwargs }
463460
464461 # 7. Define "hidden" config parameters that were saved for compatible classes
465- hidden_config_dict = {k : v for k , v in original_dict .items () if k not in init_dict and not k . startswith ( "_" ) }
462+ hidden_config_dict = {k : v for k , v in original_dict .items () if k not in init_dict }
466463
467464 return init_dict , unused_kwargs , hidden_config_dict
468465
@@ -493,6 +490,9 @@ def to_json_string(self) -> str:
493490 `str`: String containing all the attributes that make up this configuration instance in JSON format.
494491 """
495492 config_dict = self ._internal_dict if hasattr (self , "_internal_dict" ) else {}
493+ config_dict ["_class_name" ] = self .__class__ .__name__
494+ config_dict ["_diffusers_version" ] = __version__
495+
496496 return json .dumps (config_dict , indent = 2 , sort_keys = True ) + "\n "
497497
498498 def to_json_file (self , json_file_path : Union [str , os .PathLike ]):
@@ -520,6 +520,7 @@ def register_to_config(init):
520520 def inner_init (self , * args , ** kwargs ):
521521 # Ignore private kwargs in the init.
522522 init_kwargs = {k : v for k , v in kwargs .items () if not k .startswith ("_" )}
523+ config_init_kwargs = {k : v for k , v in kwargs .items () if k .startswith ("_" )}
523524 init (self , * args , ** init_kwargs )
524525 if not isinstance (self , ConfigMixin ):
525526 raise RuntimeError (
@@ -545,6 +546,7 @@ def inner_init(self, *args, **kwargs):
545546 if k not in ignore and k not in new_kwargs
546547 }
547548 )
549+ new_kwargs = {** config_init_kwargs , ** new_kwargs }
548550 getattr (self , "register_to_config" )(** new_kwargs )
549551
550552 return inner_init
@@ -562,7 +564,7 @@ def init(self, *args, **kwargs):
562564 )
563565
564566 # Ignore private kwargs in the init. Retrieve all passed attributes
565- init_kwargs = {k : v for k , v in kwargs .items () if not k . startswith ( "_" ) }
567+ init_kwargs = {k : v for k , v in kwargs .items ()}
566568
567569 # Retrieve default values
568570 fields = dataclasses .fields (self )
0 commit comments