
    bi~                        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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 ddl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)jT                  e+      Z, ejZ                  d      Z. G d de	      Z/ G d d      Z0d Z1d Z2 G d de0      Z3y)z%ConfigMixin base class and utilities.    N)OrderedDict)Path)AnyDictOptionalTupleUnion)	DDUFEntrycreate_repohf_hub_download)EntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundErrorvalidate_hf_hub_args)	HTTPError)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        X/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/configuration_utils.pyr   zFrozenDict.__init__9   sC    $)&)**, 	&JC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>WWabccr*   c                 H    t        d| j                  j                   d      )Nz#You cannot use ``setdefault`` on a r,   r-   r0   s      r)   
setdefaultzFrozenDict.setdefaultD   s#    =dnn>U>U=VV`abbr*   c                 H    t        d| j                  j                   d      )NzYou cannot use ``pop`` on a r,   r-   r0   s      r)   popzFrozenDict.popG   s"    6t~~7N7N6OzZ[[r*   c                 H    t        d| j                  j                   d      )NzYou cannot use ``update`` on a r,   r-   r0   s      r)   updatezFrozenDict.updateJ   s#    9$..:Q:Q9RR\]^^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)   r<   zFrozenDict.__setattr__M   C    4$B4>>CZCZB[[efggD%(r*   c                     t        | d      r/| j                  r#t        d| j                  j                   d      t
        |   ||       y r9   )r;   r"   r.   r(   r/   r   __setitem__r=   s      r)   rA   zFrozenDict.__setitem__R   r?   r*   )r/   
__module____qualname__r   r1   r3   r5   r7   r<   rA   __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de	de
fdZddee	ej                  f   d	efd
Ze	 ddeeee	e
f   f   deeeeee	e
f   f   f   fd       Zed        Zee	 	 ddee	ej                  f   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	ej                  f   deee	ef      fd       Zd Z e!dee	e
f   fd       Z"de	fdZ#dee	ej                  f   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                 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(   r5   r;   dictrI   loggerdebugr   )r#   r%   internal_dictprevious_dicts       r)   register_to_configzConfigMixin.register_to_configo   s    #%7GGn&opp 	

8T"t-."M !4!45M=t22=f=MLL0tM?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
        rI   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__r;   typer/   r   rI   AttributeError)r#   r>   is_in_configis_attributedeprecation_messages        r)   __getattr__zConfigMixin.__getattr__   s    (4==8kWT]]ScEdfj=kt}},$@FVW[\`WaWjWjVk  l]  ^b  ]c  ck  lp  qu  lv  l  l  k@  @q  rv  qw  wy  #z17<O_de&&t,,qd!4!4 55PQUPVVW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)rb   rd   rf   	subfolder)rf   rc   re   ri   )ospathisfileAssertionErrormakedirsjoinrJ   to_json_filerM   infor5   splitsepr   rg   _upload_folder)r#   r_   r`   r%   output_config_filerc   rd   re   rf   rg   ri   s              r)   save_configzConfigMixin.save_config   s7    77>>.) ?>2BBe!fgg
NT2  WW\\.$:J:JK,--.@-ABC#ZZ(8$?NjjD1G

;6IJJw-EjjN,@,@,Mb,QRG!'D'QVW__G

;5I-##    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-pathrT   FrU   T)ry   return_unused_kwargsdtype_class_name )
r5   
ValueError
isinstancerL   r/   r   load_configextract_init_dict_deprecated_kwargsrQ   )
clsrw   r|   r%   r]   	init_dictunused_kwargshidden_dictdeprecated_kwargmodels
             r)   from_configzConfigMixin.from_config   s   N +f4ZZ ?@F>eff &$'"ncll*#I# O- -#
 CLL(#EcU Ku NN#
 -w8K[`a,S__w6hlwpvwNFF0E0E0Ef0WPV0W-	=+ m#!.!2!27!;Ig !$ 6 6 	R=0.;.?.?@P.Q	*+	R
  i  K'),K&   /;/ 9=8K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_dictrT   FrU   )r   r   )r   r$   r%   r]   s       r)   r   zConfigMixin.get_config_dict  sE     Gse L) ) 	 	#W.AQVWs///r*   ry   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                        }nt        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 (`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.
            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proxiesrf   local_files_onlyrevisionmirrorri   
user_agentdduf_entries	file_typerw   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`zDDUF 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   rf   r   ri   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.)r5   r   strrJ   r   _get_config_file_from_ddufrj   rk   rl   isdirro   EnvironmentErrorr   r   r   r   r   r   _dict_from_json_filer   jsonJSONDecodeErrorUnicodeDecodeError)r   ry   r|   return_commit_hashr%   r   r   r   r   r   rf   r   r   _ri   r   r   config_fileerrconfig_dictcommit_hashoutputss                         r)   r   zConfigMixin.load_config#  s3   j JJ{D1	JJ{D1	!',Df!M$4e<**Y-

7D)!::&8%@::j$/JJx&JJ{D1	ZZb1
7=zz.RV7W:
:K:
$Z0
(+,I(J%??"s 
 $ 6  889VXdeKWW^^9:7KWW]]89$:IsW* !ggll+H)UXUdUde-JCOO \] ggll+H#//Z&*3??*;;OPmOnnop 3-1 __'#1#%5)'%'+Ad	r22;\2ZK-k:K %(:.y G~%Gm + &45 6i i 
 ) &j !00M/NNhj 
 & &455[\_\k\k[llmn   &56c#@   &./N.O P>>[=\ ]//2.? @ZZ  $ &-.K-L M--J,K L$$'OO#4E;  $$&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)setrL   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    rL   r   remover;   r   lenignore_for_configr   	importlibimport_moduler/   rr   has_compatibles_get_compatiblesr   r   unionr5   r   getattrlisttupler   
startswithrM   warningrJ   r   rq   )r   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  s>    $(=rB(3(9(9(;u1q?UZ[_tZtq!tuu [..01 **3/V$}$  *3-... *$$S)*
 s$$%))C0E0E,FFM &33HNN34G4JK-0-A-A-C!f:VWYdKe!!f!f!#!$# 	SA!003O%;%A%A/%R"	S "8#:L:LS:Q!Q(3(9(9(;_1qH^?^q!t__ $s||D}c*-)=90-@H(+(:(:8(D}(T%,7,=,=,?fDAq1LeCe1a4fKfM3/
=SWY^R_8`n 
 )4(9(9(;U11<<PSCTq!tUU )4(9(9(;Z1qDY?Yq!tZZ 	  	6C f}!3#)::c?C f}!'C	##!,!5	#	6 {aNN(5Ecll^ TP??##79 )..*+}{*+a/KK ;.//vw
 2;1&1 0=/B/B/D[tq!QZHZa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)r   r   r   textreaders        r)   r   z ConfigMixin._dict_from_json_file5  sW     	*446Diw7 %6{{}%zz$% %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.
        )rI   r   s    r)   rw   zConfigMixin.configC  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        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.
        rI   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_posixr;   callabler   r   )r'   r   to_json_saveables     r)   r   z4ConfigMixin.to_json_string.<locals>.to_json_saveableY  s    %, L E4((
 L	 	*x/F L E4(6;<)!,<<L =s   B*r   _ignore_filesNr   _pre_quantization_dtype   T)indent	sort_keys
)r;   rI   r(   r/   r   r   r   rL   r   r    r5   r   dumps)r#   r   r   r   r   r   s        @r)   r   zConfigMixin.to_json_stringM  s     .5T;K-Ld))RT%)^^%<%<M",7()		 !K/ "+"A"A4H //779 44 -. ;F:K:K:MN$!Qq*1--NN.-t4OO5t<zz+a4@4GG Os   D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)   rp   zConfigMixin.to_json_filet  s<     .#8 	0FLL,,./	0 	0 	0s	    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 )rJ   ro   r   r   )r   ry   r   r   s       r)   r   z&ConfigMixin._get_config_file_from_dduf  s    
 -2 OO8#//JK 	
 l*5k]Bv  xD  xI  xI  xK  wL  M  r*   )FNF)FFr   )&r/   rB   rC   __doc__rJ   r   r   r   rQ   r   r   r^   r	   rj   PathLikeboolrv   classmethodr   r   r   r   r   r   r   r   staticmethodr   r   r   r
   r   r   propertyrw   r   rp   r   r   r*   r)   rG   rG   X   s      KO8"Z Z Z$*%R[[0@*A *PT *X TYY:tCH~56Y	tU4c3h/00	1Y Yv 0 0  # 	g',S"++-='>g 
tCH~tCH~-	.g  gR T T `< `<D `d c2;;./ ?GSR[^H\?]   D #S#X # #%H %HN	05bkk1A+B 	0 s Z^_bdm_mZn  r*   rG   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   rQ   r   )r    r   r   rG   RuntimeErrorr(   r/   r   r   r   	enumerater   defaultzipr   r7   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1all3>Oq!tPP/5||~Stq!cARadSS$,89P9P8Q R2 2 
 2B7
%%d+	09):N:N:T:T:V0W
 
 ,9D![\_`[`eiqwewD!))O

 
 T:??#45 	#IC"Jt	# 	 #-"2"2"4AwF?q
': ;??1g..	
 s:??$%K(889A=04S9J5KcR]N^5^0_J,-9*9j9
+*+9j9T(D(K(C QS
s.   HH
H$H*H;H H%H
)	functoolswraps)r  r  s   ` r)   rQ   rQ     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   rQ   r   )r   rG   r  r(   r/   rL   r    dataclassesfieldsr>   r   rY   r  _MISSING_TYPEr   r5   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9P9P8Q R2 2  6<<>* ##D) 	GEzzT555EMM"k&?&??-1uzz*-4T5::-Fuzz*	G 76+6
j NN7#  o 	#FAs!9>>D"Jt	#
 s:??$%K(889A=04S9J5KcR]N^5^0_J,-+*+9j9d,T,V,r*   )r   r  r  )r   r  r"  s     @r)   flax_register_to_configr#    s6    LLM__]#&- $&-P CLJr*   c                   H     e Zd ZdZeddeeeee	f   f   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`).
    rw   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   )r   rw   r|   r%   r'  remapped_classr(   s         r)   r   zLegacyConfigMixin.from_config  sV     	P 9ES *NGPdohnoo->--f6JUfUUr*   r  )r/   rB   rC   r  r  r	   r   r   r   r   r   rD   rE   s   @r)   r%  r%    s8    
 
Vz4S>'A!B 
V 
Vr*   r%  )4r  r  r  r   r   r   rj   recollectionsr   pathlibr   typingr   r   r   r   r	   numpyr   huggingface_hubr
   r   r   huggingface_hub.utilsr   r   r   r   requestsr   typing_extensionsr   r   r   utilsr   r   r   r   r   r   
get_loggerr/   rM   compile_re_configuration_filer   rG   rQ   r#  r%  r   r*   r)   <module>r7     s     ,      	 	 #  4 4  C C   "   
		H	%#$9: ) )@s sl/d-`V Vr*   