§
    Û×j:  ã                   ó¶   — d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 i Zd„ Zd„ Zdad	„ Z G d
„ d¦  «        Zd„ Z G d„ d¦  «        Z G d„ de¦  «        ZdS )z©Shared SwiGLU expert execution. Architecture code supplies routing, not residency, and quantization handlers supply the storage
formats and their kernels (ExpertFormat).é    N)Ú
functionalé   )Ú
ExpertBank)Ú	allocatorc                 ó|   — | t           vr't          j                             | ¦  «        t           | <   t           |          S )zEThe stream of the GPU expert branch of queue_forward, one per device.)Ú_side_streamsÚtorchÚcudaÚStream©Údevices    ú;C:\Users\johnn\OneDrive\Documents\AI\mmgp\expert_compute.pyÚ_side_streamr      s2   € à•]Ð"Ð"Ý %¤
× 1Ò 1°&Ñ 9Ô 9��fÑÝ˜Ô Ð ó    c            
      óš   — t          t          j                             dt	          dt          j        ¦   «         ¦  «        ¦  «        ¦  «        S )NÚMMGP_CPU_EXPERT_THREADSé   )ÚintÚosÚenvironÚgetÚminr	   Úget_num_threads© r   r   Úcpu_threadsr      s4   € Ý�rŒz�~Š~Ð7½¸QÅÔ@UÑ@WÔ@WÑ9XÔ9XÑYÔYÑZÔZÐZr   c                 ón  — t           €pt          j        t          j        dk    rdnd¦  «        }t          j        t          j        t          j        g|j        _        t          j        |j        _	        |j        a t          |j
        | t          j        |¦  «        ¦  «        }|rt          d|› d�¦  «        ‚dS )a  Queue function(&job) on a CUDA stream (captured as a host node inside a graph capture): it runs when the work queued before it is
    done, and the work queued after it waits for it. The job (a ctypes structure) must stay alive while it may run or be replayed.NÚntz
nvcuda.dllzlibcuda.so.1zcuLaunchHostFunc failed (ú))Ú_host_launchÚctypesÚCDLLr   ÚnameÚc_void_pÚcuLaunchHostFuncÚargtypesÚc_intÚrestypeÚcuda_streamÚ	addressofÚRuntimeError)ÚfunctionÚjobÚstreamÚdriverÚstatuss        r   Úlaunch_host_jobr0      s¢   € õ ÐÝ”­R¬W¸ª_¨_˜\˜\À.ÑQÔQˆÝ,2¬O½V¼_ÍfÌoÐ+^ˆÔÔ(Ý*0¬,ˆÔÔ'ØÔ.ˆÝ˜&Ô,¨h½Ô8HÈÑ8MÔ8MÑNÔN€FØð BÝÐ@°vÐ@Ð@Ð@ÑAÔAÐAðBð Br   c                   ó<   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd
d„Z	d	„ Z
dS )ÚExpertFormata{  Storage and kernels of routed SwiGLU expert banks in one checkpoint format. Quantization handlers supply formats through their
    EXPERT_FORMATS (mmgp.quant_router.expert_formats()); a bank takes the format of the checkpoint tensors it loads. Every tensor
    holds one entry per expert along its first dimension. bank.rotation is the ConvRot group of the activations (0: none).Ú c                 ó   — t           ‚)ziCheckpoint name -> (shape, dtype) of a bank's tensors, in the order of the rows of the GPU pointer table.©ÚNotImplementedError)ÚselfÚexpertsÚhiddenÚintermediates       r   ÚtensorszExpertFormat.tensors3   ó   € å!Ð!r   c                 ó   — t           ‚)zgWhether a bank's checkpoint tensors (name -> tensor, the names of tensors()) are stored in this format.r5   )r7   r;   s     r   ÚmatcheszExpertFormat.matches7   r<   r   c                 ó   — t           ‚)aR  (job, host function address) of a CPU computation from the addresses of a pinned routing payload (bank.pack()), of resident
        flags (or 0) and of a pinned float32 [tokens, hidden] result (zeros when every pair is computed elsewhere). The job is a ctypes
        structure passed by address; a nonzero status field reports a failure.r5   )r7   ÚbankÚpayloadÚresidentÚoutÚtokensÚtopkÚthreadss           r   Úcpu_jobzExpertFormat.cpu_job;   s
   € õ "Ð!r   c
                 ó   — t           ‚)z¹The same computation from the addresses of float32 activations and probabilities and int32 ids: returns the number of pairs
        computed (out is left unwritten when there are none).r5   )
r7   r@   ÚxÚidsÚprobabilitiesrB   rC   rD   rE   rF   s
             r   Úcpu_forwardzExpertFormat.cpu_forwardA   ó
   € õ "Ð!r   Nc                 ó   — t           ‚)a   float32 [tokens, hidden] sum of the selected experts having GPU copies (pointers: int64 [experts, tensors] table of their
        addresses, zero rows contributing nothing); out and the float32 [tokens * topk, intermediate] scratch mid may be preallocated.r5   )r7   r@   rI   rJ   rK   ÚpointersrC   Úmids           r   Úgpu_forwardzExpertFormat.gpu_forwardF   rM   r   c                 ó   — t           ‚)z£float32 gate and up [2 * intermediate, hidden] and down [hidden, intermediate] weights of one expert (name -> tensor), as
        applied to unrotated activations.r5   )r7   r@   r;   s      r   Ú
dequantizezExpertFormat.dequantizeK   rM   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r;   r>   rG   rL   rQ   rS   r   r   r   r2   r2   -   s†   € € € € € ð~ð ~ð €Dð"ð "ð "ð"ð "ð "ð"ð "ð "ð"ð "ð "ð
"ð "ð "ð "ð
"ð "ð "ð "ð "r   r2   c                  ó6   — ddl m}  |                      ¦   «         S )Nr   ©Úquant_router)r3   rZ   Úexpert_formatsrY   s    r   Ú_formatsr\   Q   s&   € ØÐÐÐÐÐØ×&Ò&Ñ(Ô(Ð(r   c                   óJ   — e Zd ZdZdxZxZZed„ ¦   «         Zed„ ¦   «         Z	dS )Ú_HostStaginga  Pinned buffers shared by the banks of the process, which run one after the other: the routing payload comes back in one
    blocking copy, the CPU result goes up from pinned memory. `uploaded` orders the next write of the result buffer after its
    transfer.Nc                 óú   — t          | |¦  «        }|�|                     ¦   «         |k     rPt          j        t	          |d|€dn|                     ¦   «         z  ¦  «        |dd¬¦  «        }t          | ||¦  «         |S )Né   r   ÚcpuT©Údtyper   Ú
pin_memory)ÚgetattrÚnumelr	   ÚemptyÚmaxÚsetattr)Úclsr"   rf   rc   Úcurrents        r   Úbufferz_HostStaging.buffer\   s†   € å˜#˜tÑ$Ô$ˆØˆ?˜gŸmšm™oœo°Ò5Ð5Ý”k¥# e¨Q°w°°!°!ÈGÏMÊMÉOÌOÑ-\Ñ"]Ô"]ÐejÐsxð  FJð  Kñ  Kô  KˆGÝ�C˜˜wÑ'Ô'Ð'Øˆr   c                 óp   — | j         �| j                              ¦   «          d x| _        x| _        | _         d S ©N)ÚuploadedÚsynchronizeÚinputsÚoutputs)rj   s    r   Úreleasez_HostStaging.released   s7   € àŒ<Ð#ØŒL×$Ò$Ñ&Ô&Ð&Ø26Ð6ˆŒ
Ð6�S”[ 3¤< < <r   )
rT   rU   rV   rW   rq   rr   ro   Úclassmethodrl   rs   r   r   r   r^   r^   V   sc   € € € € € ðð ð #'Ð&€FÐ&ˆW�xàðð ñ „[ðð ð7ð 7ñ „[ð7ð 7ð 7r   r^   c                   óž   ‡ — e Zd ZdZddddœˆ fd„
Zd„ Zˆ fd„Zd	„ Zdd
„Zd„ Z	d„ Z
ed„ ¦   «         Z ej        ¦   «         dd„¦   «         Zˆ xZS )ÚSwiGLUExpertszüRouted SwiGLU experts: pageable CPU storage in their checkpoint format, plus optional GPU copies. The format is that of the
    loaded checkpoint tensors, or the registered format named at construction (the bank's tensors are then allocated on device).Nra   F)Úformatr   Ú
use_tritonc                ó@  •‡— t          ¦   «                              |d¦  «         ||c| _        | _        || _        d\  | _        | _        d | _        d| _        i | _	        ‰�=|  
                    t          ˆfd„t          ¦   «         D ¦   «         ¦  «        |¦  «         d S d S )Nr   )Nr   éÿÿÿÿc              3   ó2   •K  — | ]}|j         ‰k    ¯|V — Œd S rn   )r"   )Ú.0Ú	candidaterw   s     €r   ú	<genexpr>z)SwiGLUExperts.__init__.<locals>.<genexpr>w   s0   øè è € Ð!dÐ!d°	È9Ì>Ð]cÒKcÐKc )ÐKcÐKcÐKcÐKcÐ!dÐ!dr   )ÚsuperÚ__init__r9   r:   rx   rw   ÚrotationÚ_pointer_tableÚ_pointer_versionÚ_jobsÚ_set_formatÚnextr\   )r7   Únum_expertsr9   r:   rw   r   rx   Ú	__class__s       `  €r   r€   zSwiGLUExperts.__init__n   s§   øø€ Ý‰Œ×Ò˜ bÑ)Ô)Ð)Ø)/°Ð&ˆŒ�TÔ&Ø$ˆŒØ%,Ñ"ˆŒ�T”]Ø"ˆÔØ "ˆÔØˆŒ
ØÐØ×Ò�TÐ!dÐ!dÐ!dÐ!d½X¹Z¼ZÐ!dÑ!dÔ!dÑdÔdÐflÑmÔmÐmÐmÐmð Ðr   c           	      ó>  — | j         D ]
}| j        |= Œ|                     | j        | j        | j        ¦  «        }|                     ¦   «         D ]3\  }\  }}|                      |t          j	        |||¬¦  «        ¦  «         Œ4t          |¦  «        |c| _         | _        d S )N©rc   r   )Úexpert_tensor_namesÚ_buffersr;   r‡   r9   r:   ÚitemsÚregister_bufferr	   rg   Útuplerw   )r7   rw   r   r"   ÚdeclaredÚshaperc   s          r   r…   zSwiGLUExperts._set_formaty   s§   € ØÔ,ð 	$ð 	$ˆDØ”˜dÐ#Ð#Ø—>’> $Ô"2°D´KÀÔARÑSÔSˆØ$,§N¢NÑ$4Ô$4ð 	Wð 	WÑ ˆD‘.�5˜%Ø× Ò  ¥u¤{°5ÀÈfÐ'UÑ'UÔ'UÑVÔVÐVÐVÝ05°h±´ÀÐ-ˆÔ  $¤+ + +r   c           	      ó<  •‡‡— ‰                      ‰dz   d ¦  «        x}�&t          |                     ¦   «         ¦  «        | _        t	          ¦   «         D ]‡}	|	                     | j        | j        | j        ¦  «        }
t          ˆˆfd„|
D ¦   «         ¦  «        rC|	 
                    ˆˆfd„|
D ¦   «         ¦  «        r!|	| j        ur|                      |	d¦  «          nŒˆt          d‰d d…         › �¦  «        ‚t          ¦   «                              ‰‰|||||¦  «         d S )NÚconvrot_group_sizec              3   ó&   •K  — | ]}‰|z   ‰v V — Œd S rn   r   ©r|   r"   ÚprefixÚ
state_dicts     €€r   r~   z6SwiGLUExperts._load_from_state_dict.<locals>.<genexpr>†   s,   øè è € ÐAÐA°4�6˜D‘= JÐ.ÐAÐAÐAÐAÐAÐAr   c                 ó(   •— i | ]}|‰‰|z            “ŒS r   r   r•   s     €€r   ú
<dictcomp>z7SwiGLUExperts._load_from_state_dict.<locals>.<dictcomp>†   sB   ø€ ð  VIð  VIð  VIÐz~ÐVZÐ\fÐgmÐptÑgtÔ\uð  VIð  VIð  VIr   Úmetaz2No registered expert format stores the tensors of rz   )Úpopr   Úitemr�   r\   r;   r‡   r9   r:   Úallr>   rw   r…   r*   r   Ú_load_from_state_dict)r7   r—   r–   Úlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsÚgrouprw   Únamesrˆ   s    ``        €r   rž   z#SwiGLUExperts._load_from_state_dict�   sg  øøø€ Ø—^’^ FÐ-AÑ$AÀ4ÑHÔHÐHˆEÐUÝ §
¢
¡¤Ñ-Ô-ˆDŒMÝ‘j”jð 	cð 	cˆFØ—N’N 4Ô#3°T´[À$ÔBSÑTÔTˆEÝÐAÐAÐAÐAÐA¸5ÐAÑAÔAÑAÔAð ÀfÇnÂnð  VIð  VIð  VIð  VIð  VIð  CHð  VIñ  VIô  VIñ  GJô  GJð Ø ¤Ð,Ð,Ø×$Ò$ V¨VÑ4Ô4Ð4Ø�øåÐaÐTZÐ[^Ð\^Ð[^ÔT_ÐaÐaÑbÔbÐbÝ‰Œ×%Ò% j°&¸.È&ÐR^Ð`oÐq{Ñ|Ô|Ð|Ð|Ð|r   c                 óÔ   — d | _         d| _        t                               ¦   «          | j        r9t
          j                             ¦   «          | j                             ¦   «          d S d S )Nrz   )	r‚   rƒ   r^   rs   r„   r	   r
   rp   Úclear)r7   s    r   Úrelease_execution_cachez%SwiGLUExperts.release_execution_cacheŽ   sf   € Ø"ˆÔØ "ˆÔÝ×ÒÑÔÐØŒ:ð 	ÝŒJ×"Ò"Ñ$Ô$Ð$ØŒJ×ÒÑÔÐÐÐð	ð 	r   c           
      óØ  — |j         }|                     d| j        ¦  «                             ¦   «         }|j         \  }}|€|                      |||¦  «        }|| j        vrÝt          j        |                     ¦   «         t          j	        dd¬¦  «        }t          j        || j        t          j
        dd¬¦  «        }	| j                             | |                     ¦   «         | j        r| j                             ¦   «         nd|	                     ¦   «         ||t!          ¦   «         ¦  «        \  }
}|
|||	f| j        |<   | j        |         \  }
}}}	t          j                             ¦   «         }| j        ot'          | j        ¦  «        x}�r|                      |j        ¦  «        t/          |j        ¦  «        }}|                     ¦   «         |                     ¦   «         }}t          j        || j        t          j
        |j        ¬¦  «        }t          j        ||z  | j        t          j
        |j        ¬¦  «        }|                     |¦  «         t          j                             |¦  «        5  | j                             | ||||||¬¦  «         ddd¦  «         n# 1 swxY w Y   |                     |d¬	¦  «         t;          ||
|¦  «         t          j        |	j         t          j
        |j        ¬¦  «                             |	d¬	¦  «        }|r*|                     |¦  «         |                     |¦  «         |                     |j         ¬
¦  «                             |¦  «        S )aB  Graph-safe forward on the current CUDA stream: the CPU computes the selected experts in a host function queued between the
        copy of the routing payload to pinned memory and the copy of its result back, so a captured graph replays the whole call
        without returning to Python. With the Triton backend, the experts having GPU copies are computed on the GPU instead, in a
        branch running beside the CPU job; a placement change releases the graphs that read these copies. Failures are reported by
        raise_job_errors() once the stream has been synchronized.rz   Nra   Trb   r   rŠ   )rC   rP   ©Únon_blocking©rc   )!r‘   Úreshaper9   Ú
contiguousÚpackr„   r	   rg   rf   Úint32Úfloat32rw   rG   Údata_ptrrx   Úresident_flagsr   r
   Úcurrent_streamÚboolÚ	_residentÚ	_pointersr   r   r:   Úwait_streamr-   rQ   Úcopy_r0   Úadd_Útorc   )r7   rI   Útopk_idsÚtopk_weightsÚpackedr‘   rD   rE   rA   Úresultr,   r+   r-   ÚgpurO   ÚsideÚ
gpu_outputrP   Úoutputs                      r   Úqueue_forwardzSwiGLUExperts.queue_forward–   s�  € ð ”ˆØ�IŠI�b˜$œ+Ñ&Ô&×1Ò1Ñ3Ô3ˆØ”~‰ˆ�Øˆ>Ø—Y’Y˜q (¨LÑ9Ô9ˆFØ˜œÐ#Ð#Ý”k &§,¢,¡.¤.½¼ÈEÐ^bÐcÑcÔcˆGÝ”[ ¨¬½E¼MÐRWÐdhÐiÑiÔiˆFØ œK×/Ò/°°g×6FÒ6FÑ6HÔ6HÐlpÔl{ð  KCÈ$ÔJ]×JfÒJfÑJhÔJhÐJhð  BCð  EK÷  ETò  ETñ  EVô  EVð  X^ð  `dõ  fqñ  fsô  fsñ  tô  t‰MˆC�Ø!$ h°¸Ð!?ˆDŒJ�vÑØ)-¬°FÔ);Ñ&ˆˆX�w Ý”×*Ò*Ñ,Ô,ˆØ”/Ð:¥d¨4¬>Ñ&:Ô&:Ð:ˆ3ñ 	lØ!Ÿ^š^¨A¬HÑ5Ô5µ|ÀAÄHÑ7MÔ7M�dˆHØ%-×%8Ò%8Ñ%:Ô%:¸L×<SÒ<SÑ<UÔ<U�lˆHåœ V¨T¬[ÅÄÐVWÔV^Ð_Ñ_Ô_ˆJÝ”+˜f t™m¨TÔ->ÅeÄmÐ\]Ô\dÐeÑeÔeˆCØ×Ò˜VÑ$Ô$Ð$Ý”×"Ò" 4Ñ(Ô(ð lð lØ”×'Ò'¨¨a°¸<ÈÐWaÐgjÐ'ÑkÔkÐkðlð lð lñ lô lð lð lð lð lð lð løøøð lð lð lð là�Š�f¨4ˆÑ0Ô0Ð0Ý˜ # vÑ.Ô.Ð.Ý”˜Vœ\µ´ÀqÄxÐPÑPÔP×VÒVÐW]ÐlpÐVÑqÔqˆØð 	$Ø×Ò˜tÑ$Ô$Ð$Ø�KŠK˜
Ñ#Ô#Ð#Ø�yŠy˜qœwˆyÑ'Ô'×/Ò/°Ñ6Ô6Ð6s   É1"JÊJ#Ê&J#c                 óš   — | j                              ¦   «         D ]0\  }}}}|j        r"|j        dc}|_        t          d|› d�¦  «        ‚Œ1dS )z`After a stream synchronization: raise the failure of a host job queued by queue_forward, if any.r   zCPU expert kernel failed (r   N)r„   Úvaluesr/   r*   )r7   r,   Ú_r/   s       r   Úraise_job_errorszSwiGLUExperts.raise_job_errors¹   sp   € à œJ×-Ò-Ñ/Ô/ð 	Kð 	K‰LˆC��A�qØŒzð KØ%(¤Z°Ð"�˜œ
Ý"Ð#IÀÐ#IÐ#IÐ#IÑJÔJÐJðKð	Kð 	Kr   c                 ó˜  ‡ ‡— ‰ j         ‰ j        k    s‰ j        €«ˆˆ fd„t          ‰ j        ¦  «        D ¦   «         }t
          j                             ¦   «         rt          d¦  «        ‚t          j
        ¦   «         5  t          j        |t
          j        |¬¦  «        ‰ _        d d d ¦  «         n# 1 swxY w Y   ‰ j        ‰ _         ‰ j        S )Nc                 óž   •— g | ]I}‰j                              |¦  «        xŠrˆfd „‰j        D ¦   «         ndgt          ‰j        ¦  «        z  ‘ŒJS )c                 óD   •— g | ]}‰|                               ¦   «         ‘ŒS r   )r²   )r|   r"   rB   s     €r   ú
<listcomp>z6SwiGLUExperts._pointers.<locals>.<listcomp>.<listcomp>Â   s)   ø€ ÐTÐTÐT°4�X˜d”^×,Ò,Ñ.Ô.ÐTÐTÐTr   r   )r¶   r   r‹   Úlen)r|   ÚexpertrB   r7   s     €€r   rÌ   z+SwiGLUExperts._pointers.<locals>.<listcomp>Â   sž   ø€ ð ;ð ;ð ;Øð fjÔes×ewÒewÐx~ÑeÔeÐYÐYað  jÐTÐTÐTÐT¸4Ô;SÐTÑTÔTÐTð  HIð  GJõ  MPð  QUô  Qiñ  Mjô  Mjñ  Gjð ;ð ;ð ;r   zBThe GPU expert pointer table must be prepared before graph capturerŠ   )rƒ   Úresidency_versionr‚   Úranger‡   r	   r
   Úis_current_stream_capturingr*   r   Únormal_allocationsÚtensorÚint64)r7   r   ÚrowsrB   s   `  @r   r·   zSwiGLUExperts._pointersÀ   s   øø€ ØÔ  DÔ$:Ò:Ð:¸dÔ>QÐ>Yð;ð ;ð ;ð ;ð ;Ý"'¨Ô(8Ñ"9Ô"9ð;ñ ;ô ;ˆDåŒz×5Ò5Ñ7Ô7ð iÝ"Ð#gÑhÔhÐhÝÔ-Ñ/Ô/ð [ð [Ý&+¤l°4½u¼{ÐSYÐ&ZÑ&ZÔ&Z�Ô#ð[ð [ð [ñ [ô [ð [ð [ð [ð [ð [ð [øøøð [ð [ð [ð [à$(Ô$:ˆDÔ!ØÔ"Ð"s   Á;'B.Â.B2Â5B2c                 ó˜  — t          j        |                      d¦  «                             ¦   «                              t           j        ¦  «        |                     d¦  «                             ¦   «                              t           j        ¦  «        |                     d¦  «                             t           j        ¦  «        f¦  «        S )z½forward()'s routing payload as one int32 tensor: float32 activations, float32 probabilities, int32 ids. Graph-safe:
        computing it in the graphed stage that routes saves its launches.rz   )r	   Úcatr­   ÚfloatÚviewr°   r»   )rI   r¼   r½   s      r   r¯   zSwiGLUExperts.packË   sÈ   € õ Œy˜!Ÿ)š) B™-œ-×-Ò-Ñ/Ô/×4Ò4µU´[ÑAÔAÀ<×CWÒCWÐXZÑC[ÔC[×CaÒCaÑCcÔCc×ChÒChÕinÔitÑCuÔCuÐw÷  xHò  xHð  IKñ  xLô  xL÷  xOò  xOõ  PUô  P[ñ  x\ô  x\ð  ]ñ  ^ô  ^ð  	^r   c                 óî
  — |j         }|                     d| j        ¦  «        }|j         \  }}|€|                      |||¦  «        }|j        j        dk    }|rht                               d|                     ¦   «         t          j
        ¦  «        }	|	d |                     ¦   «         …                              |¦  «         n|}	|| j        z  || j        |z   z  }}
|	||||z  z   …                              ¦   «         }|                      ¦   «         5 }d }|�rK| j        |                              ¦   «         �r+|st!          d¦  «        ‚| j        rn| j                             | |                     ¦   «         |                     ¦   «         |                     ¦   «         |                      |j        ¦  «        ¦  «        }�n¥t          j        |t          j        ¬¦  «        }t          j        |¦  «                             ||¦  «        }t5          t7          |                     ¦   «         ¦  «                             |¦  «        ¦  «        D �]}t          j        ||k    ¦  «        \  }}|                     |j        ¦  «        |                     |j        ¦  «        }}| j                              | ||         ¦  «        \  }}tC          j"        ||          #                    ¦   «         |¦  «         $                    dd¬¦  «        \  }}tC          j"        tC          j%        |¦  «        |z  |¦  «        }| &                    d|||||d f          #                    ¦   «         z  ¦  «         �Œ|rQt                               d	|
t          j        ¦  «        }t          j'        �t          j'         (                    ¦   «          n!t          j)        |
t          j        d
¬¦  «        }|	 *                    ¦   «         }| j         +                    | ||d|z  z   |d|
z  z   | j,         *                    ¦   «         | *                    ¦   «         ||t[          ¦   «         ¦	  «	        }|r¿|d |
…                              || j        ¦  «        }|r‚t          j.        ||j        ¬¦  «                             |d¬¦  «        }t          j'        pt          j/         0                    ¦   «         t          _'        t          j'         1                    ¦   «          |�| 2                    |¦  «         n$|�|nt          j        |t          j        ¬¦  «        }|                     |j3        ¬¦  «                             |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S )Nrz   r
   rq   zAA managed expert bank with GPU residents expects CUDA activationsr¬   r`   )Údimr   rr   ra   rŠ   é   r   Trª   )4r‘   r­   r9   r¯   r   Útyper^   rl   rf   r	   r°   r¹   ÚnumpyÚleaseÚ_flagsÚanyÚ
ValueErrorrx   rw   rQ   r®   r·   Ú
zeros_liker±   Ú
from_numpyrÙ   ÚsortedÚsetÚtolistÚintersectionÚwherer»   rS   ÚFÚlinearrØ   ÚchunkÚsiluÚ
index_add_ro   rp   rg   r²   rL   r³   r   Ú
empty_liker
   ÚEventÚrecordrº   rc   )r7   rI   r¼   r½   r¾   r‘   rD   rE   r
   ÚhostÚx_offsetÚ
ids_offsetrJ   rB   rÂ   Úcpu_idsrÎ   rÕ   ÚslotsÚw13Úw2ÚgateÚuprÃ   r¿   ÚbaseÚcounts                              r   ÚforwardzSwiGLUExperts.forwardÑ   sa  € à”ˆØ�IŠI�b˜$œ+Ñ&Ô&ˆØ”~‰ˆ�Øˆ>Ø—Y’Y˜q (¨LÑ9Ô9ˆFØŒxŒ} Ò&ˆØð 	Ý×&Ò& x°·²±´ÅÄÑMÔMˆDØ��&—,’,‘.”.�Ô!×'Ò'¨Ñ/Ô/Ð/Ð/àˆDØ%¨¬Ñ3°V¸t¼{ÈTÑ?QÑ5R�*ˆØ�:˜j¨6°D©=Ñ8Ð8Ô9×?Ò?ÑAÔAˆØ�ZŠZ‰\Œ\ð $	;˜XØˆJØñ i˜DœK¨Ô,×0Ò0Ñ2Ô2ñ iØð jÝ$Ð%hÑiÔiÐiØ”?ð iØ!%¤×!8Ò!8¸¸q¿|º|¹~¼~Èx×ObÒObÑOdÔOdÐfr×f}Òf}ÑfÔfð  BF÷  BPò  BPð  QRô  QYñ  BZô  BZñ  "[ô  "[�J‘Jõ "'Ô!1°!½5¼=Ð!IÑ!IÔ!I�JÝ#Ô.¨sÑ3Ô3×8Ò8¸ÀÑFÔF�GÝ"(­¨S¯ZªZ©\¬\Ñ):Ô):×)GÒ)GÈÑ)QÔ)QÑ"RÔ"Rð iñ i˜Ý&+¤k°'¸VÒ2CÑ&DÔ&D™˜˜eØ&*§g¢g¨a¬hÑ&7Ô&7¸¿ºÀ!Ä(Ñ9KÔ9K˜e˜Ø"&¤+×"8Ò"8¸¸xÈÔ?OÑ"PÔ"P™˜˜RÝ#$¤8¨A¨d¬G¯MªM©O¬O¸SÑ#AÔ#A×#GÒ#GÈÈrÐ#GÑ#RÔ#R™˜˜bÝ!"¤­!¬&°©,¬,¸Ñ*;¸RÑ!@Ô!@˜Ø"×-Ò-¨a°°vÀÈTÐSXÐZ^ÐM^Ô@_×@eÒ@eÑ@gÔ@gÑ7gÑhÔhÐhÑhØð RÝ%×,Ò,¨Y¸Å%Ä-ÑPÔP�ÝÔ(Ð4Ý Ô)×5Ò5Ñ7Ô7Ð7øåœ XµU´]È5ÐQÑQÔQ�Ø—=’=‘?”?ˆDØ”K×+Ò+¨D°$¸¸qÀ:¹~Ñ8MÈtÐVWÐZbÑVbÑObÐdhÔdw÷  eAò  eAñ  eCô  eCð  EK÷  ETò  ETñ  EVô  EVð  X^ð  `dõ  fqñ  fsô  fsñ  tô  tˆEØð 	lØ 	  	Ô*×/Ò/°¸¼ÑDÔD�Øð 3Ý"Ô-¨f¸Q¼XÐFÑFÔF×LÒLÈVÐbfÐLÑgÔg�FÝ,8Ô,AÐ,WÅUÄZ×EUÒEUÑEWÔEW•LÔ)Ý Ô)×0Ò0Ñ2Ô2Ð2ØÐ)Ø—K’K 
Ñ+Ô+Ð+øà'1Ð'=˜˜Å5ÔCSÐTUÕ]bÔ]jÐCkÑCkÔCk�Ø—9’9 1¤7�9Ñ+Ô+×3Ò3°EÑ:Ô:ðI$	;ð $	;ð $	;ð $	;ñ $	;ô $	;ð $	;ð $	;ð $	;ð $	;ð $	;ð $	;øøøð $	;ð $	;ð $	;ð $	;ð $	;ð $	;s   ÄQU*Õ*U.Õ1U.rn   )rT   rU   rV   rW   r€   r…   rž   r¨   rÄ   rÈ   r·   Ústaticmethodr¯   r	   Úinference_moderý   Ú__classcell__)rˆ   s   @r   rv   rv   k   s  ø€ € € € € ðDð DàDHÐQVÐchð 	nð 	nð 	nð 	nð 	nð 	nð 	nðHð Hð Hð}ð }ð }ð }ð }ðð ð ð!7ð !7ð !7ð !7ðFKð Kð Kð	#ð 	#ð 	#ð ð^ð ^ñ „\ð^ð
 €UÔÑÔð2;ð 2;ð 2;ñ Ôð2;ð 2;ð 2;ð 2;ð 2;r   rv   )rW   r    r   r	   Útorch.nnr   rê   r8   r   r3   r   r   r   r   r   r0   r2   r\   r^   rv   r   r   r   ú<module>r     s?  ðð-ð -à €€€Ø 	€	€	€	à €€€Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð €ð!ð !ð !ð[ð [ð [ð €ðBð Bð Bð!"ð !"ð !"ð !"ð !"ñ !"ô !"ð !"ðH)ð )ð )ð
7ð 7ð 7ð 7ð 7ñ 7ô 7ð 7ð*Y;ð Y;ð Y;ð Y;ð Y;�Jñ Y;ô Y;ð Y;ð Y;ð Y;r   