Ë
    (täi��  ã                   óh  — 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 ddlZddlmZmZmZ ddlmZ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$jJ                  e&«      Z' ejP                  d«      Z) G d„ de	«      Z* G d„ d«      Z+d„ Z,d„ Z- G d„ de+«      Z.y)z%ConfigMixin base class and utilities.é    N)ÚOrderedDict)ÚPath)ÚAny)Ú	DDUFEntryÚcreate_repoÚhf_hub_download)ÚEntryNotFoundErrorÚHfHubHTTPErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErrorÚvalidate_hf_hub_args)ÚSelfé   )Ú__version__)ÚHUGGINGFACE_CO_RESOLVE_ENDPOINTÚDummyObjectÚ	deprecateÚextract_commit_hashÚhttp_user_agentÚloggingzconfig\.(.*)\.jsonc                   óJ   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zd„ Zd„ Zˆ fd„Zˆ fd„Z	ˆ xZ
S )Ú
FrozenDictc                 ó|   •— t        ‰| �  |i |¤Ž | j                  «       D ]  \  }}t        | ||«       Œ d| _        y )NT)ÚsuperÚ__init__ÚitemsÚsetattrÚ_FrozenDict__frozen)ÚselfÚargsÚkwargsÚkeyÚvalueÚ	__class__s        €úl/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/diffusers/configuration_utils.pyr   zFrozenDict.__init__9   s>   ø€ Ü‰Ñ˜$Ð) &Ò)àŸ*™*ž,‰JˆC�Ü�D˜#˜uÕ%ð 'ð ˆ�ó    c                 óH   — t        d| j                  j                  › d�«      ‚)Nz$You cannot use ``__delitem__`` on a ú
 instance.©Ú	Exceptionr$   Ú__name__©r   r    r!   s      r%   Ú__delitem__zFrozenDict.__delitem__A   s#   € ÜÐ>¸t¿~¹~×?VÑ?VÐ>WÐWaÐbÓcÐcr&   c                 óH   — t        d| j                  j                  › d�«      ‚)Nz#You cannot use ``setdefault`` on a r(   r)   r,   s      r%   Ú
setdefaultzFrozenDict.setdefaultD   s#   € ÜÐ=¸d¿n¹n×>UÑ>UÐ=VÐV`ÐaÓbÐbr&   c                 óH   — t        d| j                  j                  › d�«      ‚)NzYou cannot use ``pop`` on a r(   r)   r,   s      r%   ÚpopzFrozenDict.popG   s"   € ÜÐ6°t·~±~×7NÑ7NÐ6OÈzÐZÓ[Ð[r&   c                 óH   — t        d| j                  j                  › d�«      ‚)NzYou cannot use ``update`` on a r(   r)   r,   s      r%   ÚupdatezFrozenDict.updateJ   s#   € ÜÐ9¸$¿.¹.×:QÑ:QÐ9RÐR\Ð]Ó^Ð^r&   c                 óœ   •— t        | d«      r/| j                  r#t        d| j                  j                  › d�«      ‚t
        ‰| �  ||«       y ©NÚ__frozenz$You cannot use ``__setattr__`` on a r(   )Úhasattrr   r*   r$   r+   r   Ú__setattr__©r   Únamer#   r$   s      €r%   r8   zFrozenDict.__setattr__M   óC   ø€ Ü�4˜Ô$¨¯ªÜÐBÀ4Ç>Á>×CZÑCZÐB[Ð[eÐfÓgÐgÜ‰Ñ˜D %Õ(r&   c                 óœ   •— t        | d«      r/| j                  r#t        d| j                  j                  › d�«      ‚t
        ‰| �  ||«       y r5   )r7   r   r*   r$   r+   r   Ú__setitem__r9   s      €r%   r=   zFrozenDict.__setitem__R   r;   r&   )r+   Ú
__module__Ú__qualname__r   r-   r/   r1   r3   r8   r=   Ú__classcell__©r$   s   @r%   r   r   8   s/   ø„ ôòdòcò\ò_ô)÷
)ð )r&   r   c                   ó  — e Zd ZdZdZg ZdZg ZdZe	dd„«       Z
d„ Zdedefd„Zdd	eej                   z  d
efd„Ze		 ddeeeef   z  deeeeeef   f   z  fd„«       Ze	d„ «       Ze	e	 	 ddeej                   z  deeeef   eeef   f   fd„«       «       Zed„ «       Ze	d„ «       Ze	d deej                   z  deeef   dz  fd„«       Zd„ Z e!deeef   fd„«       Z"defd„Z#deej                   z  fd„Z$e	dedeeef   fd„«       Z%y)!Ú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                 ó:   — |dk7  rt        d|› d�«      ‚|| _        y)a4  
        Register this class with the given auto class so that it can be loaded with `AutoModel.from_pretrained(...,
        trust_remote_code=True)`.

        When the config is saved, the resulting `config.json` will include an `auto_map` entry mapping the auto class
        to this class's module and class name.

        Args:
            auto_class (`str` or type, *optional*, defaults to `"AutoModel"`):
                The auto class to register this class with. Can be a string (e.g. `"AutoModel"`) or the class itself.
                Currently only `"AutoModel"` is supported.

        Example:

        ```python
        from diffusers import ModelMixin, ConfigMixin


        class MyCustomModel(ModelMixin, ConfigMixin): ...


        MyCustomModel.register_for_auto_class("AutoModel")
        ```
        Ú	AutoModelz$Only 'AutoModel' is supported, got 'ú'.N)Ú
ValueErrorÚ_auto_class)ÚclsÚ
auto_classs     r%   Úregister_for_auto_classz#ConfigMixin.register_for_auto_classp   s(   € ð4 ˜Ò$ÜÐCÀJÀ<ÈrÐRÓSÐSà$ˆ�r&   c                 ó0  — | j                   €t        d| j                  › d�«      ‚|j                  dd «       t	        | d«      s|}n@t        | j                  «      }i | j                  ¥|¥}t        j                  d|› d|› �«       t        |«      | _        y )NzMake sure that z' has defined a class name `config_name`r!   Ú_internal_dictzUpdating config from z to )
Úconfig_nameÚNotImplementedErrorr$   r1   r7   ÚdictrM   ÚloggerÚdebugr   )r   r!   Úinternal_dictÚprevious_dicts       r%   Úregister_to_configzConfigMixin.register_to_config�   s”   € Ø×ÑÐ#Ü%¨¸¿¹Ð7GÐGnÐ&oÓpÐpð 	�
‰
�8˜TÔ"ä�tÐ-Ô.Ø"‰Mä  ×!4Ñ!4Ó5ˆMØ=˜t×2Ñ2Ð=°fÐ=ˆMÜ�L‰LÐ0°°¸tÀMÀ?ÐSÔTä(¨Ó7ˆÕr&   r:   Úreturnc                 ón  — d| j                   v xr t        | j                   d   |«      }|| j                   v }|rX|sVd|› dt        | «      j                  › d|› dt        | «      j                  › d|› d�}t	        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
        rM   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.rF   zdirect config name accessú1.0.0F©Ústandard_warnÚ'z' object has no attribute ')Ú__dict__r7   Útyper+   r   rM   ÚAttributeError)r   r:   Úis_in_configÚis_attributeÚdeprecation_messages        r%   Ú__getattr__zConfigMixin.__getattr__    s  € ð (¨4¯=©=Ð8Òk¼WÀTÇ]Á]ÐScÑEdÐfjÓ=kˆØ˜tŸ}™}Ð,ˆá¡Ø$@ÀÀÐFVÔW[Ð\`ÓWa×WjÑWjÐVkð  l]ð  ^bð  ]cð  ckô  lpð  quó  lv÷  lñ  lð  k@ð  @qð  rvð  qwð  wyð  #zÐÜÐ1°7Ð<OÐ_dÕeØ×&Ñ& tÑ,Ð,ä˜q¤ d£×!4Ñ!4Ð 5Ð5PÐQUÐPVÐVWÐXÓYÐYr&   Úsave_directoryÚpush_to_hubc                 óÆ  — t         j                  j                  |«      rt        d|› d�«      ‚t        j                  |d¬«       t         j                  j                  || j                  «      }| j                  |«       t        j                  d|› �«       |rÇ|j                  dd«      }|j                  dd«      }|j                  d	d
«      }|j                  dd«      }|j                  d|j                  t         j                  j                  «      d   «      }	t        |	d||¬«      j                  }	|j                  dd«      }
| j                  ||	||||
¬«       yy)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ÚprivateÚ	create_prFÚtokenÚrepo_idéÿÿÿÿ)rf   rh   rj   Ú	subfolder)rj   rg   ri   rm   )ÚosÚpathÚisfileÚAssertionErrorÚmakedirsÚjoinrN   Úto_json_filerQ   Úinfor1   ÚsplitÚsepr   rk   Ú_upload_folder)r   rc   rd   r!   Úoutput_config_filerg   rh   ri   rj   rk   rm   s              r%   Úsave_configzConfigMixin.save_config²   s7  € ô �7‰7�>‰>˜.Ô)Ü  ?°>Ð2BÐBeÐ!fÓgÐgä
�‰�N¨TÕ2ô  ŸW™WŸ\™\¨.¸$×:JÑ:JÓKÐà×ÑÐ,Ô-Ü�‰Ð-Ð.@Ð-AÐBÔCáØ#ŸZ™ZÐ(8¸$Ó?ˆNØ—j‘j ¨DÓ1ˆGØŸ
™
 ;°Ó6ˆIØ—J‘J˜w¨Ó-ˆEØ—j‘j ¨N×,@Ñ,@ÄÇÁÇÁÓ,MÈbÑ,QÓRˆGÜ! '°DÀ'ÐQVÔW×_Ñ_ˆGØŸ
™
 ;°Ó5ˆIà×ÑØØØØ-Ø#Ø#ð  õ ð r&   Úconfigc                 óD  — d|v r|j                  d«      }|€t        d«      ‚t        |t        «      s[d}d| j                  v r
|d| › d�z  }nd| j                  v r|d| › d	| › d
�z  }t        dd|d¬«        | j                  d|ddœ|¤Ž\  }} | j                  |fi |¤Ž\  }}}d|v r|j                  d«      |d<   | j                  D ]  }||v sŒ|j                  |«      ||<   Œ  | 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_pathzFPlease 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-pathrX   FrY   T)r}   Úreturn_unused_kwargsÚdtypeÚ_class_name© )
r1   rG   Ú
isinstancerP   r+   r   Úload_configÚextract_init_dictÚ_deprecated_kwargsrU   )
rI   r{   r€   r!   ra   Ú	init_dictÚunused_kwargsÚhidden_dictÚdeprecated_kwargÚmodels
             r%   Úfrom_configzConfigMixin.from_configÞ   s   € ðN +¨fÑ4Ø—Z‘ZÐ ?Ó@ˆFàˆ>ÜÐeÓfÐfô ˜&¤$Ô'Ø"nÐØ˜cŸl™lÑ*Ø#ØIÈ#Èð O-ð -ñÑ#ð
 ˜CŸL™LÑ(Ø#ØEÀcÀUð KØ�uð NðNñÐ#ô
 Ð-¨wÐ8KÐ[`ÕaØ,˜SŸ_™_ÐwÈ6ÐhlÑwÐpvÑw‰NˆF�Fà0E°×0EÑ0EÀfÑ0WÐPVÑ0WÑ-ˆ	�= +ð �mÑ#Ø!.×!2Ñ!2°7Ó!;ˆI�gÑð !$× 6Ô 6ÐØ =Ò0Ø.;×.?Ñ.?Ð@PÓ.Q�	Ð*Ò+ð !7ñ
 Ñ �iÑ ˆð ˜KÑ'Ø),¯©ˆK˜Ñ&à ˆ× Ñ Ñ/ ;Ò/ð 9˜=Ð8¨KÐ8ˆáØ˜=Ð)Ð)àˆLr&   c                 óP   — d| › d�}t        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_dictrX   FrY   )r   r…   )rI   r    r!   ra   s       r%   r�   zConfigMixin.get_config_dict:  sE   € ð GÀsÀeð L)ð )ð 	ô 	Ð# WÐ.AÐQVÕWØˆs�‰ Ð/¨Ñ/Ð/r&   r}   c                 óŒ  — |j                  dd«      }|j                  dd«      }|j                  dd«      }|j                  dd«      }|j                  dd«      }	|j                  d	d«      }
|j                  d
d«      }|j                  dd«      }|j                  dd«      }|j                  dd«      }|j                  di «      }|j                  dd«      }i |¥ddi¥}t        |«      }t        |«      }| j                  €t	        d«      ‚|r!|�t	        d«      ‚| j                  ||«      }�nit        j                  j                  |«      r|}�nFt        j                  j                  |«      �r|�tt        j                  j                  t        j                  j                  ||| j                  «      «      r,t        j                  j                  ||| j                  «      }n°t        j                  j                  t        j                  j                  || j                  «      «      r+t        j                  j                  || j                  «      }n>t        d| j                  › d|› d�«      ‚	 t        || j                  |||	||
|||||¬«      }	 | j%                  ||¬&«      }t'        |«      }|s|s|S |f}|r||fz  }|r||fz  }|S # t        $ r t        |› d�«      ‚t        $ r t        |› d|› d�«      ‚t        $ r t        |› d| j                  › d�«      ‚t         $ r}t        d|› d|› �«      ‚d}~wt        $ r$ t        dt"        › d|› d | j                  › d!�«      ‚t        $ r  t        d"|› d#|› d$| j                  › d%�«      ‚w xY w# t(        j*                  t,        f$ r t        d'|› d(�«      ‚w xY w))a—
  
        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 (`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.
            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Úproxiesrj   Úlocal_files_onlyÚrevisionÚmirrorrm   Ú
user_agentÚdduf_entriesÚ	file_typer{   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ˆDDUF file only allow for 1 level of directory (e.g transformer/model1/model.safetentors is not allowed). Please check the DDUF structurezError no file named z found in directory Ú.)Úfilenamer‘   r•   r–   r—   rj   rš   rm   r˜   r’   r“   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 `hf auth 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 file)r›   z"It looks like the config file at 'z' is not a valid JSON file.)r1   r   ÚstrrN   rG   Ú_get_config_file_from_ddufrn   ro   rp   Úisdirrs   ÚEnvironmentErrorr   r   r   r	   r
   r   Ú_dict_from_json_filer   ÚjsonÚJSONDecodeErrorÚUnicodeDecodeError)rI   r}   r€   Úreturn_commit_hashr!   r‘   r’   r“   r•   r–   rj   r—   r˜   Ú_rm   rš   r›   Úconfig_fileÚerrÚconfig_dictÚcommit_hashÚoutputss                         r%   r…   zConfigMixin.load_configC  s2  € ðj —J‘J˜{¨DÓ1ˆ	Ø—J‘J˜{¨DÓ1ˆ	Ø!'§¡Ð,DÀfÓ!MÐØŸ™Ð$4°eÓ<ˆØ—*‘*˜Y¨Ó-ˆØ—
‘
˜7 DÓ)ˆØ!Ÿ:™:Ð&8¸%Ó@ÐØ—:‘:˜j¨$Ó/ˆØ�J‰J�x Ó&ˆØ—J‘J˜{¨DÓ1ˆ	Ø—Z‘Z ¨bÓ1ˆ
Ø4:·J±J¸~ÈtÓ4Tˆà:˜
Ð: K°Ñ:ˆ
Ü$ ZÓ0ˆ
ä(+Ð,IÓ(JÐ%à�?‰?Ð"Üðsóð ñ
 ØÐ$Ü ð6óð ð ×8Ñ8Ð9VÐXdÓeŠKÜ�W‰W�^‰^Ð9Ô:Ø7ŠKÜ�W‰W�]‰]Ð8Õ9ØÐ$¬¯©¯©Ü—‘—‘Ð:¸IÀsÇÁÓWô*ô !Ÿg™gŸl™lÐ+HÈ)ÐUX×UdÑUdÓe‘Ü—‘—‘¤§¡§¡Ð-JÈCÏOÉOÓ \Ô]ä Ÿg™gŸl™lÐ+HÈ#Ï/É/ÓZ‘ä&Ø*¨3¯?©?Ð*;Ð;OÐPmÐOnÐnoÐpóð ð3ä-Ø1Ø Ÿ_™_Ø'Ø#1Ø#Ø%5ØØ)Ø'Ø%Ø'Ø+Aô�ðd	rØ×2Ñ2°;È\Ð2ÓZˆKä-¨kÓ:ˆKñ %Ñ(:ØÐà�.ˆáØ˜�yÑ ˆGáØ˜�~Ñ%ˆGàˆøôm +ò Ü&Ø4Ð5ð 6ið ióð ô
 )ò Ü&Ø�jð !0à0MÐ/NÐNhðjóð ô
 &ò Ü&Ø4Ð5Ð5[Ð\_×\kÑ\kÐ[lÐlmÐnóð ô "ò Ü&ðØ5Ð6°c¸#¸ð@óð ûô ò Ü&Ø.Ô/NÐ.Oð P>Ø>[Ð=\ð ]/Ø/2¯©Ð.?ð @ZðZóð ô $ò Ü&Ø-Ð.KÐ-Lð M-à-JÐ,Kð L$Ø$'§O¡OÐ#4°Eð;óð ðûô ×$Ñ$Ô&8Ð9ò 	rÜ"Ð%GÈÀ}ÐToÐ#pÓqÐqð	rús&   É9!K ÊN ËANÌ/M Í ANÎ)Oc                 ó”   — t        t        t        j                  | j                  «      j
                  «      j                  «       «      S ©N)ÚsetrP   ÚinspectÚ	signaturer   Ú
parametersÚkeys)Úinput_classs    r%   Ú_get_init_keyszConfigMixin._get_init_keysî  s2   € ä”4œ×)Ñ)¨+×*>Ñ*>Ó?×JÑJÓK×PÑPÓRÓSÐSr&   c           	      ó<  — |j                  dg «      }|j                  «       D ��ci c]  \  }}||vsŒ|dk7  sŒ||“Œ }}}t        |j                  «       «      }| j                  | «      }|j	                  d«       d|v r|j	                  d«       t        | d«      r"| j                  D ]  }|j	                  |«       Œ t        | j                  «      dkD  r|t        | j                  «      z
  }t        j                  t        j                  d«      d   «      }	| j                  r/| j                  «       D �
cg c]  }
t!        |
t"        «      rŒ|
‘Œ }}
ng }t        «       }|D ]$  }
| j                  |
«      }|j%                  |«      }Œ& || j                  | «      z
  }|j                  «       D ��ci c]  \  }}||vsŒ||“Œ }}}|j'                  d| j                  «      }t!        |t(        «      rd|| j                  k7  rUt        |	|«      rIt+        |	|«      }| j                  |«      |z
  }|j                  «       D ��ci c]  \  }}||vsŒ||“Œ }}}n1t!        |t(        «      s!t!        |t,        t.        f«      st1        d«      ‚|j                  «       D ��ci c]  \  }}|j3                  d	«      rŒ||“Œ }}}|j                  «       D ��ci c]  \  }}|d
k7  sŒ||“Œ }}}i }|D ]P  }||v r||v r|j'                  |«      ||<   ||v r|j'                  |«      ||<   Œ8||v sŒ=|j'                  |«      ||<   ŒR t        |«      dkD  r3t4        j7                  d|› d| j                  › d| j8                  › d�«       t        |j;                  «       «      }t        ||z
  «      dkD  rt4        j=                  ||z
  › d�«       i |¥|¥}|j                  «       D ��ci c]  \  }}||vsŒ||“Œ }}}|||fS c c}}w c c}
w c c}}w c c}}w c c}}w c c}}w c c}}w )NÚ_use_default_valuesr   r!   Ú_flax_internal_argsr   r�   r‚   z\Make sure that the `_class_name` is of type string or list of string (for custom pipelines).r¨   Úquantization_configz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.)Úgetr   rP   r¶   Úremover7   r¹   ÚlenÚignore_for_configr°   Ú	importlibÚimport_moduler+   rv   Úhas_compatiblesÚ_get_compatiblesr„   r   Úunionr1   rŸ   ÚgetattrÚlistÚtuplerG   Ú
startswithrQ   ÚwarningrN   r´   ru   )rI   r«   r!   Úused_defaultsÚkÚvÚoriginal_dictÚexpected_keysÚargÚdiffusers_libraryÚcÚcompatible_classesÚexpected_keys_comp_clsÚexpected_keys_cÚorig_cls_nameÚorig_clsÚunexpected_keys_from_origrˆ   r"   Úpassed_keysr‰   Úhidden_config_dicts                         r%   r†   zConfigMixin.extract_init_dictò  sB  € ð $Ÿ™Ð(=¸rÓBˆØ(3×(9Ñ(9Ô(;ÔuÑ(;¡  1¸qÈÒ?UÐZ[Ð_tÓZt�q˜!‘tÐ(;ˆÑuô ˜[×.Ñ.Ó0Ó1ˆð ×*Ñ*¨3Ó/ˆØ×Ñ˜VÔ$à�}Ñ$Ø× Ñ  Ô*ä�3Ð-Ô.Ø×.Ô.�Ø×$Ñ$ SÕ)ð /ô
 ˆs×$Ñ$Ó%¨Ò)Ø)¬C°×0EÑ0EÓ,FÑFˆMô &×3Ñ3´H·N±NÀ3Ó4GÈÑ4JÓKÐà×ÒØ-0×-AÑ-AÔ-CÓ!fÑ-C¨Ì:ÐVWÔYdÕKe¢!Ð-CÐÑ!fà!#Ðä!$£ÐÛ#ˆAØ!×0Ñ0°Ó3ˆOØ%;×%AÑ%AÀ/Ó%RÑ"ð $ð "8¸#×:LÑ:LÈSÓ:QÑ!QÐØ(3×(9Ñ(9Ô(;Ô_Ñ(;¡  1¸qÐH^Ò?^�q˜!‘tÐ(;ˆÑ_ð $Ÿ™¨°s·|±|ÓDˆä�}¤cÔ*Ø §¡Ò-ÜÐ)¨=Ô9äÐ0°-Ó@ˆHØ(+×(:Ñ(:¸8Ó(DÀ}Ñ(TÐ%Ø,7×,=Ñ,=Ô,?ÔfÑ,?¡D A qÀ1ÐLeÒCe˜1˜a™4Ð,?ˆKÒfÜ˜M¬3Ô/¼
À=ÔSWÔY^ÐR_Ô8`ÜØnóð ð
 )4×(9Ñ(9Ô(;ÔUÑ(;¡  1À1Ç<Á<ÐPSÕCT�q˜!‘tÐ(;ˆÑUð )4×(9Ñ(9Ô(;ÔZÑ(;¡  1¸qÐDYÓ?Y�q˜!‘tÐ(;ˆÑZð ˆ	Û ˆCð �f‰} ¨Ñ!3Ø#)§:¡:¨c£?�˜CÑ à�f‰}à!'§¡¨C£�	˜#’Ø˜Ò#à!,§¡°Ó!5�	˜#’ð !ô ˆ{Ó˜aÒÜ�N‰NØ(¨¨Ð5EÀcÇlÁlÀ^ð TPà—?‘?Ð#Ð#7ð9ôô ˜)Ÿ.™.Ó*Ó+ˆÜˆ}˜{Ñ*Ó+¨aÒ/Ü�K‰KØ  ;Ñ.Ð/Ð/vÐwôð
 2˜;Ð1¨&Ð1ˆð 0=×/BÑ/BÔ/DÔ[Ñ/D¡t q¨!ÈÐQZÒHZ˜a ™dÐ/DÐÑ[à˜-Ð);Ð;Ð;ùó{ vùò2 "gùó `ùó gùó Vùó [ùóH \sW   ¦O5³O5¹O5Ä8O;ÅO;Æ1P Æ>P É PÉPÊPÊ4PËPËPÏPÏ(PÚ	json_filer›   c                 ó¾   — |r||   j                  «       }n't        |dd¬«      5 }|j                  «       }d d d «       t        j                  «      S # 1 sw Y   ŒxY w)NÚrúutf-8©Úencoding)Ú	read_textÚopenÚreadr¤   Úloads)rI   rÙ   r›   ÚtextÚreaders        r%   r£   z ConfigMixin._dict_from_json_fileU  sN   € áØ 	Ñ*×4Ñ4Ó6‰Dä�i ¨wÕ7¸6Ø—{‘{“}�÷ 8ä�z‰z˜$ÓÐ÷ 8Ð7ús   ¥AÁAc                 óT   — | j                   j                  › d| j                  «       › �S )NÚ )r$   r+   Úto_json_string©r   s    r%   Ú__repr__zConfigMixin.__repr__^  s(   € Ø—.‘.×)Ñ)Ð*¨!¨D×,?Ñ,?Ó,AÐ+BÐCÐCr&   c                 ó   — | j                   S )z�
        Returns the config of the class as a frozen dictionary

        Returns:
            `dict[str, Any]`: Config of the class.
        )rM   rè   s    r%   r{   zConfigMixin.configa  s   € ð ×"Ñ"Ð"r&   c                 óü  ‡— t        | d«      r| j                  ni }| j                  j                  |d<   t        |d<   ˆfd„Šd|v rCt        |j                  t        «      s|j                  j                  «       n|j                  |d<   |j                  «       D ��ci c]  \  }}| ‰|«      “Œ }}}|j                  dd«       |j                  dd«       |j                  d	d«      }t        | d
d«      �g| j                  j                  j                  d«      d   }|j                  di «      }|› d| j                  j                  › �|| j                  <   ||d<   t!        j"                  |dd¬«      dz   S c c}}w )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.
        rM   r‚   Ú_diffusers_versionc                 ó^  •— t        | t        j                  «      r| j                  «       } | S t        | t        «      r| j                  «       } | S t        | d«      r't        | j                  «      r| j                  «       } | S t        | t        «      r| D �cg c]
  } ‰|«      ‘Œ } }| S c c}w )NÚto_dict)
r„   ÚnpÚndarrayÚtolistr   Úas_posixr7   Úcallablerî   rÅ   )r#   rË   Úto_json_saveables     €r%   rô   z4ConfigMixin.to_json_string.<locals>.to_json_saveablew  s›   ø€ Ü˜%¤§¡Ô,ØŸ™›�ð ˆLô ˜E¤4Ô(ØŸ™Ó(�ð
 ˆLô	 ˜ 	Ô*¬x¸¿¹Ô/FØŸ™›�ð ˆLô ˜E¤4Ô(Ù6;Ó<±e°Ñ)¨!Õ,°e�Ð<ØˆLùò =s   ÂB*rº   Ú_ignore_filesNr¸   Ú_pre_quantization_dtyperH   r�   rl   Úauto_mapé   T)ÚindentÚ	sort_keysÚ
)r7   rM   r$   r+   r   r„   rº   rP   rî   r   r1   rÄ   r>   rv   r»   rH   r¤   Údumps)r   r«   rÊ   rË   r¨   Úmoduler÷   rô   s          @r%   rç   zConfigMixin.to_json_stringk  sp  ø€ ô .5°TÐ;KÔ-L�d×)Ò)ÐRTˆØ%)§^¡^×%<Ñ%<ˆ�MÑ"Ü,7ˆÐ(Ñ)ô		ð ! KÑ/ô " +×"AÑ"AÄ4ÔHð ×/Ñ/×7Ñ7Ô9à ×4Ñ4ð Ð-Ñ.ð ;F×:KÑ:KÔ:MÔNÑ:M±$°!°Q�qÑ*¨1Ó-Ñ-Ð:MˆÑNà�‰˜¨Ô.Ø�‰Ð-¨tÔ4à�O‰OÐ5°tÓ<ˆä�4˜¨Ó-Ð9Ø—^‘^×.Ñ.×4Ñ4°SÓ9¸"Ñ=ˆFØ"—‘ z°2Ó6ˆHØ,2¨8°1°T·^±^×5LÑ5LÐ4MÐ)NˆH�T×%Ñ%Ñ&Ø&.ˆK˜
Ñ#ä�z‰z˜+¨a¸4Ô@À4ÑGÐGùó Os   ÂE8Újson_file_pathc                 óˆ   — t        |dd¬«      5 }|j                  | j                  «       «       ddd«       y# 1 sw Y   yxY w)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þ   Úwriters      r%   rt   zConfigMixin.to_json_file˜  s3   € ô �. #°Õ8¸FØ�L‰L˜×,Ñ,Ó.Ô/÷ 9×8Ñ8ús	   � 8¸Ac                 ó¨   — |dk(  r| j                   ndj                  || j                   g«      }||vrt        d|› d|j                  «       › �«      ‚|S )NÚ Ú/z#We did not manage to find the file z4 in the dduf file. We only have the following files )rN   rs   rG   r´   )rI   r}   r›   r©   s       r%   r    z&ConfigMixin._get_config_file_from_dduf£  s‚   € ð
 -°Ò2ð �OŠOà—‘Ð8¸#¿/¹/ÐJÓKð 	ð
 ˜lÑ*ÜØ5°k°]ÐBvð  xD÷  xIñ  xIó  xKð  wLð  Móð ð Ðr&   )rE   )F©NF)FFr¯   )&r+   r>   r?   Ú__doc__rN   r¾   rÁ   r‡   rH   ÚclassmethodrK   rU   rŸ   r   rb   rn   ÚPathLikeÚboolrz   r   rP   r   rÆ   r�   r�   r   r…   Ústaticmethodr¶   r†   r   r£   ré   Úpropertyr{   rç   rt   r    rƒ   r&   r%   rC   rC   X   s  „ ñð  €KØÐØ€OàÐØ€Kàò%ó ð%ò<8ð"Z ð Z¨ó Zñ$*¨#°·±Ñ*;ð *È$ó *ðX àNSñYØ $ s¨C x¡.Ñ0ðYà	��d˜D  c ™NÐ*Ñ+Ñ	+òYó ðYðv ñ0ó ð0ð Øð #Ø ñ	gà'*¨R¯[©[Ñ'8ðgð 
ˆt�C˜�H‰~˜t C¨ H™~Ð-Ñ	.ògó ó ðgðR ñTó ðTð ñ`<ó ð`<ðD ñ ¨S°2·;±;Ñ->ð  ÈdÐSVÐXaÐSaÑNbÐeiÑNiò  ó ð òDð ð#˜˜S #˜X™ò #ó ð#ð+H ó +HðZ	0¨3°·±Ñ+<ó 	0ð ðÀsð ÐZ^Ð_bÐdmÐ_mÑZnò ó ñr&   rC   c                 óB   ‡ — t        j                  ‰ «      ˆ f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                 óJ  •— |j                  «       D ��ci c]  \  }}|j                  d«      rŒ||“Œ }}}|j                  «       D ��ci c]  \  }}|j                  d«      sŒ||“Œ }}}t        | t        «      s#t	        d| j
                  j                  › d�«      ‚t        | dg «      }i }t        j                  ‰«      }	t        |	j                  j                  «       «      D �
��ci c]   \  }
\  }}|
dkD  sŒ||vsŒ||j                  “Œ" }}}
}t        ||j                  «       «      D ]
  \  }}|||<   Œ |j                  |j                  «       D ��ci c]   \  }}||vr||vr||j!                  ||«      “Œ" c}}«       t#        t%        |j                  «       «      t%        |«      z
  «      dkD  r1t'        t%        |j                  «       «      t%        |«      z
  «      |d<   i |¥|¥} t        | d«      di |¤Ž  ‰| g|¢­i |¤Ž y c c}}w c c}}w c c}}}
w c c}}w )	Nr¨   ú&`@register_for_config` was applied to úA init method, but this class does not inherit from `ConfigMixin`.r¾   r   r¸   rU   rƒ   )r   rÇ   r„   rC   ÚRuntimeErrorr$   r+   rÄ   r±   r²   Ú	enumerater³   ÚdefaultÚzipr´   r3   r»   r½   r°   rÅ   )r   r    r!   rÊ   rË   Úinit_kwargsÚconfig_init_kwargsÚignoreÚ
new_kwargsr²   Úir:   Úpr³   rÎ   r  Úinits                   €r%   Ú
inner_initz&register_to_config.<locals>.inner_init»  s$  ø€ ð )/¯©¬ÔP©¡  1¸a¿l¹lÈ3Õ>O�q˜!‘t¨ˆÑPØ/5¯|©|¬~ÔS©~¡t q¨!ÀÇÁÈcÕAR˜a ™d¨~ÐÑSÜ˜$¤Ô,ÜØ8¸¿¹×9PÑ9PÐ8Qð R2ð 2óð ô
 ˜Ð2°BÓ7ˆàˆ
Ü×%Ñ% dÓ+ˆ	ä09¸)×:NÑ:N×:TÑ:TÓ:VÔ0Wõ
Ù0W¡ ¡9 D¨!Ð[\Ð_`Ó[`ÐeiÐqwÒewˆD�!—)‘)‰OÐ0Wð 	ò 
ô ˜T :§?¡?Ó#4Ö5‰IˆC�Ø"ˆJ�tÒð 6ð 	×Ñð #-×"2Ñ"2Ô"4ôá"4‘J�A�wØ˜F‘? q°
Ñ':ð �;—?‘? 1 gÓ.Ñ.Ø"4òô	
ô Œs�:—?‘?Ó$Ó%¬¨KÓ(8Ñ8Ó9¸AÒ=Ü04´S¸¿¹Ó9JÓ5KÌcÐR]ÓN^Ñ5^Ó0_ˆJÐ,Ñ-à9Ð*Ð9¨jÐ9ˆ
Ø+Œ�Ð*Ó+Ñ9¨jÒ9ÙˆTÐ(�DÒ(˜KÓ(ùóC QùÛSùô
ùós.   •H¯HÁ
HÁ$HÃ*HÃ;HÄ HÅ%H
)Ú	functoolsÚwraps)r  r  s   ` r%   rU   rU   ²  s)   ø€ ô ‡_�_�TÓó#)ó ð#)ðJ Ðr&   c                 óh   ‡— | j                   Št        j                  ‰«      ˆfd„«       }|| _         | S )Nc                 óB  •— t        | t        «      s#t        d| j                  j                  › d�«      ‚t        |j                  «       «      }t        j                  | «      }i }|D ]t  }|j                  | j                  v rŒt        |j                  «      t        j                  k(  rd ||j                  <   ŒRt        | |j                  «      ||j                  <   Œv i |¥|¥}d|v r|j                  d«       t!        |«      D ]  \  }}	||   j                  }
|	||
<   Œ t#        t%        |j'                  «       «      t%        |«      z
  «      dkD  r1t)        t%        |j'                  «       «      t%        |«      z
  «      |d<    t        | d«      di |¤Ž  ‰| g|¢­i |¤Ž y )Nr  r  r�   r   r¸   rU   rƒ   )r„   rC   r  r$   r+   rP   r   ÚdataclassesÚfieldsr:   r¹   r]   r  Ú_MISSING_TYPErÄ   r1   r  r½   r°   r´   rÅ   )r   r    r!   r  r"  Údefault_kwargsÚfieldr  r  rÎ   r:   Úoriginal_inits              €r%   r  z%flax_register_to_config.<locals>.initç  s€  ø€ ä˜$¤Ô,ÜØ8¸¿¹×9PÑ9PÐ8Qð R2ð 2óð ô ˜6Ÿ<™<›>Ó*ˆô ×#Ñ# DÓ)ˆØˆÛˆEà�z‰z˜T×5Ñ5Ñ5ØÜ�E—M‘MÓ"¤k×&?Ñ&?Ò?Ø-1�˜uŸz™zÒ*ä-4°T¸5¿:¹:Ó-F�˜uŸz™zÒ*ð ð 7˜Ð6¨+Ð6ˆ
à�jÑ Ø�N‰N˜7Ô#ô   –o‰FˆAˆsØ˜!‘9—>‘>ˆDØ"ˆJ�tÒð &ô
 Œs�:—?‘?Ó$Ó%¬¨KÓ(8Ñ8Ó9¸AÒ=Ü04´S¸¿¹Ó9JÓ5KÌcÐR]ÓN^Ñ5^Ó0_ˆJÐ,Ñ-à+Œ�Ð*Ó+Ñ9¨jÒ9Ù�dÐ,˜TÒ, VÓ,r&   )r   r  r  )rI   r  r&  s     @r%   Úflax_register_to_configr'  ä  s6   ø€ Ø—L‘L€Mä‡_�_�]Ó#ó&-ó $ð&-ðP €C„LØ€Jr&   c                   óD   ‡ — e Zd ZdZeddeeeef   z  fˆ fd„«       Z	ˆ xZ
S )ÚLegacyConfigMixinz´
    A subclass of `ConfigMixin` to resolve class mapping from legacy classes (like `Transformer2DModel`) to more
    pipeline-specific classes (like `DiTTransformer2DModel`).
    r{   c                 ó|   •— ddl m}  ||| «      }|| u rt        t        |�  ||fi |¤ŽS  |j                  ||fi |¤ŽS )Nr   )Ú_fetch_remapped_cls_from_config)Úmodels.model_loading_utilsr+  r   r)  r�   )rI   r{   r€   r!   r+  Úremapped_classr$   s         €r%   r�   zLegacyConfigMixin.from_config  sV   ø€ õ 	Pñ 9¸ÀÓEˆà˜SÑ ÜÔ*¨NÑGÈÐPdÑoÐhnÑoÐoà-�>×-Ñ-¨fÐ6JÑUÈfÑUÐUr&   r  )r+   r>   r?   r  r  r   rP   rŸ   r   r�   r@   rA   s   @r%   r)  r)    s3   ø„ ñð
 ñ
V ¨d°3¸°8©nÑ!<ô 
Vó ô
Vr&   r)  )/r  r!  r  r¿   r±   r¤   rn   ÚreÚcollectionsr   Úpathlibr   Útypingr   Únumpyrï   Úhuggingface_hubr   r   r   Úhuggingface_hub.utilsr	   r
   r   r   r   Útyping_extensionsr   r  r   Úutilsr   r   r   r   r   r   Ú
get_loggerr+   rQ   ÚcompileÚ_re_configuration_filer   rC   rU   r'  r)  rƒ   r&   r%   Ú<module>r:     s§   ðñ  ,ã Û Û Û Û Û 	Û 	Ý #Ý Ý ã ß CÑ C÷õ õ #å ÷÷ ð 
ˆ×	Ñ	˜HÓ	%€à#˜Ÿ™Ð$9Ó:Ð ô)�ô )÷@W	ñ W	òt/òd-ô`V˜õ Vr&   