MCPcopy Create free account
hub / github.com/AlayaLab/Hive / init

Function init

models/flowsep/diffusers/configuration_utils.py:620–654  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

618
619 @functools.wraps(original_init)
620 def init(self, *args, **kwargs):
621 if not isinstance(self, ConfigMixin):
622 raise RuntimeError(
623 f"`@register_for_config` was applied to {self.__class__.__name__} init method, but this class does "
624 "not inherit from `ConfigMixin`."
625 )
626
627 # Ignore private kwargs in the init. Retrieve all passed attributes
628 init_kwargs = dict(kwargs.items())
629
630 # Retrieve default values
631 fields = dataclasses.fields(self)
632 default_kwargs = {}
633 for field in fields:
634 # ignore flax specific attributes
635 if field.name in self._flax_internal_args:
636 continue
637 if type(field.default) == dataclasses._MISSING_TYPE:
638 default_kwargs[field.name] = None
639 else:
640 default_kwargs[field.name] = getattr(self, field.name)
641
642 # Make sure init_kwargs override default kwargs
643 new_kwargs = {**default_kwargs, **init_kwargs}
644 # dtype should be part of `init_kwargs`, but not `new_kwargs`
645 if "dtype" in new_kwargs:
646 new_kwargs.pop("dtype")
647
648 # Get positional arguments aligned with kwargs
649 for i, arg in enumerate(args):
650 name = fields[i].name
651 new_kwargs[name] = arg
652
653 getattr(self, "register_to_config")(**new_kwargs)
654 original_init(self, *args, **kwargs)
655
656 cls.__init__ = init
657 return cls

Callers 1

inner_initFunction · 0.85

Calls 1

popMethod · 0.45

Tested by

no test coverage detected