+
    –°³j26  ã                  ó  a € 0 t $ ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIH	t	 ^ RI
t
^ RIt^ RIHt ^ RIt^ RIHt ^RIHtHt ^RIHtHtHtHtHtHtHt ^RIHtH t  ^R	I!H"t" ^R
I#H$t$H%t% ]'       d	   ^ RI&H't'H(t( Rt)Rs*R]+R&   ]PX                   ! R R4      4       t-]PX                   ! R R4      4       t.R R lt/R R lt0]Pb                  R R l4       t2R R lt3 ! R R]4      t4R R lt5 ! R R 4      t6R! R" lt7R# R$ lt8R# )%é    )ÚannotationsN)ÚAnyÚTYPE_CHECKING)Úpatch)Ú
OrderedSet)ÚconfigÚselect_algorithm)ÚBufferÚChoiceCallerÚLayoutÚMultiTemplateBufferÚOperationBufferÚ
StorageBoxÚ	TensorBox)ÚKernelInputsÚMMKernelInputs)ÚSchedulerNode)ÚNullHandlerÚV)Ú	GeneratorÚSequenceÚdistributed_autotuneúdist.ProcessGroup | NoneÚ_AUTOTUNE_PGc                  ó8   € ] tR t^'t$ Rt^ tR]R&   ^ tR]R&   RtR# )Ú_DistributedAutotuneStatez9
State used to track autotuning during a graph_context()
ÚintÚautotuned_indexÚautotuned_local_count© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotations__r   Ú__static_attributes__r    ó    Úe/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_inductor/distributed_autotune.pyr   r   '   s    ‡ ñð €O�SÓð "#Ð˜3×"r(   r   c                  ó,   € ] tR t^6t$ R]R&   R]R&   RtR# )Ú_DistributedAutotuneInfor   ÚindexÚboolÚlocalr    N)r!   r"   r#   r$   r&   r'   r    r(   r)   r+   r+   6   s   ‡ àƒJØ‡Kr(   r+   c               ó   € V ^8„  d   QhRR/# )é   Úreturnr   r    )Úformats   "r)   Ú__annotate__r3   <   s   € ÷ ñ Ð1ñ r(   c                 ó&  € \         P                  ! 4       '       dv   \         P                  ! 4       '       d[   \        fM   \         P                  P                  RR7      p V \         P                  P                  8X  d   \        R4      hV s\        # R # )NÚpt2_distributed_autotune_pg)Úpg_tagz-Autotune process group must include all ranks)	ÚdistÚis_availableÚis_initializedr   Údistributed_c10dÚ_new_group_with_tagÚGroupMemberÚNON_GROUP_MEMBERÚAssertionError)Úautotune_pgs    r)   Úget_autotune_pgr@   <   st   € Ü×Ò×Òœt×2Ò2×4Ò4äÒÜ×/Ñ/×CÑCØ4ð Dó ˆKð œd×.Ñ.×?Ñ?Ô?Ü$Ð%TÓUÐUØ&ˆLÜÐár(   c               ó    € V ^8„  d   QhRRRR/# )r0   Ú	schedulerú#torch._inductor.scheduler.Schedulerr1   ÚNoner    )r2   s   "r)   r3   r3   K   s   € ÷ 	8ñ 	8Ð;ð 	8Àñ 	8r(   c                óŠ   € \         P                  '       g   \        R4      h\        V 4      p\	        V4      p\        W4       R# )z”
Finish the distributed autotuning by propagating the autotuning results
between the ranks and then replacing the placeholder with the real Buffer.
z4distributed_max_autotune_gemm config must be enabledN)r   Údistributed_max_autotune_gemmr>   Ú_autotune_local_nodesÚ_syncÚ_autotune_remote_nodes)rB   Úautotune_resultsÚchoices_by_indexs   &  r)   ÚschedulerL   K   s;   € ô
 ×/×/Ð/ÜÐSÓTÐTÜ,¨YÓ7ÐÜÐ-Ó.ÐÜ˜9Ö7r(   c               ó   € V ^8„  d   QhRR/# )r0   r1   zGenerator[None, None, None]r    )r2   s   "r)   r3   r3   X   s   € ÷ 8ñ 8Ð2ñ 8r(   c               #  óB  "  € \        \        P                  ! RR7      \        4      '       d   \	        R4      h\        P
                  ! \        4       4        Rx € \        P
                  ! \        4       4       R#   \        P
                  ! \        4       4       i ; i5i)zX
Wrapped around processing a graph, sets up figuring out which ranks tune
which shapes.
F)Úcheck_poisonedzQdistributed autotune state is already active, nested graph_context is not allowedN)Ú
isinstancer   Úget_distributed_autotune_stater   r>   Úset_distributed_autotune_stater   r    r(   r)   Úgraph_contextrS   W   ss   é € ô Ü	×(Ò(¸Ô>Ü!÷ò ô Ø_ó
ð 	
ô ×$Ò$Ô%>Ó%@ÔAð8Ûä	×(Ò(¬«Ö7øŒ×(Ò(¬«Õ7üs   ‚ABÁA< Á BÁ< BÂBc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r0   ÚnameÚstrÚchoiceszlist[ChoiceCaller]Úinputsúlist[Buffer]Úlayoutr   r1   zTensorBox | Noner    )r2   s   "r)   r3   r3   k   s4   € ÷ ñ Ø
ðØ*ðØ4@ðØJPðàñr(   c                óJ  € \         P                  '       g   R# \        4       ;p'       g   R# \        V4      ^8:  d   R# \        P
                  pVP                  pV;P                  ^,          un        WdP                  4       ,          VP                  4       8H  p\        Wg4      \        P                  P                  \        &   V'       d   V;P                  ^,          un        R# \        P                  P                   P"                  P%                  \'        WV4      4      # )z‰
Used by an op (like `mm`) to determine if the op should be autotuned
locally (returns None) or remotely (returns a placeholder Buffer).
N)r   rF   r@   Úlenr   Údistributed_autotune_stater   ÚsizeÚrankr+   Úcurrent_nodeÚmetaÚ_DISTRIBUTED_AUTOTUNE_KEYr   ÚtorchÚ	_inductorÚirr   ÚcreateÚ_DistributedAutotuneBuffer)rU   rW   rX   rZ   r?   Ústater,   r.   s   &&&&    r)   Úmaybe_autotune_remoteri   k   sÜ   € ô ×/×/Ð/Ùä*Ó,Ð,ˆKÖ,Ùä
ˆ7ƒ|�qÔÙä×(Ñ(€EØ×!Ñ!€EØ	×Ò˜QÕÕØ×$Ñ$Ó&Õ&¨+×*:Ñ*:Ó*<Ñ<€Eä5MØó6„A‡N�N×ÑÔ1Ñ2÷ Ø×#Ò# qÕ(Õ#Ùä�?‰?×Ñ×'Ñ'×.Ñ.Ü" 4°Ó8óð r(   c                  óV   a € ] tR t^Œt$ RtR]R&   R V 3R lltR R ltR R	 ltR
t	V ;t
# )rg   zœ
A MultiTemplateBuffer which represents a kernel being autotuned on a
different rank. When `schedule` is called this will be replaced by the
"real" buffer.
rV   Ú_kernel_namec               ó(   € V ^8„  d   QhRRRRRRRR/# )	r0   Úkernel_namerV   rX   rY   rZ   r   r1   rD   r    )r2   s   "r)   r3   Ú'_DistributedAutotuneBuffer.__annotate__–   s2   € ÷ (ñ (àð(ð ð(ð ð	(ð
 
ñ(r(   c           	     	ób   <€ \         SV `  VVV P                  . \        / 4      R 7       Wn        R# ))Úchoice_timings_fnÚunfiltered_choicesÚallowed_prologue_inpsN)ÚsuperÚ__init__Ú_dummy_choice_timingsr   rk   )Úselfrm   rX   rZ   Ú	__class__s   &&&&€r)   rt   Ú#_DistributedAutotuneBuffer.__init__–   s8   ø€ ô 	‰ÑØØØ"×8Ñ8Ø!Ü",¨R£.ð 	ô 	
ð (Ör(   c               ó    € V ^8„  d   QhRRRR/# )r0   Ú_hint_overridez
int | Noner1   zdict[ChoiceCaller, float]r    )r2   s   "r)   r3   rn   ¦   s   € ÷ "ñ "Ø(ð"à	"ñ"r(   c                	ó   € \         h©N)ÚNotImplementedError)rv   rz   s   &&r)   ru   Ú0_DistributedAutotuneBuffer._dummy_choice_timings¦   s
   € ô
 "Ð!r(   c               ó    € V ^8„  d   QhRRRR/# )r0   Ú
ser_choiceÚ_SerializedChoicer1   r   r    )r2   s   "r)   r3   rn   ­   s   € ÷ ñ Ð#4ð ¸ñ r(   c                óN  € ^RI Hp \        P                  ! \        P
                  RR4      ;_uu_ 4        \        . V P                  O4      p\        V P                  \        4      '       g"   \        R\        V P                  4       24      hVP                  V P                  V4      pV! V P                  V.VP                  4       V P                  4      w  rV\        V\         4      '       g   \        R\        V4       24      hVuuRRR4       #   + '       g   i     R# ; i)z]
Given a _SerializedChoice (autotune results from another rank)
compute the final TensorBox.
)Úautotune_select_algorithmrB   NzExpected Layout, got zExpected TensorBox, got )r	   rƒ   r   Úobjectr   Úgraphr   Úoriginal_inputsrP   rZ   r   r>   ÚtypeÚ
get_choicerk   Únodesr   )rv   r€   rƒ   Úkernel_inputsÚchoiceÚbufferÚ_s   &&     r)   ÚautotuneÚ#_DistributedAutotuneBuffer.autotune­   sÞ   € õ 	@ä�\Š\œ!Ÿ'™' ;°×5Õ5Ü*Ð+B¨T×-AÑ-AÐ+BÓCˆMÜ˜dŸk™k¬6×2Ò2Ü$Ð'<¼TÀ$Ç+Á+Ó=NÐ<OÐ%PÓQÐQØ×*Ñ*¨4¯;©;¸ÓFˆFÙ1Ø×!Ñ!Ø�Ø×#Ñ#Ó%Ø—‘ó	‰IˆFô ˜f¤i×0Ò0Ü$Ð'?ÄÀVÃ¸~Ð%NÓOÐOØ÷ 6×5×5Ó5ús   µCDÄD$	)rk   )r!   r"   r#   r$   r%   r&   rt   ru   rŽ   r'   Ú__classcell__)rw   s   @r)   rg   rg   Œ   s)   ø‡ ñð Ó÷(ð (õ "÷ó r(   rg   c               ó    € V ^8„  d   QhRRRR/# )r0   rJ   úlist[_SerializedChoice]r1   úSequence[_SerializedChoice]r    )r2   s   "r)   r3   r3   Æ   s   € ÷ ñ Ð3ð Ð8Sñ r(   c                ó   € \        4       pV'       g   \        R4      hR.VP                  4       ,          p\        P                  P                  W VR7       \        R V 4       4      pR.V,          p^ pV F|  pV Fs  p\        V\        4      '       g   \        R\        V4       24      hWGP                  ,          e   \        RVP                   24      hWtVP                  &   V^,          pKu  	  K~  	  W58w  d   \        RV RV 24      hV# )	zL
Perform the all_gather to collect the autotune results from all the ranks.
z)autotune process group is not initializedN)Úgroupc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir|   )r\   )Ú.0Úxs   & r)   Ú	<genexpr>Ú_sync.<locals>.<genexpr>Ó   s   é € Ð0¡Z ”S˜—V�V£Zùs   ‚z Expected _SerializedChoice, got zduplicate choice for index zcount mismatch: ú != )r@   r>   r^   rc   ÚdistributedÚall_gather_objectÚsumrP   r�   r‡   r,   )rJ   r?   Ú
all_statesÚ
node_countrK   Úcheck_countÚother_resultsr‹   s   &       r)   rH   rH   Æ   s  € ô
 "Ó#€KßÜÐHÓIÐIð 26°¸×9IÑ9IÓ9KÕ0K€JÜ	×Ñ×'Ñ'¨
ÈKÐ'ÔXäÑ0¡ZÓ0Ó0€Jà15°¸Õ0CÐà€KÛ#ˆÛ#ˆFÜ˜fÔ&7×8Ò8Ü$Ð'GÌÈVËÀ~Ð%VÓWÐWØ§¡Õ-Ò9Ü$Ð'BÀ6Ç<Á<À.Ð%QÓRÐRØ-3˜VŸ\™\Ñ*Ø˜1ÕŠKó $ñ $ð Ô ÜÐ/°
¨|¸4À¸}ÐMÓNÐNØÐr(   c                  ój   € ] tR t^ætRtR R ltR R lt]R R l4       t]R R	 l4       t	R
 R lt
RtR# )r�   zÆ
This is a serializer for the autotune choice. KernelTemplateChoice can't
be serialized directly (the template and inputs prevent this) so we need to
serialize it by parts and reconstruct later on.
c               ó$   € V ^8„  d   QhRRRRRR/# )r0   r,   r   r‹   r   r1   rD   r    )r2   s   "r)   r3   Ú_SerializedChoice.__annotate__í   s!   € ÷ ?ñ ?˜cð ?¨<ð ?¸Dñ ?r(   c                	ó†   € Wn         \        P                  V4      V n        V P	                  VP
                  4      V n        R # r|   )r,   r�   Ú_template_uid_from_choiceÚtemplate_uidÚ_compute_kwargsÚdescriptionÚkwargs)rv   r,   r‹   s   &&&r)   rt   Ú_SerializedChoice.__init__í   s2   € ØŒ
Ü-×GÑGÈÓOˆÔØ×*Ñ*¨6×+=Ñ+=Ó>ˆŽr(   c               ó$   € V ^8„  d   QhRRRRRR/# )r0   rZ   r   rX   r   r1   zChoiceCaller | Noner    )r2   s   "r)   r3   r¥   ò   s"   € ÷ ñ  ð °ð ÐBUñ r(   c                óH  € V P                  4       p/ V P                  CpRV9   dW   VP                  4       ^ ,          P                  4       ^,          p\        P
                  ! WTR,          4      VR,          8H  VR&   / p^RIHpHp V! V4      p	V! W9WaV4      p
V
P                  # )z-
Deserialize the ChoiceCaller and return it.
ÚBLOCK_KÚEVEN_K)ÚDictKernelTemplateParamsÚKernelTemplateChoice)
Ú_template_from_uidr«   r‰   Úget_sizeÚsympyÚgcdÚkernel_template_choicer±   r²   r‹   )rv   rZ   rX   Útemplater«   ÚkÚextra_kwargsr±   r²   ÚparamsÚktcs   &&&        r)   rˆ   Ú_SerializedChoice.get_choiceò   s—   € ð
 ×*Ñ*Ó,ˆà �D—K‘K�ˆØ˜Ôð
 —‘“˜qÕ!×*Ñ*Ó,¨QÕ/ˆAÜ$Ÿyšy¨°9Õ,=Ó>À&ÈÕBSÑSˆF�8Ñà')ˆ÷	
ñ
 *¨&Ó1ˆÙ" 8°\È6ÓRˆØ�z‰zÐr(   c               ó    € V ^8„  d   QhRRRR/# )r0   rª   rV   r1   zdict[str, int | str | bool]r    )r2   s   "r)   r3   r¥     s   € ÷ ñ  Sð Ð-Hñ r(   c                óº  € V '       g   / # / pV P                  R4       F¹  pVP                  R^4      w  r4VP                  4       VP                  4       rCVR8X  d   RW&   KC  VR8X  d   RW&   KP  VP                  4       '       d   \        V4      W&   Ku  VP	                  R4      '       d   VP                  R4      '       g   \        RV: 24      hV^R	 W&   K»  	  V# )
z9
Given a template description turn it into input kwargs.
Ú,Ú=ÚTrueTÚFalseFÚ'z/expected string value to be single-quoted, got éÿÿÿÿ)ÚsplitÚstripÚisdigitr   Ú
startswithÚendswithr>   )rª   r«   ÚcfgÚkeyÚvals   &    r)   r©   Ú!_SerializedChoice._compute_kwargs  sÉ   € ÷
 ØˆIð /1ˆØ×$Ñ$ SÖ)ˆCØ—y‘y  aÓ(‰HˆCØ—y‘y“{ C§I¡I£K�Ø�fŒ}Ø"�“Ø˜”Ø#�“Ø—‘—’Ü! #›h�“àŸ™ s×+Ò+°·±¸S×0AÒ0AÜ(ØIÈ#ÉÐQóð ð " ! B˜i�“ñ *ð ˆr(   c               ó    € V ^8„  d   QhRRRR/# )r0   r‹   r   r1   rV   r    )r2   s   "r)   r3   r¥   )  s   € ÷ 8ñ 8¨,ð 8¸3ñ 8r(   c                ó4  € \        V \        P                  4      '       dA   V P                  P                  R8X  d   R# \        RV P                  P                  : 24      h\        V \        P                  4      '       d   R# \        R\        V 4       24      h)zi
Given a ChoiceCaller figure out which template represents it. This
is reversed by _template_from_uid().
Úmmz!torch._inductor.kernel.mm.aten_mmzTODO: kernel z%torch._inductor.kernel.mm.mm_templatezTODO: )rP   r	   ÚExternKernelCallerr‹   rU   ÚRuntimeErrorÚTritonTemplateCallerr‡   )r‹   s   &r)   r§   Ú+_SerializedChoice._template_uid_from_choice(  sw   € ô �fÔ.×AÑA×BÒBØ�}‰}×!Ñ! TÔ)Ù:ä" ]°6·=±=×3EÑ3EÑ2HÐ#IÓJÐJÜ˜Ô 0× EÑ E×FÒFÙ:ä ¬¨V« ~Ð6Ó7Ð7r(   c               ó   € V ^8„  d   QhRR/# )r0   r1   r   r    )r2   s   "r)   r3   r¥   ;  s   € ÷ ñ  Cñ r(   c                ó¢   € V P                   P                  R4      p\        4       V^ ,          ,          pVR,           F  p\        W#4      pK  	  V# )z"
See _template_uid_from_choice().
Ú.:é   NN)r¨   rÆ   ÚglobalsÚgetattr)rv   ÚpartsÚobjr¹   s   &   r)   r³   Ú$_SerializedChoice._template_from_uid;  sH   € ð ×!Ñ!×'Ñ'¨Ó,ˆÜ‹i˜˜a�Õ!ˆØ�r—�ˆAÜ˜#“/ŠCñ àˆ
r(   )r,   r«   r¨   N)r!   r"   r#   r$   r%   rt   rˆ   Ústaticmethodr©   r§   r³   r'   r    r(   r)   r�   r�   æ   sC   † ñõ?õ
ð4 ôó ðð6 ô8ó ð8÷$ñ r(   r�   c               ó    € V ^8„  d   QhRRRR/# )r0   rB   rC   r1   r’   r    )r2   s   "r)   r3   r3   F  s   € ÷ 4ñ 4Ø2ð4àñ4r(   c                ó¬  € . pV P                    Fò  p\        V\        4      '       g   K  VP                  ;pf   K-  \        V\        4      '       d   KE  \        V\
        4      '       g   K]  VP                  ;pf   Ko  VP                  ;pf   K�  VP                  \        4      pVf   Kœ  VP                  '       g   \        R4      hVP                  4       w  rx\        VP                  V4      p	VP                  V	4       Kô  	  \         P"                  p
\%        V4      V
P&                  8w  d&   \        R\%        V4       RV
P&                   R24      hV# )zh
Go through the nodes in the scheduler and autotune the kernels which
should be autotuned by this rank.
z9expected info.local to be True for locally autotuned nodez'incorrect local autotuned nodes found (r›   Ú))r‰   rP   r   Únoderg   r   Úorigin_nodera   Úgetrb   r.   r>   Úget_min_choicer�   r,   Úappendr   r]   r\   r   )rB   rJ   rã   Ú
inner_noderä   ra   ÚinfoÚ
min_choicer�   r‹   rh   s   &          r)   rG   rG   F  s>  € ð 13Ðà—”ˆÜ˜$¤×.Ò.ÙàŸ)™)Ð#ˆJÒ,Ùä�jÔ"<×=Ò=áä˜*Ô&9×:Ò:Ùà%×1Ñ1Ð1ˆKÒ:Ùà×$Ñ$Ð$ˆDÒ-Ùà�x‰xÔ1Ó2ˆØŠ<Ùà�z�zˆzÜ ØKóð ð #×1Ñ1Ó3‰ˆ
ä" 4§:¡:¨zÓ:ˆØ×Ñ Ö'ñG  ôJ ×(Ñ(€EÜ
ÐÓ × ;Ñ ;Ô;ÜØ5´cÐ:JÓ6KÐ5LÈDÐQV×QlÑQlÐPmÐmnÐoó
ð 	
ð Ðr(   c               ó$   € V ^8„  d   QhRRRRRR/# )r0   rB   rC   rK   r“   r1   rD   r    )r2   s   "r)   r3   r3   }  s+   € ÷  Dñ  DØ2ð Dà1ð Dð 
ñ Dr(   c                óü  € \        V P                  4       EFa  w  r#\        V\        4      '       g   K  \        VP                  ;p\
        4      '       g   KB  VP                  f   \        R4      hVP                  P                  \        ,          pVP                  WP                  ,          4      pVP                  p\        V\        4      '       g   \        R\        V4       24      hVP                  p\        V\        4      '       g   \        R\        V4       24      hVP                   VP                   8w  d&   \        RVP                    RVP                    24      hV P#                  W„W#4       EKd  	  R# )zc
Go through the nodes in the scheduler and autotune the nodes that were
autotuned on remote ranks.
Nz&dist_node.origin_node must not be NonezExpected StorageBox, got zExpected OperationBuffer, got zlayout mismatch: r›   )Ú	enumerater‰   rP   r   rã   rg   rä   r>   ra   rb   rŽ   r,   Údatar   r‡   r   rZ   Ú_replace_node)	rB   rK   Úirã   Ú	dist_noderé   Úout_tensorboxÚout_storageÚ
out_buffers	   &&       r)   rI   rI   }  sC  € ô ˜YŸ_™_×-‰ˆÜ�dœM×*Ô*¬zØŸ)™)Ð#ˆYÔ&@÷0
ô 0
ð ×$Ñ$Ò,Ü$Ð%MÓNÐNØ×(Ñ(×-Ñ-Ô.GÕHˆDØ%×.Ñ.Ð/?Ç
Á
Õ/KÓLˆMà'×,Ñ,ˆKÜ˜k¬:×6Ò6Ü$Ð'@ÄÀkÓARÐ@SÐ%TÓUÐUØ$×)Ñ)ˆJÜ˜j¬/×:Ò:Ü$Ø4´T¸*Ó5EÐ4FÐGóð ð × Ñ  I×$4Ñ$4Ô4Ü$Ø'¨
×(9Ñ(9Ð':¸$¸y×?OÑ?OÐ>PÐQóð ð ×#Ñ# J¸1×Có/ .r(   )9Ú__conditional_annotations__Ú
__future__r   Ú
contextlibÚdataclassesÚtypingr   r   Úunittest.mockr   rµ   Útorch._loggingrc   Útorch.distributedrœ   r7   Útorch.fxÚtorch.utils._ordered_setr   Ú r   r	   re   r
   r   r   r   r   r   r   rŠ   r   r   rB   r   Úvirtualizedr   r   Úcollections.abcr   r   rb   r   r&   Ú	dataclassr   r+   r@   rL   ÚcontextmanagerrS   ri   rg   rH   r�   rG   rI   )rõ   s   @r)   Ú<module>r     sô   øðß "Ð "ã Û ß %Ý ã ã Ý  Û Ý /ç &÷÷ ñ ÷ 8Ý $ß '÷ ß3ð 3Ð à)-€Ð&Ó -ð ×Ñ÷#ð #ó ð#ð ×Ñ÷ð ó ðõ
õ	8ð ×Ñô8ó ð8õ&ôB6Ð!4ô 6õt÷@]ñ ]õ@4÷n Dr(   