o
    ¢ÄiH  ã                   @   sL   d dl mZ d dlmZ d dlmZ d dlmZ eeƒZ	G dd„ deƒZ
dS )é    )Ú	getLogger)ÚFusionAttentionClip)Ú
ModelProto)ÚBertOnnxModelc                       s<   e Zd Zddededef‡ fdd„Zdd„ Zd	d
„ Z‡  ZS )ÚClipOnnxModelr   ÚmodelÚ	num_headsÚhidden_sizec                    s(   t ƒ j|||d t| | j| jƒ| _d S )N)r   r	   )ÚsuperÚ__init__r   r	   r   Úclip_attention_fusion)Úselfr   r   r	   ©Ú	__class__© úb/home/kim/smarthome/.venv/lib/python3.10/site-packages/onnxruntime/transformers/onnx_model_clip.pyr      s   zClipOnnxModel.__init__c                 C   s@   i }g d¢}|D ]}|   |¡}t|ƒ||< qt d|› ¡ |S )z8
        Returns node count of fused operators.
        )Z	AttentionZFastGeluZGeluZLayerNormalizationZ	QuickGeluZBiasGeluZSkipLayerNormalizationzOptimized operators:)Zget_nodes_by_op_typeÚlenÚloggerÚinfo)r   Zop_countÚopsÚopÚnodesr   r   r   Úget_fused_operator_statistics   s   	
z+ClipOnnxModel.get_fused_operator_statisticsc                 C   s   | j  ¡  d S )N)r   Úapply)r   r   r   r   Úfuse_attention)   s   zClipOnnxModel.fuse_attention)r   r   )	Ú__name__Ú
__module__Ú__qualname__r   Úintr   r   r   Ú__classcell__r   r   r   r   r      s    r   N)Úloggingr   Zfusion_attention_clipr   Zonnxr   Zonnx_model_bertr   r   r   r   r   r   r   r   Ú<module>   s   