ó
    USh&  ã                   óB   • S SK r S SK Jr   " S S\R                  5      rg)é    N)Únnc                   óJ   ^ • \ rS rSrS	U 4S jjrS rS rS rS rS r	Sr
U =r$ )
ÚLitEmaé   c                 ó®  >• [         TU ]  5         US:  d  US:”  a  [        S5      e0 U l        U R	                  S[
        R                  " U[
        R                  S95        U R	                  SU(       a#  [
        R                  " S[
        R                  S9O"[
        R                  " S[
        R                  S95        UR                  5        H}  u  pEUR                  (       d  M  UR                  S	S
5      nU R                  R                  XF05        U R	                  XeR                  5       R                  5       R                  5        M     / U l        g )Ng        ç      ð?zDecay must be between 0 and 1Údecay©ÚdtypeÚnum_updatesr   éÿÿÿÿÚ.Ú )ÚsuperÚ__init__Ú
ValueErrorÚm_name2s_nameÚregister_bufferÚtorchÚtensorÚfloat32ÚintÚnamed_parametersÚrequires_gradÚreplaceÚupdateÚcloneÚdetachÚdataÚcollected_params)ÚselfÚmodelr	   Úuse_num_upatesÚnameÚpÚs_nameÚ	__class__s          €Ú?/home/gothic/public_html/Fooocus/ldm_patched/ldm/modules/ema.pyr   ÚLitEma.__init__   s÷   ø€ Ü‰ÑÔØ�3‹;˜% #›+ÜÐ<Ó=Ð=àˆÔØ×Ñ˜W¤e§l¢l°5ÄÇÁÑ&NÔOØ×Ñ˜]ÖP^¬E¯LªL¸Ä%Ç)Á)Ò,LÜ�\Š\˜"¤E§I¡IÑ.ô	0ð ×-Ñ-Ö/‰GˆDØ��‰àŸ™ c¨2Ó.�Ø×"Ñ"×)Ñ)¨4¨.Ô9Ø×$Ñ$ V¯W©W«Y×-=Ñ-=Ó-?×-DÑ-DÖEñ 0ð !#ˆÕó    c                 ón   • U ? U R                  S[        R                  " S[        R                  S95        g )Nr   r   r
   )r   r   r   r   r   )r!   s    r(   Úreset_num_updatesÚLitEma.reset_num_updates   s'   € ØÐØ×Ñ˜]¬E¯LªL¸Ä%Ç)Á)Ñ,LÕMr*   c                 ó|  • U R                   nU R                  S:¼  aH  U =R                  S-  sl        [        U R                   SU R                  -   SU R                  -   -  5      nSU-
  n[        R                  " 5          [        UR                  5       5      n[        U R                  5       5      nU Hl  nXF   R                  (       aE  U R                  U   nXW   R                  XF   5      XW'   XW   R                  X5U   XF   -
  -  5        M[  X`R                  ;  a  Ml   e   S S S 5        g ! , (       d  f       g = f)Nr   é   é
   r   )r	   r   Úminr   Úno_gradÚdictr   Únamed_buffersr   r   Útype_asÚsub_)r!   r"   r	   Úone_minus_decayÚm_paramÚshadow_paramsÚkeyÚsnames           r(   ÚforwardÚLitEma.forward   s  € Ø—
‘
ˆà×Ñ˜qÓ Ø×Ò Ñ!ÕÜ˜Ÿ
™
 Q¨×)9Ñ)9Ñ%9¸bÀ4×CSÑCSÑ>SÑ$TÓUˆEà ™+ˆä�]Š]�_Ü˜5×1Ñ1Ó3Ó4ˆGÜ  ×!3Ñ!3Ó!5Ó6ˆMã�Ø‘<×-×-Ø ×.Ñ.¨sÑ3�EØ+8Ñ+?×+GÑ+GÈÉÓ+U�MÑ(Ø!Ñ(×-Ñ-¨oÈuÑAUÐX_ÑXdÑAdÑ.eÖfà"×&8Ñ&8Õ8Ð8Ð8ñ ÷	 �_Ž_ús   Á?BD-Ä D-Ä-
D;c                 ó2  • [        UR                  5       5      n[        U R                  5       5      nU H_  nX$   R                  (       a8  X$   R                  R                  X0R                  U      R                  5        MN  X@R                  ;  a  M_   e   g )N)r3   r   r4   r   r   Úcopy_r   )r!   r"   r8   r9   r:   s        r(   Úcopy_toÚLitEma.copy_to2   sy   € Ü�u×-Ñ-Ó/Ó0ˆÜ˜T×/Ñ/Ó1Ó2ˆÛˆCØ‰|×)×)Ø‘×!Ñ!×'Ñ'¨×6HÑ6HÈÑ6MÑ(N×(SÑ(SÖTà×"4Ñ"4Õ4Ð4Ð4ò	 r*   c                 óX   • U Vs/ s H  o"R                  5       PM     snU l        gs  snf )z•
Save the current parameters for restoring later.
Args:
  parameters: Iterable of `torch.nn.Parameter`; the parameters to be
    temporarily stored.
N)r   r    )r!   Ú
parametersÚparams      r(   ÚstoreÚLitEma.store;   s#   € ñ =GÓ GºJ°5§¡¦¹JÑ GˆÕùÒ Gs   …'c                 óŒ   • [        U R                  U5       H*  u  p#UR                  R                  UR                  5        M,     g)a’  
Restore the parameters stored with the `store` method.
Useful to validate the model with EMA parameters without affecting the
original optimization process. Store the parameters before the
`copy_to` method. After validation (or model saving), use this to
restore the former parameters.
Args:
  parameters: Iterable of `torch.nn.Parameter`; the parameters to be
    updated with the stored parameters.
N)Úzipr    r   r?   )r!   rC   Úc_paramrD   s       r(   ÚrestoreÚLitEma.restoreD   s4   € ô " $×"7Ñ"7¸ÖD‰NˆGØ�J‰J×Ñ˜WŸ\™\Ö*ò Er*   )r    r   )g§èH.ÿï?T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r,   r<   r@   rE   rJ   Ú__static_attributes__Ú__classcell__)r'   s   @r(   r   r      s(   ø† ÷#ò&Nò9ò*5òH÷+ð +r*   r   )r   r   ÚModuler   © r*   r(   Ú<module>rT      s   ðÛ Ý ôK+ˆR�Y‰Yõ K+r*   