+
    –°³jX/  ã                  ó–  a € 0 t $ ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHt ^ RIt]'       d   ^ RIHt . tR]R&   R R	 ltR
 R ltR R lt]	! RRR7       ! R R4      4       t ! R R]P,                  P.                  4      t ! R R]P,                  P.                  4      t ! R R]P4                  4      t ! R R]4      tR# )é    )ÚannotationsN)Ú	dataclass)ÚAnyÚTYPE_CHECKING)ÚProcessGroupzlist[ctypes.CDLL]Ú_NCCL_EP_KEEPALIVEc               ó    € V ^8„  d   QhRRRR/# )é   ÚnameÚstrÚreturnz
str | None© )Úformats   "Ú`/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/_token_switch.pyÚ__annotate__r      s   € ÷ 
.ñ 
.˜ð 
. 
ñ 
.ó    c                ó¼   €  \         P                  P                  V 4      pTe   TP                  '       g   R # TP                  ^ ,          #   \         d     R # i ; i©N)Ú	importlibÚutilÚ	find_specÚModuleNotFoundErrorÚsubmodule_search_locations)r   Úspecs   & r   Ú_find_pkg_dirr      sU   € ðÜ�~‰~×'Ñ'¨Ó-ˆð ‚|˜4×:×:Ð:ÙØ×*Ñ*¨1Õ-Ð-øô	 ô Úðús   ‚A ÁAÁAc               ó   € V ^8„  d   QhRR/# )r
   r   ÚNoner   )r   s   "r   r   r   #   s   € ÷ %Lñ %L˜$ñ %Lr   c                 ó`  € \        R 4      p V f   \        R4      h\        P                  P	                  V R4      pR\        P
                  9  dl   \        P                  P	                  VRR4      p\        P                  P                  V4      '       g   \        RV  RV R	24      hV\        P
                  R&   \        R
4      pVed   \        P                  P                  \        P                  P	                  VR4      4      '       d!   \        P
                  P                  RV4       \        P                  P	                  VRR4      p\        P                  P                  V4      '       d<   \        P                  \        P                  ! V\        P                  R7      4       R# R# )ÚncclNz‘TokenSwitchNCCL needs the 'nccl4py' package for this build's libnccl_ep.so and runtime JIT headers. Install it with `pip install nccl4py==0.3.1`.ÚepÚNCCL_EP_HOMEÚincludeÚnccl_epznccl4py at z+ is missing the EP JIT headers expected at z(; reinstall nccl4py or set NCCL_EP_HOME.znvidia.ncclÚ	NCCL_HOMEÚlibzlibnccl_ep.so)Úmode)r   ÚImportErrorÚosÚpathÚjoinÚenvironÚisdirÚ
setdefaultÚisfiler   ÚappendÚctypesÚCDLLÚ
RTLD_LOCAL)Únccl_pkgÚep_dirÚ
ep_headersÚnvidia_ncclr%   s        r   Ú_prepare_nccl4pyr7   #   s>  € ô ˜VÓ$€HØÒÜð,ó
ð 	
ô
 �W‰W�\‰\˜( DÓ)€FØœRŸZ™ZÔ'Ü—W‘W—\‘\ &¨)°YÓ?ˆ
Ü�w‰w�}‰}˜Z×(Ò(ÜØ˜h˜Zð (Ø �\Ð!IðKóð ð &,Œ�
‰
�>Ñ"ô   Ó.€KØÒ¤2§7¡7§=¡=´·±·±¸kÈ9Ó1U×#VÒ#VÜ
�
‰
×Ñ˜k¨;Ô7ô
 �'‰'�,‰,�v˜u oÓ
6€CÜ	‡w�w‡~�~�c×ÒÜ×!Ñ!¤&§+¢+¨c¼×8IÑ8IÔ"JÖKñ r   c               ó   € V ^8„  d   QhRR/# )r
   r   r   r   )r   s   "r   r   r   K   s   € ÷ ñ ˜ñ r   c                 óš   €  ^ RI Hp  V #   \         d     Mi ; i\        4         ^ RI Hp  T #   \         d   p\        R4      ThRp?ii ; i)r   NzŽtorch._nccl_ep is unavailable; this PyTorch was not built with USE_NCCL_EP (or, for a USE_SYSTEM_NCCL=ON build, the nccl4py wheel is missing).)Útorch._nccl_epÚ_nccl_epr'   r7   )Ú_epÚes     r   Ú_import_nccl_epr>   K   sa   € ðå$àˆ
øÜô Ùðúô Ôðå$ð €Jøô ô Üðó
ð ð		ûðús    ‚
 Š—¦. ®A
¹AÁA
T)ÚfrozenÚslotsc                  ó,   € ] tR t^ht$ R]R&   R]R&   RtR# )ÚRoutingÚobjectÚhandleútorch.TensorÚtopk_idxr   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotations__Ú__static_attributes__r   r   r   rB   rB   h   s   ‡ àƒNØ×r   rB   c                  óB   € ] tR t^nt]R R l4       t]R R l4       tRtR# )Ú_DispatchAutogradc               ó4   € V ^8„  d   QhRRRRRRRRR	RR
RRR/# )r
   Úctxr   ÚtsÚTokenSwitchÚroutingrB   ÚtokensrE   Útopk_weightsÚmax_recv_tokensÚintr   ú/tuple[torch.Tensor, torch.Tensor, torch.Tensor]r   )r   s   "r   r   Ú_DispatchAutograd.__annotate__p   sN   € ÷ :ñ :Øð:àð:ð ð:ð ð	:ð
 #ð:ð ð:ð 
9ñ:r   c                	ó&  € VP                   w  rgVP                   ^,          pVP                  WW4      p	VP                  WX4      p
VP                  P                  WX4      pVP                  W#WIW«4       Wn        W n        VP                   V n        WšV3# )é   )ÚshapeÚ	new_zerosrF   Ú	_dispatchrQ   rS   Útokens_shape)rP   rQ   rS   rT   rU   rV   Ú_NÚHÚKÚ
out_tokensÚout_topk_weightsÚout_topk_idxs   &&&&&&      r   ÚforwardÚ_DispatchAutograd.forwardo   s�   € ð —‘‰ˆØ×Ñ˜qÕ!ˆØ×%Ñ% oÓ9ˆ
Ø'×1Ñ1°/ÓEÐØ×'Ñ'×1Ñ1°/ÓEˆØ
�‰Ø˜\Ð7Gô	
ð ŒØŒØ!Ÿ<™<ˆÔØ¨\Ð9Ð9r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r
   rP   r   Úgrad_out_tokensrE   Úgrad_out_topk_weightsÚgrad_out_topk_idxr   z+tuple[None, None, torch.Tensor, None, None]r   )r   s   "r   r   rY   ‡   s:   € ÷ 3ñ 3Øð3à%ð3ð  ,ð3ð (ð	3ð
 
5ñ3r   c                	ó°   € VP                  V P                  4      pV P                  P                  V P                  VP                  4       V4       R R VR R 3# r   )r]   r_   rQ   Ú_combinerS   Ú
contiguous)rP   ri   rj   rk   Úgrad_tokenss   &&&& r   ÚbackwardÚ_DispatchAutograd.backward…   sL   € ð &×/Ñ/°×0@Ñ0@ÓAˆØ�‰�‰˜Ÿ™ _×%?Ñ%?Ó%AÀ;ÔOØ�T˜;¨¨dÐ2Ð2r   r   N©rG   rH   rI   rJ   Ústaticmethodrf   rp   rL   r   r   r   rN   rN   n   s(   † Øô:ó ð:ð* ô3ó ô3r   rN   c                  óB   € ] tR t^’t]R R l4       t]R R l4       tRtR# )Ú_CombineAutogradc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R/# )
r
   rP   r   rQ   rR   rS   rB   Úexpert_tokensrE   r   r   )r   s   "r   r   Ú_CombineAutograd.__annotate__”   s:   € ÷ ñ Øðàðð ðð $ð	ð
 
ñr   c                	óL  € VP                   P                  ^ ,          pVP                  ^,          pVP                  WE4      pVP                  W#V4       Wn        W n        VP                  V n        VP                  V n        VP                   P                  ^,          V n	        V# )r   )
rF   r\   r]   rm   rQ   rS   Úexpert_shapeÚdtypeÚexpert_dtypeÚtop_k)rP   rQ   rS   rw   ÚNra   rc   s   &&&&   r   rf   Ú_CombineAutograd.forward“   sŒ   € ð ×Ñ×"Ñ" 1Õ%ˆØ×Ñ Õ"ˆØ"×,Ñ,¨QÓ2ˆ
Ø
�‰�G¨JÔ7ØŒØŒØ(×.Ñ.ˆÔØ(×.Ñ.ˆÔØ×$Ñ$×*Ñ*¨1Õ-ˆŒ	ØÐr   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   rP   r   ri   rE   r   ztuple[None, None, torch.Tensor]r   )r   s   "r   r   rx   §   s$   € ÷ =ñ =Øð=Ø#/ð=à	(ñ=r   c                	óh  € V P                   w  r#VP                  ^ ,          pV P                  pV P                  pV P                  P
                  pVP                  Ws4      P                  V4      pVP                  WE\        P                  R7      p	VP                  Wu\        P                  R7      p
V P                  P                  P                  Wu4      pV P                  P                  V P                  VP                  V4      P                  4       V	VV
V4       RRVRV P                  4       3# )r   )r{   N)rz   r\   r}   r|   rQ   Ú_max_recv_tokens_per_rankr]   ÚtoÚtorchÚfloat32rS   rF   r^   rn   )rP   ri   ÚMra   r~   rb   r{   Úmax_recvÚgrad_expert_fullÚdummy_weightsÚdummy_out_weightsÚdummy_out_idxs   &&          r   rp   Ú_CombineAutograd.backward¥   s  € ð
 ×Ñ‰ˆØ×!Ñ! !Õ$ˆØ�I‰IˆØ× Ñ ˆð —6‘6×3Ñ3ˆØ*×4Ñ4°XÓA×DÑDÀUÓKÐØ'×1Ñ1°!¼e¿m¹mÐ1ÓLˆØ+×5Ñ5°hÌÏÉÐ5ÓWÐØŸ™×,Ñ,×6Ñ6°xÓCˆØ�‰×ÑØ�K‰KØ×Ñ˜uÓ%×0Ñ0Ó2ØØØØô	
ð �TÐ+¨B¨QÐ/×:Ñ:Ó<Ð<Ð<r   r   Nrr   r   r   r   ru   ru   ’   s(   † Øôó ðð" ô=ó ô=r   ru   c                  óÈ   € ] tR t^ÃtRt]P                  RR R ll4       t]P                  R R l4       t]P                  R R l4       t	RR	R/R
 R lllt
R	R/R R lltRtR# )rR   zšAbstract token routing switch (e.g. expert-parallel dispatch / combine).

Typical usage: :meth:`create_routing`, then :meth:`dispatch` / :meth:`combine`.
Nc               ó$   € V ^8„  d   QhRRRRRR/# ©r
   rF   rE   Úper_expert_token_countsútorch.Tensor | Noner   rB   r   )r   s   "r   r   ÚTokenSwitch.__annotate__Ê   s(   € ÷ 
"ñ 
"àð
"ð "5ð
"ð 
ñ	
"r   c                ó   € \         h)zÝCreate expert routing for the current phase (e.g. top-k indices).

``per_expert_token_counts`` is optional 1D int32, length >= local experts:
output buffer for per-expert receive counts (NCCL EP ``RECV_EXPERT_COUNTER``).
©ÚNotImplementedError)ÚselfrF   r�   s   &&&r   Úcreate_routingÚTokenSwitch.create_routingÉ   s
   € ô "Ð!r   c               ó4   € V ^8„  d   QhRRRRRRRRRRRRR	R
/# ©r
   rS   rB   rT   rE   rU   rc   rd   re   r   r   r   )r   s   "r   r   r’   ×   sP   € ÷ 	"ñ 	"àð	"ð ð	"ð #ð		"ð
 !ð	"ð 'ð	"ð #ð	"ð 
ñ	"r   c                	ó   € \         hr   r”   ©r–   rS   rT   rU   rc   rd   re   s   &&&&&&&r   r^   ÚTokenSwitch._dispatchÖ   s
   € ô "Ð!r   c               ó(   € V ^8„  d   QhRRRRRRRR/# ©r
   rS   rB   rw   rE   rc   r   r   r   )r   s   "r   r   r’   ã   s2   € ÷ "ñ "àð"ð $ð"ð !ð	"ð
 
ñ"r   c                	ó   € \         hr   r”   ©r–   rS   rw   rc   s   &&&&r   rm   ÚTokenSwitch._combineâ   s
   € ô "Ð!r   Úoutc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r
   rS   rB   rT   rE   rU   rV   z
int | Noner£   z6tuple[torch.Tensor, torch.Tensor, torch.Tensor] | Noner   rX   r   )r   s   "r   r   r’   ë   sG   € ÷ 
ñ 
àð
ð ð
ð #ð	
ð
 $ð
ð Dð
ð 
9ñ
r   c               ó„   € Ve   V P                   ! WV.VO5!   V# Vf   \        R4      h\        P                  WW#V4      # )a‘  Route tokens to experts.

With ``out=(out_tokens, out_topk_weights, out_topk_idx)``: writes to the provided
buffers and returns them; no autograd support.
Without ``out``: allocates output buffers and returns
``(out_tokens, out_topk_weights, out_topk_idx)`` with autograd support.
``max_recv_tokens`` is required when ``out`` is not provided.
``topk_weights`` receives no gradient (routing metadata).
z5max_recv_tokens is required when out= is not provided)r^   Ú
ValueErrorrN   Úapply)r–   rS   rT   rU   rV   r£   s   &&&&&$r   ÚdispatchÚTokenSwitch.dispatchë   sM   € ð$ Š?Ø�NŠN˜7¨LÐ?¸3Ô?ØˆJØÒ"ÜÐTÓUÐUÜ ×&Ñ&Ø˜6°ó
ð 	
r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r
   rS   rB   rw   rE   r£   r‘   r   r   )r   s   "r   r   r’     s8   € ÷ Dñ DàðDð $ðDð
 !ðDð 
ñDr   c               ó^   € Ve   V P                  WV4       V# \        P                  WV4      # )zÚGather expert outputs back to token order.

With ``out=out_tokens``: writes to the provided buffer and returns it;
no autograd support.
Without ``out``: allocates an output buffer and returns it with autograd support.
)rm   ru   r§   )r–   rS   rw   r£   s   &&&$r   ÚcombineÚTokenSwitch.combine  s/   € ð Š?Ø�M‰M˜'°#Ô6ØˆJÜ×%Ñ% d°]ÓCÐCr   r   r   )rG   rH   rI   rJ   Ú__doc__ÚabcÚabstractmethodr—   r^   rm   r¨   r¬   rL   r   r   r   rR   rR   Ã   s‚   † ñð
 	×Ñö
"ó ð
"ð 	×Ñô	"ó ð	"ð 	×Ñô"ó ð"ñ
ð GK÷
ð 
ð6Dð
 $(÷Dó Dr   rR   c                  óN   € ] tR tRtRtR R ltRR R lltR R	 ltR
 R ltRt	R# )ÚTokenSwitchNCCLi  zPToken switch backed by NCCL EP (:func:`ncclEpCreateGroup` / dispatch / combine).c               ó0   € V ^8„  d   QhRRRRRRRRRRRR	/# )
r
   Úprocess_groupr   Únum_expertsrW   Úmax_dispatch_tokens_per_rankÚmax_recv_tokens_per_rankÚmax_token_bytesr   r   r   )r   s   "r   r   ÚTokenSwitchNCCL.__annotate__  sF   € ÷ 
ñ 
à#ð
ð ð
ð '*ð	
ð
 #&ð
ð ð
ð 
ñ
r   c                	óŒ   € \        4       V n        W@n        V P                  P                  P	                  VVVVV4      V n        R # r   )r>   r<   r‚   Ú_NcclEpGroupÚcreateÚ_group)r–   r´   rµ   r¶   r·   r¸   s   &&&&&&r   Ú__init__ÚTokenSwitchNCCL.__init__  s?   € ô #Ó$ˆŒØ)AÔ&Ø—h‘h×+Ñ+×2Ñ2ØØØ(Ø$Øó
ˆŽr   Nc               ó$   € V ^8„  d   QhRRRRRR/# r�   r   )r   s   "r   r   r¹   .  s(   € ÷ 9ñ 9àð9ð "5ð9ð 
ñ	9r   c                ó|   € V P                   P                  P                  V P                  VV4      p\	        W1R7      # )zQCreate expert routing for this phase; pass to :meth:`dispatch` / :meth:`combine`.)rD   rF   )r<   Ú_NcclEpHandler¼   r½   rB   )r–   rF   r�   rD   s   &&& r   r—   ÚTokenSwitchNCCL.create_routing.  s8   € ð —‘×'Ñ'×.Ñ.Ø�K‰KØØ#ó
ˆô
 ˜fÔ8Ð8r   c               ó4   € V ^8„  d   QhRRRRRRRRRRRRR	R
/# rš   r   )r   s   "r   r   r¹   ;  sP   € ÷ 
ñ 
àð
ð ð
ð #ð	
ð
 !ð
ð 'ð
ð #ð
ð 
ñ
r   c                	óZ   € V P                   P                  VP                  VVVVV4       R # r   )r<   Ú_nccl_ep_dispatchrD   rœ   s   &&&&&&&r   r^   ÚTokenSwitchNCCL._dispatch;  s,   € ð 	�‰×"Ñ"Ø�N‰NØØØØØö	
r   c               ó(   € V ^8„  d   QhRRRRRRRR/# rŸ   r   )r   s   "r   r   r¹   M  s2   € ÷ 

ñ 

àð

ð $ð

ð !ð	

ð
 
ñ

r   c                	óT   € V P                   P                  VP                  VV4       R # r   )r<   Ú_nccl_ep_combinerD   r¡   s   &&&&r   rm   ÚTokenSwitchNCCL._combineM  s#   € ð 	�‰×!Ñ!Ø�N‰NØØö	
r   )r<   r½   r‚   r   )
rG   rH   rI   rJ   r®   r¾   r—   r^   rm   rL   r   r   r   r²   r²     s   † ÙZõ
÷$9õ
÷$

ñ 

r   r²   )Ú__conditional_annotations__Ú
__future__r   r¯   r0   Úimportlib.utilr   r(   Údataclassesr   Útypingr   r   r„   Ú"torch.distributed.distributed_c10dr   r   rK   r   r7   r>   rB   ÚautogradÚFunctionrN   ru   ÚABCrR   r²   )rÌ   s   @r   Ú<module>rÕ      s·   øðç "Ð "ã 
Û Û Û 	Ý !ß %ã ÷ Ý?ð )+Ð Ð%Ó *õ
.õ%LõPñ: �$˜dÔ#÷ð ó $ðô
!3˜Ÿ™×/Ñ/ô !3ôH.=�u—~‘~×.Ñ.ô .=ôbSD�#—'‘'ô SDôl>
�kö >
r   