o
    áÙ·iy  ã                   @   sF   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ dejƒZ	dS )é    )ÚCallable)ÚAnyN)Úcurrent_omni_platformc                       sf   e Zd ZdZd‡ fdd„Zdefdd„Zdefdd	„Zd
d„ Z	dd„ Z
dd„ Zdd„ Z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__© úX/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/diffusion/layers/custom_op.pyr	      s   
zCustomOp.__init__c                 C   s>   t  ¡ r| jS t  ¡ r| jS t  ¡ r| jS t  ¡ r| jS | j	S r   )
r   Úis_rocmÚforward_hipÚis_cudaÚforward_cudaÚis_npuÚforward_npuÚis_xpuÚforward_xpuÚforward_nativer   r   r   r   r
      s   zCustomOp.dispatch_forwardc                 O   ó   | j |i |¤ŽS r   )r   ©r   ÚargsÚkwargsr   r   r   Úforward   s   zCustomOp.forwardc                 O   ó   t ‚)zíPyTorch-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   r   "   s   zCustomOp.forward_nativec                 O   r    r   r!   r   r   r   r   r   *   ó   zCustomOp.forward_cudac                 O   r    r   r!   r   r   r   r   r   -   r#   zCustomOp.forward_npuc                 O   r    r   r!   r   r   r   r   r   0   r#   zCustomOp.forward_xpuc                 O   r   r   )r   r   r   r   r   r   3   s   zCustomOp.forward_hip)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r
   r   r   r   r   r   r   r   Ú__classcell__r   r   r   r   r   	   s    r   )
Úcollections.abcr   Útypingr   Útorch.nnÚnnÚvllm_omni.platformsr   ÚModuler   r   r   r   r   Ú<module>   s
    