+
    þäûj@  ã                  ó®   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHtH	t	H
t
Ht  ! R R4      tR R ltR R	 ltR
 R ltRR R lltR/ /R R llt. ROtR# )zM
A module containing commonly-used functionality to implement architectures.
)ÚannotationsN)ÚAnyÚLiteralÚMappingÚProtocolÚTypeVarc                  ó^   € ] tR t^tRtR R lt]R R l4       t]R R l4       tR R	 lt	R
t
R# )ÚKeyConditionz=
A condition that checks if a state dict has the given keys.
c               ó    € V ^8„  d   QhRRRR/# )é   ÚkindzLiteral['all', 'any']Úkeysztuple[str | KeyCondition, ...]© )Úformats   "ÚRC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\spandrel\util\__init__.pyÚ__annotate__ÚKeyCondition.__annotate__   s   € ÷ 1ñ 1Ø)ð1Ø1Oñ1ó    c                	ó   € W n         Wn        R # ©N©Ú_keysÚ_kind)Úselfr   r   s   &&&r   Ú__init__ÚKeyCondition.__init__   s   € ð Œ
Ø,0Ž
r   c               ó    € V ^8„  d   QhRRRR/# ©r   r   ústr | KeyConditionÚreturnr	   r   )r   s   "r   r   r      ó   € ÷ )ñ )Ð)ð )¨lñ )r   c                 	ó   € \        R V 4      # )Úall©r	   ©r   s   *r   Úhas_allÚKeyCondition.has_all   ó   € ä˜E 4Ó(Ð(r   c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r      r    r   c                 	ó   € \        R V 4      # )Úanyr#   r$   s   *r   Úhas_anyÚKeyCondition.has_any   r'   r   c               ó    € V ^8„  d   QhRRRR/# )r   Ú
state_dictúMapping[str, object]r   Úboolr   )r   s   "r   r   r       s   € ÷ 	;ñ 	;Ð#7ð 	;¸Dñ 	;r   c                	ór  aa€ R  V3R lloV P                   R8X  dO   \        ;QJ d)    V3R lV P                   4       F  '       d   K   R# 	  R# ! V3R lV P                   4       4      # \        ;QJ d)    V3R lV P                   4       F  '       g   K   R# 	  R# ! V3R lV P                   4       4      # )c               ó    € V ^8„  d   QhRRRR/# )r   Úkeyr   r   r0   r   )r   s   "r   r   Ú+KeyCondition.__call__.<locals>.__annotate__!   s   € ÷ 	%ñ 	%Ð+ð 	%°ñ 	%r   c                óJ   <€ \        V \        4      '       d	   V ! S4      # V S9   # r   )Ú
isinstancer	   )r3   r.   s   &€r   Ú_detectÚ&KeyCondition.__call__.<locals>._detect!   s%   ø€ Ü˜#œ|×,Ò,Ù˜:“Ð&Ø˜*Ñ$Ð$r   r"   c              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5ir   r   ©Ú.0r3   r7   s   & €r   Ú	<genexpr>Ú(KeyCondition.__call__.<locals>.<genexpr>'   ó   øé € Ð:©z¨‘w˜s—|�|«zùó   ƒFTc              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5ir   r   r:   s   & €r   r<   r=   )   r>   r?   )r   r"   r   r*   )r   r.   r7   s   &f@r   Ú__call__ÚKeyCondition.__call__    s}   ù€ ÷	%ð 	%ð
 �:‰:˜Ôß“3Ô:¨t¯zªzÓ:—3”3Ð:’3Ð:�3Ô:¨t¯zªzÓ:Ó:Ð:ç“3Ô:¨t¯zªzÓ:—3”3Ð:’3Ð:�3Ô:¨t¯zªzÓ:Ó:Ð:r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ústaticmethodr%   r+   rA   Ú__static_attributes__r   r   r   r	   r	      s>   † ñõ1ð ô)ó ð)ð ô)ó ð)÷	;ñ 	;r   r	   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r.   r/   Úkey_patternÚstrr   Úintr   )r   s   "r   r   r   ,   s"   € ÷ ñ Ð$8ð Àsð Èsñ r   c                óp   € \        ^d4       F&  pVP                  \        V4      4      V 9   g   K$  Vu # 	  R# )a   
Returns the maximum index `i` such that `key_pattern.format(str(i))` is in `state`.

If no such key is in state, then `-1` is returned.

Example:
    get_first_seq_index(state, "body.{}.weight") -> -1
    get_first_seq_index(state, "body.{}.weight") -> 3
éÿÿÿÿ)Úranger   rL   )r.   rK   Úis   && r   Úget_first_seq_indexrR   ,   s5   € ô �3ŽZˆØ×Ñœc !›fÓ%¨Ö3ØŠHñ ð €Ir   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r.   r/   Úseq_keyrL   r   rM   r   )r   s   "r   r   r   <   s"   € ÷ ñ Ð0ð ¸3ð À3ñ r   c                óP  € VR,           p\        4       pV P                  4        F\  pVP                  V4      '       g   K  V\        V4      R P	                  R^R7      ^ ,          pVP                  \        V4      4       K^  	  \        V4      ^ 8X  d   ^ # \        V4      ^,           # )zÞ
Returns the length of a sequence in the state dict.

The length is detected by finding the maximum index `i` such that
`{seq_key}.{i}.{suffix}` is in `state` for some suffix.

Example:
    get_seq_len(state, "body") -> 5
Ú.N)Úmaxsplit)Úsetr   Ú
startswithÚlenÚsplitÚaddrM   Úmax)r.   rT   Úprefixr   ÚkÚindexs   &&    r   Úget_seq_lenra   <   s‡   € ð �s�]€Fä“U€DØ�_‰_ÖˆØ�<‰<˜×ÔØ”c˜&“k�mÐ$×*Ñ*¨3¸Ð*Ó;¸AÕ>ˆEØ�H‰H”S˜“ZÖ ñ ô
 ˆ4ƒy�A„~ÙÜˆt‹9�q�=Ðr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚxrM   Úinput_channelsr   útuple[int, int]r   )r   s   "r   r   r   S   s!   € ÷ ñ  Sð ¸#ð À/ñ r   c                óâ   € R R lpV^^^.pV FO  pW,          ^ 8X  g   K  V! W,          4      '       g   K(  \        \        P                  ! W,          4      4      V3u # 	  \        RV  R24      h)z‚
Returns a scale and number of output channels such that `scale**2 * out_nc = x`.

This is commonly used for pixelshuffel layers.
c               ó    € V ^8„  d   QhRRRR/# )r   ÚnrM   r   r0   r   )r   s   "r   r   Ú3get_scale_and_output_channels.<locals>.__annotate__c   s   € ÷ 1ñ 1�Sð 1˜Tñ 1r   c                ón   € \         P                  ! V 4      \        \         P                  ! V 4      4      8H  # r   )ÚmathÚsqrtrM   )rh   s   &r   Ú	is_squareÚ0get_scale_and_output_channels.<locals>.is_squarec   s"   € Ü�yŠy˜‹|œs¤4§9¢9¨Q£<Ó0Ñ0Ð0r   zwExpected output channels to be either 1, 3, or 4. Could not find a pair (scale, out_nc) such that `scale**2 * out_nc = Ú`)rM   rk   rl   ÚAssertionError)rc   rd   rm   Ú
candidatesÚcs   &&   r   Úget_scale_and_output_channelsrs   S   su   € õ 1ð ! ! Q¨Ð*€JÛˆØ�5�AŽ:™) A¥F×+Ô+Ü”t—y’y ¥Ó(Ó)¨1Ð,Ò,ñ ô ðQØQRÐPSÐSTð	Vóð r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r.   r/   Úupsample_keyrL   Ú
default_nfrM   r   re   r   )r   s   "r   r   r   r   s0   € ÷ ñ Ø$ðàðð ðð ñ	r   c                óì   € ^pTp\        ^ ^
^4       F]  pV RV R2pW`9  d    W43# W,          pVP                  pV^,          pV\        P                  ! V^ ,          V,          4      ,          pK_  	  W43# )aa  
This will detect the upscale factor and number of features of a pixelshuffle module in the state dict.

A pixelshuffle module is a sequence of alternating up convolutions and pixelshuffle.
The class of this module is commonyl called `Upsample`.
Examples of such modules can be found in most SISR architectures, such as SwinIR, HAT, RGT, and many more.
rV   z.weight)rP   Úshaperk   Úisqrt)	r.   ru   rv   ÚupscaleÚnum_featrQ   r3   Útensorrx   s	   &&&      r   Úget_pixelshuffle_paramsr}   r   sˆ   € ð €GØ€Hä�1�b˜!Ž_ˆØ�˜a ˜s 'Ð*ˆØÔ Øð ÐÐð •ˆà!'§¡ˆØ˜•8ˆØ”4—:’:˜e A�h¨(Õ2Ó3Õ3Šñ ð ÐÐr   Úextra_parametersc               ó   € V ^8„  d   QhRR/# )r   r~   r/   r   )r   s   "r   r   r   �   s   € ÷ =ñ =Ð/Cñ =r   c                ób   a a€ R R lo ! R R\         4      p\        RVR7      pR V V3R llpV# )	zI
Stores the hyperparameters of a class in a `hyperparameters` attribute.
c               ó    € V ^8„  d   QhRRRR/# )r   Úspeczinspect.FullArgSpecr   údict[str, Any]r   )r   s   "r   r   Ú+store_hyperparameters.<locals>.__annotate__”   s   € ÷ ñ Ð2ð °~ñ r   c           	     óâ   € / pV P                   e   V P                   pV P                  eE   / VC\        \        V P                  \        V P                  4      ) R  V P                  4      4      CpV# r   )ÚkwonlydefaultsÚdefaultsÚdictÚzipÚargsrZ   )r‚   r‡   s   & r   Úget_arg_defaultsÚ/store_hyperparameters.<locals>.get_arg_defaults”   sn   € ØˆØ×ÑÒ*Ø×*Ñ*ˆHà�=‰=Ò$ðØðä”s˜4Ÿ9™9¤c¨$¯-©-Ó&8Ð%8Ð%:Ð;¸T¿]¹]ÓKÓLðˆHð
 ˆr   c                  ó"   € ] tR t^¡t$ R]R&   RtR# )Ú2store_hyperparameters.<locals>.WithHyperparametersrƒ   Úhyperparametersr   N)rC   rD   rE   rF   Ú__annotations__rI   r   r   r   ÚWithHyperparametersrŽ   ¡   s   ‡ Ø'×'r   r‘   ÚC)Úboundc               ó    € V ^8„  d   QhRRRR/# )r   Úclsztype[C]r   r   )r   s   "r   r   r„   ¦   s   € ÷ $ñ $�7ð $˜wñ $r   c                ó‚  <aa€ V P                   o\        P                  ! S4      pS! V4      oVP                  e   \	        R4      hVP
                  e   \	        R4      hVP                  R.8w  d$   \	        RV P                  ,           R,           4      h\        P                  ! S4      R VVV3R ll4       pW n         V # )NzPClass has *args, which is not allowed in combination with @store_hyperparameterszSClass has **kwargs, which is not allowed in combination with @store_hyperparametersr   z2@store_hyperparameters requires all arguments of `zW.__init__` after `self` to be keyword arguments. Use `def __init__(self, *, a, b, c):`.c               ó   € V ^8„  d   QhRR/# )r   r   r’   r   )r   s   "r   r   Ú:store_hyperparameters.<locals>.inner.<locals>.__annotate__¼   s   € ÷ 	%ñ 	%˜1ñ 	%r   c           
     óÈ   <€ SP                  4        F6  w  r#W!9   g   K  W,          V8w  d   \        R V RV RW,           24      hW K8  	  / SCSCVCV n        S! V 3/ VB  R# )zExpected hyperparameter z to be z
, but got N)ÚitemsÚ
ValueErrorr�   )r   Úkwargsr_   Úvr‡   r~   Úold_inits   &,  €€€r   Únew_initÚ6store_hyperparameters.<locals>.inner.<locals>.new_init»   s|   ø€ ð )×.Ñ.Ö0‘�Ø–;Ø•y A”~Ü(Ø6°q°c¸ÀÀÀ:ÈfÍiÈ[ÐYóð ð š	ñ 1ð $NÐ&6Ð#M¸(Ð#MÀfÐ#MˆDÔ Ù�TÑ$˜VÔ$r   )
r   ÚinspectÚgetfullargspecÚvarargsÚUserWarningÚvarkwrŠ   rC   Ú	functoolsÚwraps)r•   r‚   rŸ   r‡   rž   r~   r‹   s   &  @@€€r   ÚinnerÚ$store_hyperparameters.<locals>.inner¦   s¿   ú€ Ø—<‘<ˆä×%Ò% hÓ/ˆÙ# DÓ)ˆà�<‰<Ò#ÜØbóð ð �:‰:Ò!ÜØeóð ð �9‰9˜˜Ô ÜØDØ—,‘,õàkõlóð ô 
�Š˜Ó	"÷	%ñ 	%ó 
#ð	%ð  ŒØˆ
r   )r   r   )r~   r‘   r’   r¨   r‹   s   d   @r   Ústore_hyperparametersrª   �   s5   ù€ õ
ô(œhô (ô 	�Ð.Ô/€A÷$ñ $ðL €Lr   )Úupsampleé@   )rR   r}   rs   ra   r	   rª   )rG   Ú
__future__r   r¦   r¡   rk   Útypingr   r   r   r   r   r	   rR   ra   rs   r}   rª   Ú__all__r   r   r   Ú<module>r°      sP   ðñõ #ã Û Û ß ;Õ ;÷;ñ ;õ>õ õ.÷>ð:=Àb÷ =ò@‚r   