+
    œ°³jY$  ã                  óŒ  a € 0 t $ 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Ht ^RIHt ]P(                  ! ]4      tR	R
RRRR/tRRRR/t]
P2                  P4                  R!R R ll4       t]	! RR7       ! R R4      4       tRsR]R&   ]
P2                  P>                  R R l4       t R R l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)Úversion)Úlogging)Úis_kernels_availableÚmaybe_import_error)Úlazy_load_kernelÚsiluÚswigluÚgeluÚgegluÚreluÚregluznvidia-cutlass-dslz4.6.0zapache-tvm-ffiz0.1.10c               ó    € V ^8„  d   QhRRRR/# )é   Úraise_errorÚboolÚreturn© )Úformats   "Úc/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/integrations/sonicmoe.pyÚ__annotate__r   .   s   € ÷ ,ñ , dð ,°tñ ,ó    c           
     ó–  € \        4       '       g   \        RV R7      # \        P                  P	                  4       '       g   \        RV R7      # \        P                  P                  4       ^ ,          pV^	8  d   \        RV R2V R7      # \        P                  4        Fm  w  r# \        P                  P                  V4      p\        P                  ! T4      \        P                  ! T4      8  g   KV  \        RT RT R	T R
2T R7      u # 	  R#   \        P                  P                   d    \        RT R2T R7      u u # i ; i)u  Whether the sonic-moe kernel can be loaded in this environment: `kernels` installed, a CUDA GPU on
Hopper (SM90) or newer, and `nvidia-cutlass-dsl` / `apache-tvm-ffi` no newer than the versions the
kernel was validated against (`SONICMOE_DEPENDENCIES`) â€” newer releases may break its CuteDSL / TVM
FFI dispatch. A one-glance gate for callers, including external stacks. With `raise_error=True` (used
by the loader) it re-raises the specific `ImportError` instead of returning `False`.

`@assume_constant_result` makes dynamo evaluate this once at trace time and inline the bool (its probe
is untraceable â€” an `lru_cache`'d import check, the `get_device_capability` pybind, and
`importlib.metadata` version lookups), so it stays compile-safe if called from a compiled region.
zSsonic-moe requires the `kernels` package. Use a different `experts_implementation`.©r   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-moe requires `z`, but it is not installed.z` >= z, but z is installed.T)r   r   ÚtorchÚcudaÚis_availableÚget_device_capabilityÚSONICMOE_DEPENDENCIESÚitemsÚ	importlibÚmetadatar   ÚPackageNotFoundErrorÚparse)r   ÚmajorÚdistributionÚmin_versionÚ	installeds   &    r   Úis_sonicmoe_loadabler*   -   sC  € ô  ×!Ò!Ü!ØaØ#ô
ð 	
ô �:‰:×"Ñ"×$Ò$Ü!ØrØ#ô
ð 	
ô �J‰J×,Ñ,Ó.¨qÕ1€EØˆq„yÜ!ðØ˜Ð MðOà#ô
ð 	
ô
 &;×%@Ñ%@Ö%BÑ!ˆð
	Ü!×*Ñ*×2Ñ2°<Ó@ˆIô
 �=Š=˜Ó#¤g§m¢m°KÓ&@Ö@Ü%Ø& | n°E¸+¸ÀfÈYÈKÐWeÐfØ'ôò ñ &Cñ  øô ×!Ñ!×6Ñ6ô 	Ü%Ø& | nÐ4OÐPÐ^iôô ð	ús   Â&DÄ0EÅET)Ú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_inputsr   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   r   r   r-   r-   ]   s   ‡ áKàÓØ (×(r   r-   zSonicMoE | NoneÚ	_SONICMOEc               ó   € V ^8„  d   QhRR/# )r   r   ÚNoner   )r   s   "r   r   r   l   s   € ÷ .ñ .˜tñ .r   c                 ód  € \         e   R# \        RR7       \        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  r4Ve   K  VNK  	  pppV'       d   \        R
RP                  V4       R24      h\        VVR7      s R# u uppi )a   
Load sonic-moe once into the `_SONICMOE` module global.

`@allow_in_graph` makes `torch.compile` treat the untraceable hub download + dynamic import as a
single opaque node instead of tracing into it; it returns `None` (proxyable) and populates the
global, which `load_sonicmoe_kernel` then returns.

Under NO circumstances may this function return a value: an `@allow_in_graph` fx node's
return must be proxyable, and returning the bundle (e.g. from the warm-cache
short-circuit) breaks torch.compile with `Unsupported: torch.* op returned non-Tensor`.

Raises `ImportError` if CUDA/hardware requirements are not met, or if the kernel or
required symbols are not found.
NTr   z	sonic-moeu}   Failed to load the sonic-moe kernel â€” check that `kernels-community/sonic-moe` has a build matching the current torch/CUDA.ÚenumsÚActivationTyper0   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/   r0   )r8   r*   r	   ÚImportErrorÚgetattrÚjoinr-   )Úkernelr/   r0   ÚnameÚattrÚmissings         r   Ú_load_sonicmoe_kernelrE   k   sì   € ô" ÒÙÜ TÕ*Ü˜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Ø#=ô‚Iùós   Á!B,Á.B,c               ó   € V ^8„  d   QhRR/# )r   r   r-   r   )r   s   "r   r   r   �   s   € ÷ ñ ˜hñ r   c                 ó"   € \        4        \        # )N)rE   r8   r   r   r   Úload_sonicmoe_kernelrH   �   s   € ÜÔÜÐr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   Úselfztorch.nn.ModuleÚhidden_statesztorch.TensorÚtop_k_indexÚtop_k_weightsr   r   )r   s   "r   r   r   ¢   s:   € ÷ 9ñ 9Ø
ð9àð9ð ð9ð  ð	9ð
 ñ9r   c                ó˜  € V P                   '       g   \        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                  p
V P                  pV P                  '       d   V P                  MRpV P                  '       d   V P                   MRp\#        V P$                  RR4      P'                  4       pV\(        9  d!   \        RV: R\+        \(        4       R24      hV P,                  '       d   R
MRpV
P.                  ! V!  p
VP.                  ! V!  p\1        4       pVP3                  VVVV	V
VVVV P4                  \#        VP6                  \(        V,          P9                  4       4      \        P:                  ! 4       '       * V P<                  RR7      w  ppV# )z/sonicmoe requires gated experts (has_gate=True))ÚdeviceNÚ
hidden_actr
   zsonicmoe does not support the z activation; expected one of Ú.)ÚEÚactivation_typeÚis_inference_mode_enabledÚconcat_layoutÚ	stream_idéÿÿÿÿ)r   é   é    )rX   r   rY   )Úhas_gateÚ
ValueErrorrO   Úsizer   ÚarangeÚ	unsqueezeÚexpandÚreshapeÚintÚtoÚdtypeÚgate_up_projÚ	down_projÚhas_biasÚgate_up_proj_biasÚdown_proj_biasr?   ÚconfigÚlowerÚACT_MAPÚsortedÚis_transposedÚpermuterH   r0   Únum_expertsr/   ÚupperÚis_grad_enabledÚis_concatenated)rJ   rK   rL   rM   rO   Ú	num_top_kÚ
num_tokensÚ	token_idxÚrouter_scoresÚ
expert_idsÚw1Úw2Úb1Úb2Úact_nameÚpermÚsonicmoeÚoutputÚ_s   &&&&               r   Úsonicmoe_experts_forwardr�   ¢   sø  € ð �=�=ˆ=ÜÐJÓKÐKà×!Ñ!€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Ø#'§=§= =ˆ×	Ò	°d€BØ $§§ ˆ×	Ò	°4€Bô �t—{‘{ L°&Ó9×?Ñ?ÓA€HØ”wÔÜÐ9¸(¹ÐEbÔciÔjqÓcrÐbsÐstÐuÓvÐvð
 ×*×*Ð*‰9°	€DØ	�Š�TÑ	€BØ	�Š�TÑ	€Bä#Ó%€HØ×3Ñ3ØØØØØ
Ø
Ø
Ø
Ø
×
Ñ
Ü × =Ñ =¼wÀxÕ?P×?VÑ?VÓ?XÓYÜ&+×&;Ò&;Ó&=Ô"=Ø×*Ñ*Øð 4ó �I€FˆAð €Mr   )F)#Ú__conditional_annotations__r5   Ú
__future__r   Úimportlib.metadatar"   Úcollections.abcr   Údataclassesr   r   Ú	packagingr   Úutilsr   Úutils.import_utilsr   r   Úhub_kernelsr	   Ú
get_loggerr1   Úloggerrk   r    Ú_dynamoÚassume_constant_resultr*   r-   r8   r6   Úallow_in_graphrE   rH   r�   )r‚   s   @r   Ú<module>r�      sÒ   øðôõ #ã Ý $Ý !ã Ý å ß IÝ )ð 
×	Ò	˜HÓ	%€ð �8˜V W¨f°gÐ
>€ð .¨wÐ8HÈ(ÐSÐ ð ‡�×%Ñ%ö,ó &ð,ñ^ �$Ô÷)ð )ó ð)ð "€	ˆ?Ó !ð ‡�×Ñô.ó ð.õb÷
9r   