+
    ùäûjC+  ã                   óŒ   € ^ RI t ^ RIt^ RIHtHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHtHt R R lt ! R R	4      t ! R
 R]4      tR# )é    N)ÚAnyÚDictÚListÚOptional)ÚEinopsError)Ú_product)ÚParsedExpressionÚ	_ellipsisc                ó0   € V ^8„  d   QhR\         R\        /# )é   ÚaxesÚreport_message)ÚsetÚstr)Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\einops\layers\_einmix.pyÚ__annotate__r   
   s   € ÷ 7ñ 7”sð 7¬Cñ 7ó    c                 óZ   € \        V 4      ^ 8”  d   \        VP                  V 4      4      hR# )r   N)Úlenr   r   )r   r   s   &&r   Ú_report_axesr   
   s(   € Ü
ˆ4ƒy�1„}Ü˜.×/Ñ/°Ó5Ó6Ð6ñ r   c                   ór   a a€ ] tR t^t oR
V3R lV 3R llltV3R lR ltV3R lR ltR tR tR	t	Vt
V ;t# )Ú_EinmixMixinc                óB   <€ V ^8„  d   QhRS[ RS[ RS[S[ ,          RS[/# ©r   ÚpatternÚweight_shapeÚ
bias_shapeÚaxes_lengths)r   r   r   )r   Ú__classdict__s   "€r   r   Ú_EinmixMixin.__annotate__   s.   ø€ ÷ 1
ñ 1
¡ð 1
±3ð 1
ÁHÉSÅMð 1
Ñjmñ 1
r   c                óz   <€ \         SV `  4        Wn        W n        W0n        W@n        V P                  WW4R7       R# )añ  
EinMix - Einstein summation with automated tensor management and axis packing/unpacking.

EinMix is a combination of einops and MLP, see tutorial:
https://github.com/arogozhnikov/einops/blob/main/docs/3-einmix-layer.ipynb

Imagine taking einsum with two arguments, one of each input, and one - tensor with weights
>>> einsum('time batch channel_in, channel_in channel_out -> time batch channel_out', input, weight)

This layer manages weights for you, syntax highlights a special role of weight matrix
>>> EinMix('time batch channel_in -> time batch channel_out', weight_shape='channel_in channel_out')
But otherwise it is the same einsum under the hood. Plus einops-rearrange.

Simple linear layer with a bias term (you have one like that in your framework)
>>> EinMix('t b cin -> t b cout', weight_shape='cin cout', bias_shape='cout', cin=10, cout=20)
There is no restriction to mix the last axis. Let's mix along height
>>> EinMix('h w c-> hout w c', weight_shape='h hout', bias_shape='hout', h=32, hout=32)
Example of channel-wise multiplication (like one used in normalizations)
>>> EinMix('t b c -> t b c', weight_shape='c', c=128)
Multi-head linear layer (each head is own linear layer):
>>> EinMix('t b (head cin) -> t b (head cout)', weight_shape='head cin cout', ...)

... and yes, you need to specify all dimensions of weight shape/bias shape in parameters.

Use cases:
- when channel dimension is not last, use EinMix, not transposition
- patch/segment embeddings
- when need only within-group connections to reduce number of weights and computations
- next-gen MLPs (follow tutorial link above to learn more!)
- in general, any time you want to combine linear layer and einops.rearrange

Uniform He initialization is applied to weight tensor.
This accounts for the number of elements mixed and produced.

Parameters
:param pattern: transformation pattern, left side - dimensions of input, right side - dimensions of output
:param weight_shape: axes of weight. A tensor of this shape is created, stored, and optimized in a layer
       If bias_shape is not specified, bias is not created.
:param bias_shape: axes of bias added to output. Weights of this shape are created and stored. If `None` (the default), no bias is added.
:param axes_lengths: dimensions of weight tensor
)r   r   r   r   N)ÚsuperÚ__init__r   r   r   r   Úinitialize_einmix)Úselfr   r   r   r   Ú	__class__s   &&&&,€r   r$   Ú_EinmixMixin.__init__   s?   ø€ ôT 	‰ÑÔØŒØ(ÔØ$ŒØ(ÔØ×ÑØÀ:ð 	ö 	
r   c                óB   <€ V ^8„  d   QhRS[ RS[ RS[S[ ,          RS[/# r   )r   r   Údict)r   r    s   "€r   r   r!   C   s5   ø€ ÷ v
ñ v
©ð v
¹Cð v
ÉXÑVYÍ]ð v
Ñjnñ v
r   c                ó  a€ VP                  R 4      w  rV\        V4      p\        V4      p\        V4      p	\        \        P	                  VP
                  0 VP
                  mV	P
                  m4      R4       V	P                  '       d   \        R4      hVP                  '       g   VP                  '       dS   VP                  '       d   VP                  '       g   \        RV 24      hVP                  '       d   \        RV 24      h\        ;QJ d    R WxV	3 4       F  '       g   K   RM	  RM! R WxV	3 4       4      '       d   \        R4      hR	V9   g   R
V9   d   \        RV 24      hRp
RpRp\        ;QJ d&    R VP                   4       F  '       g   K   RM	  RM! R VP                   4       4      '       d€   . pVP                   F  pWÞ,          pK  	  V Uu. uF  qÿ\        8w  d   TMRNK  	  ppRP                  V4      pV RV 2p
VP                  4        UUu/ uF  w  ppWý9   g   K  VVbK  	  ppp\        ;QJ d&    R VP                   4       F  '       g   K   RM	  RM! R VP                   4       4      '       g   VP                  '       dS   . pVP                   F  pWÞ,          pK  	  V Uu. uF  qÿ\        8w  d   TMRNK  	  ppRP                  V4      pV RV 2pV P                  W«V/ 4       V	P
                   F  pVV9  g   K  \        RV R24      h	  \        \        P	                  \        V4      0 VP
                  mV	P
                  m4      R4       \        \        P	                  V	P
                  0 VP
                  mVP
                  m4      R4       \        V	P
                  4      ^ 8X  d   \         P"                  ! R^R7       V	P                   Uu. uF  w  pVV,          NK  	  pp\%        V	P                   Uu. uF!  w  pVVP
                  9  g   K  VV,          NK#  	  up4      pVEe3   \'        V\(        4      '       g   \        R4      h\        V4      p\        \        P	                  VP
                  VP
                  4      R4       \        \        P	                  VP
                  \        V4      4      R4       . pRpVP                   FŠ  pV\        8X  d   V'       d   \        R4      hK#  V Fa  pV\        8X  d   V'       d   \        R4      hK#  VVP
                  9   d   VP+                  VV,          4       RpKP  VP+                  ^4       Kc  	  KŒ  	  MRp^V,          R,          p^V,          R,          pV P-                  VVVV4       0 VP
                  mVP
                  mV	P
                  mp\        V9   d   VP/                  \        4       \1        V4      p\3        \4        P6                  V4       UUu/ uF	  w  ppVVbK  	  uppoRS\        &   R V3R llpV! V4       R V! V	4       R V! V4       2V n        R# u upi u uppi u upi u upi u upi u uppi )!z->z7Unrecognized identifiers on the right side of EinMix {}zKEllipsis is not supported in weight, as its shape should be fully specifiedz,Ellipsis in EinMix should be on both sides, z3Ellipsis on left side can't be in parenthesis, got c              3   ó8   "  € T F  qP                   x € K  	  R # 5i©N)Úhas_non_unitary_anonymous_axes)Ú.0Úxs   & r   Ú	<genexpr>Ú1_EinmixMixin.initialize_einmix.<locals>.<genexpr>S   s   é € ÐOÑ9N°A×/Ö/Ó9Nùs   ‚TFz2Anonymous axes (numbers) are not allowed in EinMixÚ(Ú)z,Parenthesis is not allowed in weight shape: Nc              3   ó>   "  € T F  p\        V4      ^8g  x € K  	  R# 5i©é   N©r   ©r/   Úgroups   & r   r1   r2   [   s   é € Ð=Ñ,< 5Œs�5‹z˜QŽÓ,<ùó   ‚ú...Ú z-> c              3   ó>   "  € T F  p\        V4      ^8g  x € K  	  R# 5ir6   r8   r9   s   & r   r1   r2   d   s   é € Ð>Ñ,= 5Œs�5‹z˜QŽÓ,=ùr;   z ->z
Dimension z of weight should be specifiedzAxes {} are not used in patternzWeight axes {} are redundantzCEinMix: weight has no dimensions (means multiplication by a number))Ú
stacklevelzAbias shape should be string specifying which axes bias depends onz"Bias axes {} not present in outputz#Sizes not provided for bias axes {}z:all bias dimensions should go after ellipsis in the outputg      à?c                ó$   € V ^8„  d   QhR\         /# )r   r   )r	   )r   s   "r   r   Ú4_EinmixMixin.initialize_einmix.<locals>.__annotate__­   s   € ÷ 	#ñ 	#Ô&6ñ 	#r   c                 ó  <€ . pV P                    Fa  p\        V\        4      '       d+   TP                  V Uu. uF  pSV,          NK  	  up4       KC  V\        8X  g   Q hVP                  R 4       Kc  	  RP                  V4      # u upi )r<   Ú )ÚcompositionÚ
isinstanceÚlistÚextendr
   ÚappendÚjoin)r   ÚresultÚcomposed_axisÚaxisÚmapping2letterss   &   €r   Úwrite_flat_remappedÚ;_EinmixMixin.initialize_einmix.<locals>.write_flat_remapped­   sx   ø€ ØˆFØ!%×!1Ô!1�Ü˜m¬T×2Ò2Ø—M‘MÁ]Ó"SÁ]¸T ?°4×#8Ð#8Á]Ñ"SÖTà(¬IÔ5Ð5Ð5Ø—M‘M %Ö(ñ "2ð —7‘7˜6“?Ð"ùò	 #Ts   ¸B
Ú,)Úsplitr	   r   r   Ú
differenceÚidentifiersÚhas_ellipsisr   Úhas_ellipsis_parenthesizedÚanyrD   r
   rI   ÚitemsÚ_create_rearrange_layersr   ÚwarningsÚwarnr   rE   r   rH   Ú_create_parametersÚremoveÚsortedÚzipÚstringÚascii_lowercaseÚeinsum_pattern) r&   r   r   r   r   Úleft_patternÚright_patternÚleftÚrightÚweightÚpre_reshape_patternÚpre_reshape_lengthsÚpost_reshape_patternÚnamesr:   ÚnamerD   ÚlengthrL   Ú_weight_shapeÚ_fan_inÚbiasÚ_bias_shapeÚused_non_trivial_sizer   Úweight_boundÚ
bias_boundÚmapped_identifiersÚletterÚkrN   rM   s    &&&&&                          @r   r%   Ú_EinmixMixin.initialize_einmixC   só  ø€ Ø&-§m¡m°DÓ&9Ñ#ˆÜ Ó-ˆÜ  Ó/ˆÜ! ,Ó/ˆÜÜ�N‰N˜5×,Ñ,Ð.V°×0@Ñ0@Ð.VÀ6×CUÑCUÐ.VÓWØEô	
ð ××ÐÜÐkÓlÐlØ××Ð × 2× 2Ð 2Ø×%×%Ð%¨%×*<×*<Ð*<Ü!Ð$PÐQXÐPYÐ"ZÓ[Ð[Ø×.×.Ð.Ü!Ð$WÐX_ÐW`Ð"aÓbÐbß‹3ÑO¸$ÀvÑ9NÓO�3�3Š3ÑO¸$ÀvÑ9NÓO×OÒOÜÐRÓSÐSØ�,Ô #¨Ô"5ÜÐ LÈ\ÈNÐ[Ó\Ð\à"ÐØ"ÐØ#Ðß‹3Ñ=¨D×,<Ò,<Ó=�3�3Š3Ñ=¨D×,<Ò,<Ó=×=Ò=Ø!ˆEØ×)Ô)�Ø•’ñ *áFKÓLÁe¸d¤YÔ.‘T°EÒ9ÁeˆEÐLØŸ(™( 5›/ˆKØ%1 N°#°k°]Ð"CÐØDP×DVÑDVÔDXÔ"jÑDX±L°D¸&Ð\`Ñ\i¤< 4¨¢<ÑDXÐÑ"jç‹3Ñ>¨E×,=Ò,=Ó>�3�3Š3Ñ>¨E×,=Ò,=Ó>×>Ò>À%×Bb×BbÐBbØˆEØ×*Ô*�Ø•’ñ +áFKÓLÁe¸d¤YÔ.‘T°EÒ9ÁeˆEÐLØŸ(™( 5›/ˆKØ&1 ]°#°m°_Ð#EÐ à×%Ñ%Ð&9ÐPdÐfhÔià×&Ô&ˆDØ˜<Ö'Ü! J¨t¨fÐ4RÐ"SÓTÐTñ 'ô 	Ü�N‰Nœ3˜|Ó,Ð.V°×0@Ñ0@Ð.VÀ6×CUÑCUÐ.VÓWØ-ô	
ô 	Ü�N‰N˜6×-Ñ-Ð/V°×1AÑ1AÐ/VÀE×DUÑDUÐ/VÓWÐYwô	
ô ˆv×!Ñ!Ó" aÔ'Ü�MŠMÐ_ÐlmÕnà;A×;MÒ;MÓNÑ;M±°˜ d×+Ð+Ñ;MˆÐNä¸f×>PÒ>PÓrÑ>P±7°DÐTXÐ`e×`qÑ`qÑTqÔ.˜L¨×.Ð.Ñ>PÑrÓsˆØÓ!ä˜j¬#×.Ò.Ü!Ð"eÓfÐfÜ# JÓ/ˆDÜÜ—‘˜t×/Ñ/°×1BÑ1BÓCØ4ôô Ü—‘˜t×/Ñ/´°\Ó1BÓCØ5ôð
 ˆKØ$)Ð!Ø×)Ô)�Øœ9Ô$ß,Ü)Ð*fÓgÐgñ -ó !%˜Ø¤9Ô,ß4Ü&1Ð2nÓ&oÐ oñ  5à! T×%5Ñ%5Ô5Ø'×.Ñ.¨|¸DÕ/AÔBØ48Ò1à'×.Ñ.¨qÖ1ó !%ò *ð  ˆKà˜G�¨Õ+ˆØ˜'•k cÕ)ˆ
Ø×Ñ ¨|¸[È*ÔUð Z˜t×/Ñ/ÐY°%×2CÑ2CÐYÀf×FXÑFXÐYÐÜÐ*Ô*Ø×%Ñ%¤iÔ0Ü#Ð$6Ó7ÐÜ69¼&×:PÑ:PÐRdÔ6eÔfÑ6e©¨°˜1˜fš9Ñ6eÒfˆØ%*ˆœ	Ñ"÷	#ð 	#ñ # 4Ó(Ð)¨Ñ+>¸vÓ+FÐ*GÀrÑJ]Ð^cÓJdÐIeÐfð 	Öùòq Mùó #kùò Mùò& OùârùóZ gs0   Ç%Y.È)Y3È9Y3ËY9Ï4Y>ÐZÐ7ZØ&Zc          	      ór   <€ V ^8„  d   QhRS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          /# ©r   rg   rh   ri   Úpost_reshape_lengths©r   r   r   )r   r    s   "€r   r   r!   »   sI   ø€ ÷ Tñ Tá%¡c�]ðTñ &¡d�^ðTñ '¡s�mð	Tñ
 '¡t�nñTr   c                ó   € \        R 4      h)ú.Should be defined in framework implementations©ÚNotImplementedError©r&   rg   rh   ri   rz   s   &&&&&r   rX   Ú%_EinmixMixin._create_rearrange_layers»   s   € ô "Ð"RÓSÐSr   c                ó   € \        R4      h)zShape and implementationsr}   r~   ©r&   r   rr   r   rs   s   &&&&&r   r[   Ú_EinmixMixin._create_parametersÄ   s   € ä!Ð"RÓSÐSr   c                ó@  € \        V P                  4      pVR V P                   R2,          pV P                  e   VR V P                   R2,          pV P                  P                  4        F  w  r#VRV RV 2,          pK  	  V P                  P                   RV R2# )z, 'Ú'z, Ú=r3   r4   )Úreprr   r   r   r   rW   r'   Ú__name__)r&   ÚparamsrL   rl   s   &   r   Ú__repr__Ú_EinmixMixin.__repr__È   sœ   € Ü�d—l‘lÓ#ˆØ�C˜×)Ñ)Ð*¨!Ð,Õ,ˆØ�?‰?Ò&Ø˜˜DŸO™OÐ,¨AÐ.Õ.ˆFØ ×-Ñ-×3Ñ3Ö5‰LˆDØ˜˜4˜&  & Ð*Õ*ŠFñ 6à—.‘.×)Ñ)Ð*¨!¨F¨8°1Ð5Ð5r   )r   r   ra   r   r   r-   )r‰   Ú
__module__Ú__qualname__Ú__firstlineno__r$   r%   rX   r[   r‹   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r'   r    s   @@r   r   r      s9   ù‡ € ÷1
õ 1
÷fv
ð v
÷pTð TòT÷6ò 6r   r   c                   ó<   a € ] tR t^Òt o RtV 3R lR ltR tRtV tR# )Ú_EinmixDebuggerzUsed only to test mixinc          	      ór   <€ V ^8„  d   QhRS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          /# ry   r{   )r   r    s   "€r   r   Ú_EinmixDebugger.__annotate__Õ   sC   ø€ ÷ 
9ñ 
9á%¡c�]ð
9ñ &¡d�^ð
9ñ '¡s�mð	
9ñ
 '¡t�nñ
9r   c                ó6   € Wn         W n        W0n        W@n        R # r-   )rg   rh   ri   rz   r€   s   &&&&&r   rX   Ú(_EinmixDebugger._create_rearrange_layersÕ   s   € ð $7Ô Ø#6Ô Ø$8Ô!Ø$8Ö!r   c                ó   € Wn         W0n        R # r-   )Úsaved_weight_shapeÚsaved_bias_shaperƒ   s   &&&&&r   r[   Ú"_EinmixDebugger._create_parametersá   s   € Ø".ÔØ *Ör   )rz   ri   rh   rg   r›   rš   N)	r‰   r�   rŽ   r�   Ú__doc__rX   r[   r�   r‘   )r    s   @r   r”   r”   Ò   s   ø‡ € Ù!÷
9ð 
9÷+ð +r   r”   )r_   rY   Útypingr   r   r   r   Úeinopsr   Úeinops.einopsr   Úeinops.parsingr	   r
   r   r   r”   © r   r   Ú<module>r£      s8   ðÛ Û ß ,Ó ,å Ý "ß 6õ7÷
@6ñ @6ôF+�lö +r   