o
    Zh`                     @   s  U d dl mZmZ ddlmZ zNd dlmZmZmZm	Z	 d dlm
Z dZdedd	d
ideddd
ideddddideddd
idZeeeeeef ef f ed< ee dd Z
W n ey{   dd Z
G dd dZdd Z	dd ZdZY nw dd  Zg d!Zd"S )#    )DictUnion   )is_torchdynamo_compiling)DeviceLayerRepositoryregister_kernel_mappingreplace_kernel_forward_from_hub)use_kernel_forward_from_hubTcudaz!kernels-community/deformable-detrMultiScaleDeformableAttention)repo_id
layer_namezkernels-community/moeLlama4TextMoez#kernels-community/triton-layer-normZLlamaRMSNormzpure-layer-test)r   r   revisionzmedmekk/triton-llama-mlpZTritonLlamaMLP)r   r   ZRMSNormZMLP_KERNEL_MAPPINGc                     s    fdd}|S )a5  
        Expands `kernels`' `use_kernel_forward_from_hub` to NOT use a kernel at compile time. This should be removed
        when `kernels` supports `torch.compile`.

        If the layer has a `config` attribute, we can also set `config.disable_custom_kernels = True` to disable the
        kernel.
        c                    s<    j ti }|   j  fdd}| _  S )Nc                     s>   t  dot jdd }t s|r| i |S | i |S )Nconfigdisable_custom_kernels)hasattrgetattrr   r   )Zforward_argsZforward_kwargsr   clsZkernel_forwardZoriginal_forward T/var/www/auris/lib/python3.10/site-packages/transformers/integrations/hub_kernels.pyforward_with_compile_pathS   s   
zcuse_kernel_forward_from_hub.<locals>.decorator_with_compile_path.<locals>.forward_with_compile_path)forward$original_use_kernel_forward_from_hub)r   	decoratorr   argskwargsr   r   decorator_with_compile_pathH   s   z@use_kernel_forward_from_hub.<locals>.decorator_with_compile_pathr   )r   r    r!   r   r   r   r
   ?   s   	r
   c                  O   s   dd }|S )Nc                 S   s   | S Nr   )r   r   r   r   r   e      z.use_kernel_forward_from_hub.<locals>.decoratorr   )r   r    r   r   r   r   r
   d   s   c                   @   s   e Zd Zdd ZdS )r   c                 O      t d)NzNLayerRepository requires `kernels` to be installed. Run `pip install kernels`.RuntimeError)selfr   r    r   r   r   __init__k      zLayerRepository.__init__N)__name__
__module____qualname__r(   r   r   r   r   r   j   s    r   c                  O   r$   )Nz^replace_kernel_forward_from_hub requires `kernels` to be installed. Run `pip install kernels`.r%   r   r   r   r   r	   n   s   r	   c                  O   r$   )NzVregister_kernel_mapping requires `kernels` to be installed. Run `pip install kernels`.r%   r   r   r   r   r   s   r)   r   Fc                   C   s   t S r"   )_hub_kernels_availabler   r   r   r   is_hub_kernels_availabley   r#   r.   )r   r.   r
   r   r	   N)typingr   r   utilsr   Zkernelsr   r   r   r	   r
   r   r-   r   str__annotations__ImportErrorr.   __all__r   r   r   r   <module>   sN   &"