o
    ×ôj€  ã                   @   s*  d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZmZmZmZ ddlZddlmZmZ ddlmZmZmZmZ ddlmZ d	d
lmZ d	dlm Z m!Z!m"Z"m#Z#m$Z$m%Z% e% &e'¡Z(e )d¡Z*G dd„ de	ƒZ+G dd„ dƒZ,dd„ Z-dd„ Z.G dd„ de,ƒZ/dS )z%ConfigMixin base class and utilities.é    N)ÚOrderedDict)Ú	PosixPath)ÚAnyÚDictÚTupleÚUnion)Úcreate_repoÚhf_hub_download)ÚEntryNotFoundErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErrorÚvalidate_hf_hub_args)Ú	HTTPErroré   )Ú__version__)ÚHUGGINGFACE_CO_RESOLVE_ENDPOINTÚDummyObjectÚ	deprecateÚextract_commit_hashÚhttp_user_agentÚloggingzconfig\.(.*)\.jsonc                       sT   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Z‡ fdd„Z‡ fdd„Z	‡  Z
S )Ú
FrozenDictc                    s:   t ƒ j|i |¤Ž |  ¡ D ]
\}}t| ||ƒ qd| _d S )NT)ÚsuperÚ__init__ÚitemsÚsetattrÚ_FrozenDict__frozen)ÚselfÚargsÚkwargsÚkeyÚvalue©Ú	__class__© úp/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/diffusers/configuration_utils.pyr   8   s   
zFrozenDict.__init__c                 O   ó   t d| jj› d�ƒ‚)Nz$You cannot use ``__delitem__`` on a ú
 instance.©Ú	Exceptionr#   Ú__name__©r   r   r   r$   r$   r%   Ú__delitem__@   ó   zFrozenDict.__delitem__c                 O   r&   )Nz#You cannot use ``setdefault`` on a r'   r(   r+   r$   r$   r%   Ú
setdefaultC   r-   zFrozenDict.setdefaultc                 O   r&   )NzYou cannot use ``pop`` on a r'   r(   r+   r$   r$   r%   ÚpopF   r-   zFrozenDict.popc                 O   r&   )NzYou cannot use ``update`` on a r'   r(   r+   r$   r$   r%   ÚupdateI   r-   zFrozenDict.updatec                    ó6   t | dƒr| jrtd| jj› d�ƒ‚tƒ  ||¡ d S ©NÚ__frozenz$You cannot use ``__setattr__`` on a r'   )Úhasattrr   r)   r#   r*   r   Ú__setattr__©r   Únamer!   r"   r$   r%   r5   L   ó   zFrozenDict.__setattr__c                    r1   r2   )r4   r   r)   r#   r*   r   Ú__setitem__r6   r"   r$   r%   r9   Q   r8   zFrozenDict.__setitem__)r*   Ú
__module__Ú__qualname__r   r,   r.   r/   r0   r5   r9   Ú__classcell__r$   r$   r"   r%   r   7   s    r   c                   @   sF  e Zd ZdZdZg ZdZg Zdd„ Zde	de
fdd	„Zd&d
ee	ejf defdd„Zed'deeee	e
f f fdd„ƒZedd„ ƒZee		d(dee	ejf deee	e
f ee	e
f f fdd„ƒƒZedd„ ƒZedd„ ƒZedee	ejf fdd„ƒZdd„ Zedee	e
f fdd „ƒZde	fd!d"„Z d#ee	ejf fd$d%„Z!dS ))ÚConfigMixinaõ  
    Base class for all configuration classes. All configuration parameters are stored under `self.config`. Also
    provides the [`~ConfigMixin.from_config`] and [`~ConfigMixin.save_config`] methods for loading, downloading, and
    saving classes that inherit from [`ConfigMixin`].

    Class attributes:
        - **config_name** (`str`) -- A filename under which the config should stored when calling
          [`~ConfigMixin.save_config`] (should be overridden by parent class).
        - **ignore_for_config** (`List[str]`) -- A list of attributes that should not be saved in the config (should be
          overridden by subclass).
        - **has_compatibles** (`bool`) -- Whether the class has compatible classes (should be overridden by subclass).
        - **_deprecated_kwargs** (`List[str]`) -- Keyword arguments that are deprecated. Note that the `init` function
          should only have a `kwargs` argument if at least one argument is deprecated (should be overridden by
          subclass).
    NFc                 K   st   | j d u rtd| j› d�ƒ‚| dd ¡ t| dƒs|}nt| jƒ}i | j¥|¥}t d|› d|› �¡ t	|ƒ| _d S )NzMake sure that z' has defined a class name `config_name`r   Ú_internal_dictzUpdating config from z to )
Úconfig_nameÚNotImplementedErrorr#   r/   r4   Údictr>   ÚloggerÚdebugr   )r   r   Zinternal_dictZprevious_dictr$   r$   r%   Úregister_to_confign   s   


zConfigMixin.register_to_configr7   Úreturnc                 C   s’   d| j v ot| j d |ƒ}|| j v }|r;|s;d|› dt| ƒj› d|› dt| ƒj› d|› d�}tdd	|d
d� | j| S tdt| ƒj› d|› d�ƒ‚)aW  The only reason we overwrite `getattr` here is to gracefully deprecate accessing
        config attributes directly. See https://github.com/huggingface/diffusers/pull/3129

        This function is mostly copied from PyTorch's __getattr__ overwrite:
        https://pytorch.org/docs/stable/_modules/torch/nn/modules/module.html#Module
        r>   zAccessing config attribute `z` directly via 'z1' object attribute is deprecated. Please access 'z' over 'z1's config object instead, e.g. 'scheduler.config.z'.zdirect config name accessú1.0.0F©Ústandard_warnú'z' object has no attribute ')Ú__dict__r4   Útyper*   r   r>   ÚAttributeError)r   r7   Zis_in_configZis_attributeÚdeprecation_messager$   r$   r%   Ú__getattr__   s   
0
zConfigMixin.__getattr__Úsave_directoryÚpush_to_hubc           
      K   sÐ   t j |¡rtd|› d�ƒ‚t j|dd� t j || j¡}|  |¡ t 	d|› �¡ |rf| 
dd¡}| 
dd	¡}| 
d
d	¡}| 
dd¡}| 
d| t jj¡d ¡}	t|	d||d�j}	| j||	|||d� dS dS )aI  
        Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the
        [`~ConfigMixin.from_config`] class method.

        Args:
            save_directory (`str` or `os.PathLike`):
                Directory where the configuration JSON file is saved (will be created if it does not exist).
            push_to_hub (`bool`, *optional*, defaults to `False`):
                Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the
                repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
                namespace).
            kwargs (`Dict[str, Any]`, *optional*):
                Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
        zProvided path (z#) should be a directory, not a fileT)Úexist_okzConfiguration saved in Úcommit_messageNÚprivateFÚ	create_prÚtokenÚrepo_idéÿÿÿÿ)rQ   rS   rU   )rU   rR   rT   )ÚosÚpathÚisfileÚAssertionErrorÚmakedirsÚjoinr?   Úto_json_filerB   Úinfor/   ÚsplitÚsepr   rV   Ú_upload_folder)
r   rO   rP   r   Úoutput_config_filerR   rS   rT   rU   rV   r$   r$   r%   Úsave_config‘   s*   

ûøzConfigMixin.save_configÚconfigc           
      K   s2  d|v r	|  d¡}|du rtdƒ‚t|tƒsKd}d| jv r&|d| › d�7 }nd| jv r6|d	| › d
| › d�7 }tdd|dd� | jd|ddœ|¤Ž\}}| j|fi |¤Ž\}}}d|v rb|  d¡|d< | jD ]}||v rr|  |¡||< qe| di |¤Ž}	d|v rƒ| j|d< |	j	di |¤Ž i |¥|¥}|r—|	|fS |	S )a
  
        Instantiate a Python class from a config dictionary.

        Parameters:
            config (`Dict[str, Any]`):
                A config dictionary from which the Python class is instantiated. Make sure to only load configuration
                files of compatible classes.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                Whether kwargs that are not consumed by the Python class should be returned or not.
            kwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to update the configuration object (after it is loaded) and initiate the Python class.
                `**kwargs` are passed directly to the underlying scheduler/model's `__init__` method and eventually
                overwrite the same named arguments in `config`.

        Returns:
            [`ModelMixin`] or [`SchedulerMixin`]:
                A model or scheduler object instantiated from a config dictionary.

        Examples:

        ```python
        >>> from diffusers import DDPMScheduler, DDIMScheduler, PNDMScheduler

        >>> # Download scheduler from huggingface.co and cache.
        >>> scheduler = DDPMScheduler.from_pretrained("google/ddpm-cifar10-32")

        >>> # Instantiate DDIM scheduler class with same config as DDPM
        >>> scheduler = DDIMScheduler.from_config(scheduler.config)

        >>> # Instantiate PNDM scheduler class with same config as DDPM
        >>> scheduler = PNDMScheduler.from_config(scheduler.config)
        ```
        Úpretrained_model_name_or_pathNzFPlease make sure to provide a config as the first positional argument.zJIt is deprecated to pass a pretrained model name or path to `from_config`.Ú	Schedulerz3If you were trying to load a scheduler, please use z”.from_pretrained(...) instead. Otherwise, please make sure to pass a configuration dictionary instead. This functionality will be removed in v1.0.0.ÚModelz/If you were trying to load a model, please use z.load_config(...) followed by z�.from_config(...) instead. Otherwise, please make sure to pass a configuration dictionary instead. This functionality will be removed in v1.0.0.zconfig-passed-as-pathrF   FrG   T)rf   Úreturn_unused_kwargsÚdtypeÚ_class_namer$   )
r/   Ú
ValueErrorÚ
isinstancerA   r*   r   Úload_configÚextract_init_dictÚ_deprecated_kwargsrD   )
Úclsre   ri   r   rM   Ú	init_dictÚunused_kwargsZhidden_dictZdeprecated_kwargÚmodelr$   r$   r%   Úfrom_config»   sB   %



ÿ
ÿÿ
€
zConfigMixin.from_configc                 O   s,   d| › d�}t dd|dd� | j|i |¤ŽS )Nz8 The function get_config_dict is deprecated. Please use zE.load_config instead. This function will be removed in version v1.0.0Úget_config_dictrF   FrG   )r   rn   )rq   r   r   rM   r$   r$   r%   rv     s   
ÿzConfigMixin.get_config_dictrf   c                 K   sÜ  |  dd¡}|  dd¡}|  dd¡}|  dd¡}|  dd¡}	|  d	d¡}
|  d
d¡}|  dd¡}|  dd¡}|  dd¡}|  dd¡}|  di ¡}i |¥ddi¥}t|ƒ}t|ƒ}| jdu ratdƒ‚tj |¡rj|}nÈtj |¡r¬|dur‹tj tj 	||| j¡¡r‹tj 	||| j¡}n§tj tj 	|| j¡¡r tj 	|| j¡}n’t
d| j› d|› d�ƒ‚zt|| j|||
|	|||||||d�}W nq tyÎ   t
|› d�ƒ‚ tyÞ   t
|› d|› d�ƒ‚ tyï   t
|› d| j› d�ƒ‚ t�y } z
t
d|› d|› �ƒ‚d}~w t�y   t
dt› d|› d| j› d �ƒ‚ t
�y1   t
d!|› d"|› d#| j› d$�ƒ‚w z|  |¡}t|ƒ}W n tjtf�yP   t
d%|› d&�ƒ‚w |�sY|�sY|S |f}|�rd||f7 }|�rl||f7 }|S )'aN  
        Load a model or scheduler configuration.

        Parameters:
            pretrained_model_name_or_path (`str` or `os.PathLike`, *optional*):
                Can be either:

                    - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on
                      the Hub.
                    - A path to a *directory* (for example `./my_model_directory`) containing model weights saved with
                      [`~ConfigMixin.save_config`].

            cache_dir (`Union[str, os.PathLike]`, *optional*):
                Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
                is not used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force the (re-)download of the model weights and configuration files, overriding the
                cached versions if they exist.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible. Will be removed in v1
                of Diffusers.
            proxies (`Dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
            output_loading_info(`bool`, *optional*, defaults to `False`):
                Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
            local_files_only (`bool`, *optional*, defaults to `False`):
                Whether to only load local model weights and configuration files or not. If set to `True`, the model
                won't be downloaded from the Hub.
            token (`str` or *bool*, *optional*):
                The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
                `diffusers-cli login` (stored in `~/.huggingface`) is used.
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
                allowed by Git.
            subfolder (`str`, *optional*, defaults to `""`):
                The subfolder location of a model file within a larger model repository on the Hub or locally.
            return_unused_kwargs (`bool`, *optional*, defaults to `False):
                Whether unused keyword arguments of the config are returned.
            return_commit_hash (`bool`, *optional*, defaults to `False):
                Whether the `commit_hash` of the loaded configuration are returned.

        Returns:
            `dict`:
                A dictionary of all the parameters stored in a JSON configuration file.

        Ú	cache_dirNÚ	local_dirÚlocal_dir_use_symlinksÚautoÚforce_downloadFÚresume_downloadÚproxiesrU   Úlocal_files_onlyÚrevisionÚmirrorÚ	subfolderÚ
user_agentÚ	file_typere   z¯`self.config_name` is not defined. Note that one should not load a config from `ConfigMixin`. Please make sure to define `config_name` in a class inheriting from `ConfigMixin`zError no file named z found in directory Ú.)Úfilenamerw   r{   r}   r|   r~   rU   r‚   r�   r   rx   ry   zó is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `token` or log in with `huggingface-cli login`.z• is not a valid git identifier (branch name, tag name or commit id) that exists for this model name. Check the model page at 'https://huggingface.co/z' for available revisions.z& does not appear to have a file named z:There was a specific connection error when trying to load z:
zWe couldn't connect to 'zM' to load this model, couldn't find it in the cached files and it looks like z- is not the path to a directory containing a zœ file.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'.zCan't load config for 'zœ'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z2' is the correct path to a directory containing a z filez"It looks like the config file at 'z' is not a valid JSON file.)r/   r   Ústrr?   rl   rX   rY   rZ   Úisdirr]   ÚEnvironmentErrorr	   r   r   r
   r   r   Ú_dict_from_json_filer   ÚjsonÚJSONDecodeErrorÚUnicodeDecodeError)rq   rf   ri   Zreturn_commit_hashr   rw   rx   ry   r{   r|   r}   rU   r~   r   Ú_r�   r‚   Úconfig_fileÚerrÚconfig_dictÚcommit_hashÚoutputsr$   r$   r%   rn     sÊ   8
ÿÿÿ
óÿþÿÿÿÿÿ€ÿþÿþýÿÿ
ÿ

zConfigMixin.load_configc                 C   s   t tt | j¡jƒ ¡ ƒS ©N)ÚsetrA   ÚinspectÚ	signaturer   Ú
parametersÚkeys)Zinput_classr$   r$   r%   Ú_get_init_keysÈ  s   zConfigMixin._get_init_keysc              	      s€  |  dg ¡‰‡fdd„| ¡ D ƒ}t| ¡ ƒ}|  | ¡}| d¡ d|v r*| d¡ t| dƒr:| jD ]}| |¡ q2t| jƒdkrH|t	| jƒ }t
 t d¡d ¡}| jr_d	d
„ |  ¡ D ƒ}ng }t	ƒ ‰ |D ]}|  |¡}	ˆ  |	¡‰ qfˆ |  | ¡ ‰ ‡ fdd„| ¡ D ƒ}| d| j¡}
t|
tƒr³|
| jkr³t||
ƒr³t||
ƒ}|  |¡| ‰‡fdd„| ¡ D ƒ}nt|
tƒsÃt|
ttfƒsÃtdƒ‚dd„ | ¡ D ƒ}i ‰|D ](}||v rá||v rá| |¡||< ||v rí| |¡ˆ|< qÐ||v rø| |¡ˆ|< qÐt|ƒdk�rt d|› d| j› d| j› d�¡ t	ˆ ¡ ƒ}t|| ƒdk�r*t || › d�¡ i |¥|¥}‡fdd„| ¡ D ƒ}ˆ||fS )NÚ_use_default_valuesc                    s&   i | ]\}}|ˆ vr|d kr||“qS )rš   r$   ©Ú.0ÚkÚv)Úused_defaultsr$   r%   Ú
<dictcomp>Ð  s   & z1ConfigMixin.extract_init_dict.<locals>.<dictcomp>r   r   Ú_flax_internal_argsr   r„   c                 S   s   g | ]	}t |tƒs|‘qS r$   )rm   r   )rœ   Úcr$   r$   r%   Ú
<listcomp>é  ó    z1ConfigMixin.extract_init_dict.<locals>.<listcomp>c                    ó   i | ]\}}|ˆ vr||“qS r$   r$   r›   )Úexpected_keys_comp_clsr$   r%   r    ò  ó    rk   c                    r¥   r$   r$   r›   )Úunexpected_keys_from_origr$   r%   r    ý  r§   z\Make sure that the `_class_name` is of type string or list of string (for custom pipelines).c                 S   ó    i | ]\}}|  d ¡s||“qS ©r�   ©Ú
startswithr›   r$   r$   r%   r      ó     zThe config attributes z were passed to z?, but are not expected and will be ignored. Please verify your z configuration file.zG was not found in config. Values will be initialized to default values.c                    r¥   r$   r$   r›   )rr   r$   r%   r    (  r§   )Úgetr   rA   r™   Úremover4   r¡   ÚlenÚignore_for_configr”   Ú	importlibÚimport_moduler*   r`   Úhas_compatiblesZ_get_compatiblesÚunionr/   rm   r†   ÚgetattrÚlistÚtuplerl   rB   Úwarningr?   r˜   r_   )rq   r�   r   Zoriginal_dictÚexpected_keysÚargZdiffusers_libraryZcompatible_classesr¢   Zexpected_keys_cZorig_cls_nameÚorig_clsr    Zpassed_keysrs   Zhidden_config_dictr$   )r¦   rr   r¨   rŸ   r%   ro   Ì  sv   





ÿ
ÿ
ÿ€þÿÿ
zConfigMixin.extract_init_dictÚ	json_filec                 C   s@   t |ddd��}| ¡ }W d   ƒ n1 sw   Y  t |¡S )NÚrúutf-8©Úencoding)ÚopenÚreadrŠ   Úloads)rq   r½   ÚreaderÚtextr$   r$   r%   r‰   ,  s   
ÿ
z ConfigMixin._dict_from_json_filec                 C   s   | j j› d|  ¡ › �S )Nú )r#   r*   Úto_json_string©r   r$   r$   r%   Ú__repr__2  s   zConfigMixin.__repr__c                 C   s   | j S )z�
        Returns the config of the class as a frozen dictionary

        Returns:
            `Dict[str, Any]`: Config of the class.
        )r>   rÉ   r$   r$   r%   re   5  s   zConfigMixin.configc                    sr   t | dƒr| jni }| jj|d< t|d< dd„ ‰ ‡ fdd„| ¡ D ƒ}| dd	¡ | d
d	¡ tj|ddd�d S )zÛ
        Serializes the configuration instance to a JSON string.

        Returns:
            `str`:
                String containing all the attributes that make up the configuration instance in JSON format.
        r>   rk   Z_diffusers_versionc                 S   s.   t | tjƒr|  ¡ } | S t | tƒrt| ƒ} | S r“   )rm   ÚnpÚndarrayÚtolistr   r†   )r!   r$   r$   r%   Úto_json_saveableK  s   
þz4ConfigMixin.to_json_string.<locals>.to_json_saveablec                    s   i | ]	\}}|ˆ |ƒ“qS r$   r$   r›   ©rÎ   r$   r%   r    R  r¤   z.ConfigMixin.to_json_string.<locals>.<dictcomp>Z_ignore_filesNrš   é   T)ÚindentÚ	sort_keysÚ
)	r4   r>   r#   r*   r   r   r/   rŠ   Údumps)r   r�   r$   rÏ   r%   rÈ   ?  s   zConfigMixin.to_json_stringÚjson_file_pathc                 C   sB   t |ddd��}| |  ¡ ¡ W d  ƒ dS 1 sw   Y  dS )zç
        Save the configuration instance's parameters to a JSON file.

        Args:
            json_file_path (`str` or `os.PathLike`):
                Path to the JSON file to save a configuration instance's parameters.
        Úwr¿   rÀ   N)rÂ   ÚwriterÈ   )r   rÕ   Úwriterr$   r$   r%   r^   Y  s   "ÿzConfigMixin.to_json_file)F©NF)FF)"r*   r:   r;   Ú__doc__r?   r±   r´   rp   rD   r†   r   rN   r   rX   ÚPathLikeÚboolrd   Úclassmethodr   r   ru   rv   r   r   rn   Ústaticmethodr™   ro   r‰   rÊ   Úpropertyre   rÈ   r^   r$   r$   r$   r%   r=   W   sD    *"Y
üþú )

_	r=   c                    s   t  ˆ ¡‡ fdd„ƒ}|S )a²  
    Decorator to apply on the init of classes inheriting from [`ConfigMixin`] so that all the arguments are
    automatically sent to `self.register_for_config`. To ignore a specific argument accepted by the init but that
    shouldn't be registered in the config, use the `ignore_for_config` class variable

    Warning: Once decorated, all private arguments (beginning with an underscore) are trashed and not sent to the init!
    c                    s*  dd„ |  ¡ D ƒ‰dd„ |  ¡ D ƒ}t| tƒs!td| jj› d�ƒ‚t| dg ƒ‰ i ‰t ˆ¡}‡ fdd„t	|j
  ¡ ƒD ƒ}t|| ¡ ƒD ]\}}|ˆ|< qCˆ ‡ ‡‡fdd„|  ¡ D ƒ¡ ttˆ ¡ ƒtˆƒ ƒd	krxttˆ ¡ ƒtˆƒ ƒˆd
< i |¥ˆ¥‰t| dƒdi ˆ¤Ž ˆ| g|¢R i ˆ¤Ž d S )Nc                 S   r©   rª   r«   r›   r$   r$   r%   r    q  r­   z:register_to_config.<locals>.inner_init.<locals>.<dictcomp>c                 S   s    i | ]\}}|  d ¡r||“qS rª   r«   r›   r$   r$   r%   r    r  r­   ú&`@register_for_config` was applied to úA init method, but this class does not inherit from `ConfigMixin`.r±   c                    s,   i | ]\}\}}|d kr|ˆ vr||j “qS )r   )Údefault)rœ   Úir7   Úp)Úignorer$   r%   r    }  s    &c                    s.   i | ]\}}|ˆ vr|ˆvr|ˆ  ||¡“qS r$   )r®   )rœ   r�   râ   ©rå   Úinit_kwargsÚ
new_kwargsr$   r%   r    …  s
    þr   rš   rD   r$   )r   rm   r=   ÚRuntimeErrorr#   r*   r¶   r•   r–   Ú	enumerater—   Úzipr˜   r0   r°   r”   r·   )r   r   r   Zconfig_init_kwargsr–   r—   r»   r7   ©Úinitræ   r%   Ú
inner_initn  s0   
ÿ

ÿ
þÿ	z&register_to_config.<locals>.inner_init)Ú	functoolsÚwraps)rí   rî   r$   rì   r%   rD   e  s   	%rD   c                    s&   | j ‰ t ˆ ¡‡ fdd„ƒ}|| _ | S )Nc                    s&  t | tƒstd| jj› d�ƒ‚t| ¡ ƒ}t | ¡}i }|D ] }|j	| j
v r'qt|jƒtjkr5d ||j	< qt| |j	ƒ||j	< qi |¥|¥}d|v rN| d¡ t|ƒD ]\}}	|| j	}
|	||
< qRtt| ¡ ƒt|ƒ ƒdkr|tt| ¡ ƒt|ƒ ƒ|d< t| dƒdi |¤Ž ˆ | g|¢R i |¤Ž d S )Nrà   rá   rj   r   rš   rD   r$   )rm   r=   ré   r#   r*   rA   r   ÚdataclassesÚfieldsr7   r¡   rK   râ   Ú_MISSING_TYPEr¶   r/   rê   r°   r”   r˜   r·   )r   r   r   rç   rò   Údefault_kwargsÚfieldrè   rã   r»   r7   ©Úoriginal_initr$   r%   rí   š  s.   
ÿ



z%flax_register_to_config.<locals>.init)r   rï   rð   )rq   rí   r$   rö   r%   Úflax_register_to_config—  s
   (rø   c                   @   s4   e Zd ZdZeddeeeee	f f fdd„ƒZ
dS )ÚLegacyConfigMixinz´
    A subclass of `ConfigMixin` to resolve class mapping from legacy classes (like `Transformer2DModel`) to more
    pipeline-specific classes (like `DiTTransformer2DModel`).
    NFre   c                 K   s*   ddl m} ||| ƒ}|j||fi |¤ŽS )Nr   )Ú_fetch_remapped_cls_from_config)Zmodels.model_loading_utilsrú   ru   )rq   re   ri   r   rú   Zremapped_classr$   r$   r%   ru   Í  s   
zLegacyConfigMixin.from_configrÙ   )r*   r:   r;   rÚ   rÝ   r   r   r   r†   r   ru   r$   r$   r$   r%   rù   Ç  s    &rù   )0rÚ   rñ   rï   r²   r•   rŠ   rX   ÚreÚcollectionsr   Úpathlibr   Útypingr   r   r   r   ÚnumpyrË   Úhuggingface_hubr   r	   Úhuggingface_hub.utilsr
   r   r   r   Úrequestsr   Ú r   Úutilsr   r   r   r   r   r   Ú
get_loggerr*   rB   ÚcompileZ_re_configuration_filer   r=   rD   rø   rù   r$   r$   r$   r%   Ú<module>   s8    


     20