+
    –°³jD.  ã                  ó–  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
HtHtHtHtHt ]'       d	   ^ RIHtHt ^ RIt^ RIHt . R$OtR]R	&   ]P2                  ! ]4      t]! R
4      t]	 ! R R]],          4      4       tRRRRR^ RR/R R lltR%R R lltR 3R R llt R R lt!R R lt"R R lt#R R lt$R  R! lt%R" R# lt&R# )&zl
A set of primitive functions for performing collective ops.

Each should also handle single rank scenario.
)ÚannotationsN)Údefaultdict)Ú	dataclass)ÚAnyÚcastÚGenericÚTYPE_CHECKINGÚTypeVar)ÚCallableÚIterableÚSyncPayloadz	list[str]Ú__all__ÚTc                  óD   € ] tR t^&t$ R]R&   R]R&   R]R&   RtR]R	&   R
tR# )r   ú
str | NoneÚ
stage_nameÚboolÚsuccessr   ÚpayloadNzException | NoneÚ	exception© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotations__r   Ú__static_attributes__r   ó    Úc/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/collective_utils.pyr   r   &   s   ‡ àÓØƒMØƒJØ"&€IÐ×&r   r   Tr   ÚrankÚpgc               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )é   Ú
data_or_fnúT | Callable[[], T]r   r   r   r   r   Úintr    údist.ProcessGroup | NoneÚreturnr   r   )Úformats   "r   Ú__annotate__r)   .   sN   € ÷ M%ñ M%Ø#ðM%ð ðM%ð ð	M%ð
 ðM%ð 	!ðM%ð ñM%r   c               ó¸  € V'       g   V e   \        R4      hRpRpVf   V^ 8X  g   Ve2   VP                  4       V8X  d   \        V 4      '       d
    V ! 4       pMT p\	        VVVVR7      pVeL   V.p	\
        P                  ! W“VR7       \        V	4      ^8w  d   \        R\        V	4       24      hV	^ ,          pVP                  '       g[   RV R2p
Ve   V
R	VP                   2,          p
VP                  e   V
R
VP                   2,          p
\        V
4      VP                  h\        \        VP                  4      #   \         d   pRpTp Rp?LøRp?ii ; i)a  
Broadcasts the data payload from rank 0 to all other ranks.
Or if a function is passed, execute it in rank 0 and broadcast result to all other ranks.

Can be used to broadcast a failure signal to stop all ranks.

If the function raises an exception, all ranks will raise.

Args:
    data_or_fn: the data to broadcast or function to execute and broadcast result.
    success: False to stop all ranks.
    stage_name: the name of the logical stage for synchronization and debugging
    rank: rank to broadcast data or execute function and broadcast results.
    pg: the process group for sync
Throws:
    RuntimeError from original exception trace
Returns:
    the value after synchronization

Example usage:
>> id = broadcast(data_or_fn=allocate_id, rank=0, pg=ext_pg.my_pg)
Nz9Data or Function is expected to be None if not successfulF©r   r   r   r   )ÚsrcÚgroupz7Expected broadcast_list to have exactly 1 element, got zRank z failedz: stage z: exception )ÚAssertionErrorr   ÚcallableÚ	Exceptionr   ÚdistÚbroadcast_object_listÚlenr   r   r   ÚRuntimeErrorr   r   r   )r#   r   r   r   r    r   r   ÚeÚsync_objÚbroadcast_listÚ	error_msgs   &$$$$      r   Ú	broadcastr9   .   so  € ÷> �zÒ-ÜØGó
ð 	
ð €GØ"&€Ià
Š
�t˜q”y b¢n¸¿¹»ÀdÔ9Jä�J×ÒðÙ$›,‘ð
 !ˆGô ØØØØô	€Hð 
‚~Ø"˜ˆÜ×"Ò" >À2ÕFÜˆ~Ó !Ô#Ü ØIÌ#ÈnÓJ]ÐI^Ð_óð ð " !Õ$ˆð ××ÐØ˜D˜6 Ð)ˆ	ØÒ!Ø˜8 H×$7Ñ$7Ð#8Ð9Õ9ˆIØ×ÑÒ)Ø˜<¨×(:Ñ(:Ð';Ð<Õ<ˆIä˜9Ó%¨8×+=Ñ+=Ð=ä”�8×#Ñ#Ó$Ð$øôC ô Ø�Ø•	ûðús   ÁE  Å EÅEÅEc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r"   r#   r$   r   r   r    r&   r'   zlist[T]r   )r(   s   "r   r)   r)   ~   s6   € ÷ I"ñ I"Ø#ðI"àðI"ð 	!ðI"ð ñ	I"r   c                ó¬  € RpRpRp\        V 4      '       d
    V ! 4       pMT p\        VVVVR7      pVEeA   R.\        P                  ! V4      ,          p\        W(V4       \        \        \        ,          V^ ,          4      P                  p. p	. p
Rp\        \        \        \        \        ,          ,          V4      4       F‹  w  rÍVP                  V8w  d   VRV RVP                   R2,          pK2  VP                  '       g-   VP                  e   V	P                  WÍP                  34       Kp  V
P                  VP                  4       K�  	  \        V	4      ^ 8”  d   \!        VV	4      V	^ ,          hV
# VP                  '       g$   \!        R	VP                   24      VP                  hVP                  .#   \         d   pRpTp Rp?EL«Rp?ii ; i)
aú  
A simple all_gather primitive with basic synchronization guard logic,
by checking payload from all ranks has the same stage name.

Args:
    data_or_fn: the data to be all gathered across ranks or function to be executed
    stage_name: the sync stage name for out-of-sync protection
    pg: the process group for sync
Throws:
    RuntimeError from original exception trace
Returns:
    a list of synced data from all ranks

Example usage:
>> all_ids = all_gather(data_or_fn=allocate_id, pg=ext_pg.my_pg)
NTFr+   Ú z)Unexpected stage name received from rank z: Ú z!all_gather failed with exception )r/   r0   r   r1   Úget_world_sizeÚall_gather_object_enforce_typer   r   r   Ú	enumerateÚlistr   r   Úappendr   r3   r4   )r#   r   r    r   r   r   r5   r6   Ú
total_listÚexception_listÚret_listr8   ÚiÚsps   &&&           r   Ú
all_gatherrH   ~   sº  € ð* €GØ"&€IØ€Gä�
×Òð	Ù “l‰Gð
 ˆäØØØØô	€Hð 
ƒ~à�Vœd×1Ò1°"Ó5Õ5ˆ
Ü& r°xÔ@äœ+¤a�.¨*°Q­-Ó8×CÑCˆ
Ø68ˆØˆØˆ	äœt¤D¬´Q­Õ$8¸*ÓEÖF‰EˆAØ�}‰} 
Ô*ØØ?À¸sÀ"ÀRÇ]Á]ÀOÐSTÐUõ�	ñ Ø—:—:�: "§,¡,Ò":Ø×%Ñ% q¯,©,Ð&7Ô8ÙØ�O‰O˜BŸJ™JÖ'ñ Gô ˆ~Ó Ô"ÜØØóð " !Õ$ð%ð ˆà××ÐÜØ3°H×4FÑ4FÐ3GÐHóà×%Ñ%ð&ð × Ñ Ð!Ð!øô[ ô 	ØˆGØŽIûð	ús   ™F9 Æ9GÇGÇGc                ó.   € \        V 4      \        V4      J # )N)Útype)ÚxÚys   &&r   Ú<lambda>rM   Ô   s   € ¼DÀ»GÄtÈAÃwÑ<Nr   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r"   r    údist.ProcessGroupÚobject_listz	list[Any]Úobjr   Útype_checkerzCallable[[Any, Any], bool]r'   ÚNoner   )r(   s   "r   r)   r)   Í   s<   € ÷ "ñ "Øð"ð ð"ð
 
ð"ð -ð"ð 
ñ"r   c                ó  € \         P                  ! WV R7       \        V4      pV^ 8X  d   R# V^ ,          p\        ^V4       FD  pV! WQV,          4      '       d   K  \	        RV R\        W,          4       R\        V4       24      h	  R# )a&  
Similar to plain all_gather_object but with additional type checking
AFTER gather is done to ensure basic consistency.
If check does not pass, all ranks will fail with exception.

This is generally to prevent conditional logic leading to
unexpected messages being received. This is considered fatal code error,
but due to logic stacks this might happen implicitly in practice.

The default check does not check sub type (considered different)
or covariance (considered same) but users can pass in custom checker
if more complicated check is needed.
)r-   NzObject type at index z is z, while first object type is )r1   Úall_gather_objectr3   ÚrangeÚ	TypeErrorrJ   )r    rP   rQ   rR   Úlist_lenÚ	first_objrF   s   &&&&   r   r?   r?   Í   s‹   € ô, 	×Ò˜;°2Õ6ô �;Ó€HØ�1„}ÙØ˜A•€IÜ�1�hÖˆÙ˜I°1¥~×6Ô6ÜØ'¨ s¨$¬t°KµNÓ/CÐ.Dð E.Ü.2°9«oÐ->ð@óð ó  r   c               ó    € V ^8„  d   QhRRRR/# )r"   ÚrankszIterable[int]r'   Ústrr   )r(   s   "r   r)   r)   ò   s   € ÷ (ñ (˜Mð (¨cñ (r   c                óà  € \        V 4      p \        V 4      ^ 8  d   \        R4      h\        \	        V 4      4      \        V 4      8w  d   \        R4      hRp. pV '       dó   V P                  ^ 4      pVf   TpK!  \        V\        4      '       d@   W1^,           8X  d   \        W^,           ^4      pKY  W1,
          p\        WV,           V4      pKv  \        V\        4      '       g   \        R4      hW1P                  8X  d?   \        VP                  VP                  VP                  ,           VP                  4      pKå  VP                  V4       TpKú  \        V\        4      '       d$   VP                  \        W^,           ^4      4       M'\        V\        4      '       d   VP                  V4       . pV F¥  p\        V4      ^8X  d   VP                  VP                   4       K1  VP                  ^8X  d-   VP                  VP                   RVP                   24       Kn  VP                  VP                   RVP                   RVP                   24       K§  	  RP                  V4      # )é    zranks should all be positivez#ranks should not contain duplicatesNz!curr must be an instance of rangeÚ:Ú,)ÚsortedÚminr.   r3   ÚsetÚpopÚ
isinstancer%   rV   ÚstopÚstartÚsteprB   Újoin)r[   ÚcurrÚrangesrK   rh   ÚresultÚrs   &      r   Ú_summarize_ranksrn   ò   sÆ  € Ü�5‹M€EÜ
ˆ5ƒz�A„~ÜÐ;Ó<Ð<Ü
Œ3ˆu‹:ƒœ#˜e›*Ô$ÜÐBÓCÐCØ#€DØ€Fß
Ø�I‰I�a‹LˆØŠ<ØŠDÜ˜œc×"Ò"Ø˜1•HŒ}Ü˜T q¥5¨!Ó,’à•x�Ü˜T t¥8¨TÓ2’ä˜d¤E×*Ò*Ü$Ð%HÓIÐIØ—I‘IŒ~Ü˜TŸZ™Z¨¯©°T·Y±YÕ)>ÀÇ	Á	ÓJ’à—‘˜dÔ#Ø’ä�$œ×ÒØ�‰”e˜D¨¥(¨AÓ.Õ/Ü	�Dœ%×	 Ò	 Ø�‰�dÔà€FÛˆÜˆq‹6�QŒ;Ø�M‰M˜QŸW™W˜IÖ'Ø�V‰V�qŒ[Ø�M‰M˜QŸW™W˜I Q q§v¡v hÐ/Ö0à�M‰M˜QŸW™W˜I Q q§v¡v h¨a°·±¨xÐ8Ö9ñ ð �8‰8�FÓÐr   c               ó$   € V ^8„  d   QhRRRRRR/# ©r"   Ú	generatorútorch.Generatorr-   rO   r'   ztuple[dict[Any, set], str]r   )r(   s   "r   r)   r)     ó$   € ÷ /ñ /Øð/Ø'8ð/àñ/r   c                ó`  € V P                  4       p\        VP                  4       4       Uu. uF  p\        P                  ! V4      NK  	  pp\        P
                  P                  WB4       V Uu. uFk  pVR ,          P                  \        P                  4      P                  4       VR,          P                  \        P                  4      P                  4       3NKm  	  pp\        \        4      p\        V4       F!  w  pw  ršWyV
3,          P                  V4       K#  	  VR3# u upi u upi ):Né   N:ru   NNz(Seed, Offset))Ú	get_staterV   ÚsizeÚtorchÚ
empty_likeÚdistributedrH   ÚviewÚuint64Úitemr   rc   r@   Úadd)rq   r-   Úlocal_stateÚ_Ú
all_statesÚstateÚseeds_offsetsÚseed_offset_ranksr   ÚseedÚoffsets   &&         r   Ú_check_philox_rng_syncr‡     sü   € ð ×%Ñ%Ó'€KÜ9>¸u¿z¹z»|Ô9LÓMÑ9L°A”%×"Ò" ;Ö/Ñ9L€JÐMÜ	×Ñ× Ñ  Ô9ñ  óáˆEð 
ˆr��‰œŸ™Ó	%×	*Ñ	*Ó	,¨e°B­i¯n©n¼U¿\¹\Ó.J×.OÑ.OÓ.QÓRÙð ð ô $¤CÓ(ÐÜ )¨-Ö 8Ñˆ‰nˆtØ ˜.Õ)×-Ñ-¨dÖ3ñ !9àÐ.Ð.Ð.ùò Nùòs   ¬D&Á0A1D+c               ó$   € V ^8„  d   QhRRRRRR/# rp   r   )r(   s   "r   r)   r)   -  rs   r   c                ó¤  € V P                  4       p\        VP                  4       4       Uu. uF  p\        P                  ! V4      NK  	  pp\        P
                  P                  WB4       \        \        4      p\        V4       F?  w  rbV\        P                  ! V4      P                  4       ,          P                  V4       KA  	  VR 3# u upi )zGenerator state hash)rv   rV   rw   rx   ry   rz   rH   r   rc   r@   Úhash_tensorr}   r~   )rq   r-   Ústate_tensorr€   Úall_state_tensorsÚstate_ranksr   s   &&     r   Ú_check_cpu_rng_syncrŽ   -  s®   € ð ×&Ñ&Ó(€LÜAFÀuÇzÁzÃ|ÔATÓUÑAT¸Aœ×)Ò)¨,Ö7ÑATÐÐUÜ	×Ñ× Ñ Ð!2ÔAÜœcÓ"€KÜ'Ð(9Ö:Ñˆð 	”E×%Ò% lÓ3×8Ñ8Ó:Õ;×?Ñ?ÀÖEñ	 ;ð
 Ð.Ð.Ð.ùò Vs   ¬Cc               ó$   € V ^8„  d   QhRRRRRR/# rp   r   )r(   s   "r   r)   r)   =  s$   € ÷ 

ñ 

Øð

Ø'8ð

àñ

r   c                óÞ   € V P                   P                  R9   d   \        W4      # V P                   P                  R8X  d   \        W4      # \	        RV P                   P                   24      h)ÚcudaÚcpuzUnsupported generator device: >   Úxpur‘   )ÚdevicerJ   r‡   rŽ   ÚNotImplementedError)rq   r-   s   &&r   Ú_check_rng_sync_internalr–   =  sf   € ð ×Ñ×Ñ Ô/Ü% iÓ7Ð7Ø	×	Ñ	×	Ñ	 %Ô	'Ü" 9Ó4Ð4ä!Ø,¨Y×-=Ñ-=×-BÑ-BÐ,CÐDó
ð 	
r   c               ó$   € V ^8„  d   QhRRRRRR/# )r"   Útagr\   Úvalue_rankszdict[Any, set[int]]r'   r   )r(   s   "r   r)   r)   J  s"   € ÷ 
(ñ 
(˜3ð 
(Ð-@ð 
(ÀSñ 
(r   c                óp  € R V  R2.pVP                  4        UUu. uF  w  r4\        V4      \        V4      .NK  	  ppp\        P                  P                  R4      '       d   ^ RIHp V! WRR7      # RP                  V Uu. uF  p\        V4      NK  	  up4      p\        V RV 24      # u uppi u upi )ÚRanksz valuesÚtabulate)rœ   )ÚheadersÚ
)Úitemsrn   r\   Ú	importlibÚutilÚ	find_specrœ   ri   )	r˜   r™   r�   Úvaluer[   Úrank_valuesrœ   ÚrowÚrow_strs	   &&       r   Ú_desync_table_strr§   J  s¯   € Ø˜3˜%˜w˜Ð(€GàBM×BSÑBSÔBUôÙBU±,°%Ô	˜%Ó	 ¤# e£*Ó-ÑBUð ñ ô ‡~�~×Ñ 
×+Ò+Ý%á˜Ô5Ð5Ø�i‰i©[Ó9©[ cœ˜Sž©[Ñ9Ó:€GÜ�'�˜"˜W˜IÐ&Ó'Ð'ùóùò :s   ›!B-ÂB3c               ó$   € V ^8„  d   QhRRRRRR/# )r"   rq   rr   r-   rO   r'   r   r   )r(   s   "r   r)   r)   W  s"   € ÷ ñ ˜ð Ð7Hð ÈZñ r   c                óŠ   € \        W4      w  r#R p\        V4      ^8”  d$   R\        W24       2p\        P	                  V4       V# )NzGenerator desync detected:
)r–   r3   r§   ÚloggerÚerror)rq   r-   r™   Úvalue_headerÚlog_strs   &&   r   Ú_check_rng_syncr®   W  sE   € Ü 8¸Ó JÑ€KØ€GÜ
ˆ;Ó˜!ÔØ0Ô1BÀ<Ó1]Ð0^Ð_ˆÜ�‰�WÔØ€Nr   )r   r9   rH   r?   )NN)'Ú__conditional_annotations__Ú__doc__Ú
__future__r   r    ÚloggingÚcollectionsr   Údataclassesr   Útypingr   r   r   r   r	   Úcollections.abcr
   r   rx   Útorch.distributedrz   r1   r   r   Ú	getLoggerr   rª   r   r   r9   rH   r?   rn   r‡   rŽ   r–   r§   r®   )r¯   s   @r   Ú<module>r¹      sÝ   øðôõ #ã Û Ý #Ý !ß =Õ =÷ ß2ã Ý  ò€ˆó ð 
×	Ò	˜8Ó	$€áˆCƒL€ð ô'�'˜!•*ó 'ó ð'ðM%ð ðM%ð "ð	M%ð
 ðM%ð $(÷M%÷`I"ñl 0O÷"õJ(õV/õ /õ 

õ
(÷r   