+
    QV-jŽ  ã                  ó6  € R t ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIt^RI	H
t
 ^RIHt ^RIHt ]
P                  ! ]4      tRR	R
RRR/t]! RR7       ! R R4      4       t]P(                  R R l4       t]P,                  P.                  R R l4       tR R ltR# )zõSonicMoE integration: fused MoE using CuteDSL kernels from `kernels-community/sonic-moe`.

Provides `sonicmoe_experts_forward` registered as "sonicmoe" in the ExpertsInterface.
Requirements: CUDA, `kernels`, `nvidia-cutlass-dsl`, has_gate=True.
)ÚannotationsN)ÚCallable)Ú	dataclass)Úlogging)Úlazy_load_kernel)Úto_localÚsiluÚswigluÚgeluÚgegluÚreluÚregluT)Úfrozenc                  ó0   € ] tR t^(t$ RtR]R&   R]R&   RtR# )ÚSonicMoEzAEntry points exposed by the `kernels-community/sonic-moe` kernel.ÚtypeÚactivation_type_enumr   Úmoe_general_routing_inputs© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ús/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/integrations/sonicmoe.pyr   r   (   s   ‡ áKàÓØ (×(r   r   c               ó   € V ^8„  d   QhRR/# )é   Úreturnr   r   )Úformats   "r   Ú__annotate__r"   1   s   € ÷ 0ñ 0˜xñ 0r   c                 ó  € \         P                  P                  4       '       g   \        R4      h\         P                  P	                  4       ^ ,          p V ^	8  d   \        RV  R24      h\        R4      pVf   \        R4      h\        \        VRR4      RR4      p\        VR	R4      pR
V3R	V33 UUu. uF  w  rEVe   K  VNK  	  pppV'       d   \        RRP                  V4       R24      h\        VVR7      # u uppi )z§
Load sonic-moe once and return its entry points.

Raises `ImportError` if CUDA/hardware requirements are not met, or if the kernel or
required symbols are not found.
zdsonic-moe kernel requires CUDA, but CUDA is not available. Use a different `experts_implementation`.z`sonic-moe requires a Hopper (SM90+) or newer GPU, but the current device has compute capability z-.x. Use a different `experts_implementation`.z	sonic-moeNu}   Failed to load the sonic-moe kernel â€” check that `kernels-community/sonic-moe` has a build matching the current torch/CUDA.ÚenumsÚActivationTyper   zenums.ActivationTypez.sonic-moe kernel is missing required symbols: z, zN. Make sure you have the `kernels` package and `nvidia-cutlass-dsl` installed.)r   r   )	ÚtorchÚcudaÚis_availableÚImportErrorÚget_device_capabilityr   ÚgetattrÚjoinr   )ÚmajorÚkernelr   r   ÚnameÚattrÚmissings          r   Ú_load_sonicmoe_kernelr2   0   sC  € ô �:‰:×"Ñ"×$Ò$ÜØró
ð 	
ô
 �J‰J×,Ñ,Ó.¨qÕ1€EØˆq„yÜð&Ø&+ WÐ,Yð[ó
ð 	
ô
 ˜kÓ*€FØ‚~Üð;ó
ð 	
ô
 #¤7¨6°7¸DÓ#AÐCSÐUYÓZÐÜ!(¨Ð1MÈtÓ!TÐð
 $Ð%9Ð:Ø)Ð+EÐFñ
ôñ
‰JˆDð ÷ 	ˆñ
ð ñ ÷ ÜØ<¸T¿Y¹YÀwÓ=OÐ<Pð Q[ð [ó
ð 	
ô
 Ø1Ø#=ôð ùós   Â5C>ÃC>c               óL   € V ^8„  d   QhRRRRRRRRRRRRR	RR
RRRRRRRRRRR/# )r   Úhidden_statesútorch.TensorÚrouter_scoresÚ
expert_idsÚ	token_idxÚw1Úb1ztorch.Tensor | NoneÚw2Úb2Úact_nameÚstrÚnum_expertsÚintÚconcat_layoutÚboolÚis_inference_mode_enabledr    r   )r!   s   "r   r"   r"   e   sŠ   € ÷ +ñ +Øð+àð+ð ð+ð ð	+ð
 	ð+ð 	ð+ð 	ð+ð 	ð+ð ð+ð ð+ð ð+ð  $ð+ð ñ+r   c                óæ   € \        4       pVP                  p\        V\        P	                  VR4      P                  4       VP                  4      pVP                  V VVVVVVVV	VVV
RR7      w  ppV# )uW  Module-level shim around `moe_general_routing_inputs` so `allow_in_graph` can wrap it.

sonicmoe asserts `not torch.compiler.is_compiling()` internally because it dispatches
CuteDSL kernels, which Dynamo can't trace. `allow_in_graph` keeps the call in the FX
graph as a single opaque node (no tracing into the body, no graph break) while still
running the real Python at runtime â€” autograd through `_UpProjection` / `_DownProjection`
flows normally. The decorator must be applied at module load time, not inside the compiled
function â€” hence this shim plus the `allow_in_graph` decorator above.
r	   N)ÚEÚactivation_typerC   rA   Ú	stream_id)r2   r   r+   ÚACT_MAPÚgetÚupperÚSWIGLUr   )r4   r6   r7   r8   r9   r:   r;   r<   r=   r?   rA   rC   Úsonicmoer   rF   ÚoutputÚ_s   &&&&&&&&&&&&     r   Ú_sonicmoe_wrapperrO   d   s�   € ô0 %Ó&€HØ#×8Ñ8ÐÜØœgŸk™k¨(°HÓ=×CÑCÓEÐG[×GbÑGbó€Oð ×3Ñ3ØØØØØ
Ø
Ø
Ø
Ø
Ø'Ø";Ø#Øð 4ó �I€FˆAð €Mr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   Úselfztorch.nn.Moduler4   r5   Útop_k_indexÚtop_k_weightsr    r   )r!   s   "r   r"   r"   “   s:   € ÷ 5ñ 5Ø
ð5àð5ð ð5ð  ð	5ð
 ñ5r   c                óP  € V P                   '       g   \        R 4      hVP                  P                  R8w  d   \        R4      hVP                  pVP	                  R4      pVP	                  ^ 4      p\
        P                  ! WdR7      P                  ^4      P                  RV4      P                  R4      P                  4       pVP                  R4      P                  VP                  4      pVP                  R4      P                  4       p	\        V P                  4      p
\        V P                  4      pV P                   '       d   \        V P"                  4      MRpV P                   '       d   \        V P$                  4      MRp\'        V P(                  RR4      P+                  4       pV P,                  '       d   R	MR
pV
P.                  ! V!  p
VP.                  ! V!  p\1        VVV	VV
VVVVV P2                  V P4                  \
        P6                  ! 4       '       * R7      # )z/sonicmoe requires gated experts (has_gate=True)r'   zsonicmoe requires CUDA device)ÚdeviceNÚ
hidden_actr   )r4   r6   r7   r8   r9   r:   r;   r<   r=   r?   rA   rC   éÿÿÿÿ)r   é   é    )rX   r   rY   )Úhas_gateÚ
ValueErrorrU   r   Úsizer&   ÚarangeÚ	unsqueezeÚexpandÚreshaper@   ÚtoÚdtyper   Úgate_up_projÚ	down_projÚhas_biasÚgate_up_proj_biasÚdown_proj_biasr+   ÚconfigÚlowerÚis_transposedÚpermuterO   r?   Úis_concatenatedÚis_grad_enabled)rQ   r4   rR   rS   rU   Ú	num_top_kÚ
num_tokensr8   r6   r7   r9   r;   r:   r<   r=   Úperms   &&&&            r   Úsonicmoe_experts_forwardrq   “   sÆ  € ð �=�=ˆ=ÜÐJÓKÐKØ×Ñ× Ñ  FÔ*ÜÐ8Ó9Ð9à×!Ñ!€FØ× Ñ  Ó$€IØ×#Ñ# AÓ&€Jô —’˜ZÔ7×AÑAÀ!ÓD×KÑKÈBÐPYÓZ×bÑbÐceÓf×jÑjÓl€IØ!×)Ñ)¨"Ó-×0Ñ0°×1DÑ1DÓE€MØ×$Ñ$ RÓ(×,Ñ,Ó.€Jô 
�$×#Ñ#Ó	$€BÜ	�$—.‘.Ó	!€BØ-1¯]¯]¨]Œ�$×(Ñ(Ô	)À€BØ*.¯-¯-¨-Œ�$×%Ñ%Ô	&¸T€Bô �t—{‘{ L°&Ó9×?Ñ?ÓA€Hð ×*×*Ð*‰9°	€DØ	�Š�TÑ	€BØ	�Š�TÑ	€BäØ#Ø#ØØØØØØØØ×$Ñ$Ø×*Ñ*Ü&+×&;Ò&;Ó&=Ô"=ôð r   )r   Ú
__future__r   Ú	functoolsÚcollections.abcr   Údataclassesr   r&   Úutilsr   Úhub_kernelsr   Útensor_parallelr   Ú
get_loggerr   ÚloggerrH   r   Úcacher2   Ú_dynamoÚallow_in_graphrO   rq   r   r   r   Ú<module>r~      s¥   ðñõ #ã Ý $Ý !ã å Ý )Ý %ð 
×	Ò	˜HÓ	%€ð �8˜V W¨f°gÐ
>€ñ �$Ô÷)ð )ó ð)ð ‡�ô0ó ð0ðf ‡�×Ñô+ó ð+÷\5r   