o
    پi                     @   sb   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 e	e
Ze ZG dd dejZdS )    )Callable)AnyN)current_platform)init_loggerc                       s  e Zd ZU dZd" fddZdefddZdefdd	Zdefd
dZdefddZ	defddZ
defddZdefddZdefddZdefddZdefddZedefddZedefddZi Zeeed  f ed< ededefd d!Z  ZS )#CustomOpzb
    Base class for custom ops.
    Dispatches the forward method to the appropriate backend.
    returnNc                    s   t    |  | _d S N)super__init__dispatch_forward_forward_methodself	__class__ b/home/ubuntu/.local/lib/python3.10/site-packages/sglang/multimodal_gen/runtime/layers/custom_op.pyr
      s   
zCustomOp.__init__c                 O      | j |i |S r   )r   r   argskwargsr   r   r   forward   s   zCustomOp.forwardc                 O      t )zPyTorch-native implementation of the forward method.
        This method is optional. If implemented, it can be used with compilers
        such as torch.compile or PyTorch XLA. Also, it can be used for testing
        purposes.
        NotImplementedErrorr   r   r   r   forward_native      zCustomOp.forward_nativec                 O   r   r   r   r   r   r   r   forward_cuda'   s   zCustomOp.forward_cudac                 O   r   r   r   r   r   r   r   forward_hip*      zCustomOp.forward_hipc                 O   r   r   r   r   r   r   r   forward_cpu.   r    zCustomOp.forward_cpuc                 O   r   r   r   r   r   r   r   forward_tpu2      zCustomOp.forward_tpuc                 O   r   r   r"   r   r   r   r   forward_musa8   r$   zCustomOp.forward_musac                 O   r   r   r"   r   r   r   r   forward_oot>      zCustomOp.forward_ootc                 O   r   r   r"   r   r   r   r   forward_npuC   r'   zCustomOp.forward_npuc                 C   sH   t r| jS t r| jS t r| jS t r| jS t	 r!| j
S | jS r   )_is_cudar   r   is_hipr   is_npur(   is_xpuforward_xpuis_musar%   r   r   r   r   r   r   H   s   zCustomOp.dispatch_forwardc                 C   s   dS )NTr   )clsr   r   r   enabledV   s   zCustomOp.enabledc                   C   r   )z
        On by default if level < CompilationLevel.PIECEWISE
        Specifying 'all' or 'none' in custom_op takes precedence.
        r   r   r   r   r   
default_on[   r   zCustomOp.default_onop_registrynamec                    s    fdd}|S )Nc                    s,    j vsJ d | _|  j < | S )NzDuplicate op name: )r2   r3   )op_clsr/   r3   r   r   	decoratorn   s   
z$CustomOp.register.<locals>.decoratorr   )r/   r3   r6   r   r5   r   registerk   s   zCustomOp.register)r   N)__name__
__module____qualname____doc__r
   r   r   r   r   r   r!   r#   r%   r&   r(   r   r   classmethodboolr0   staticmethodr1   r2   dictstrtype__annotations__r7   __classcell__r   r   r   r   r      s(   
 r   )collections.abcr   typingr   torch.nnnn'sglang.multimodal_gen.runtime.platformsr   1sglang.multimodal_gen.runtime.utils.logging_utilsr   r8   loggeris_cudar)   Moduler   r   r   r   r   <module>   s   