o
    ¢Äid  ã                   @   sV   d dl Z 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 )é    N)ÚAttentionMask)ÚFusionConformerAttention)ÚFusionOptions)ÚBertOnnxModelc                       sH   e Zd Z‡ fdd„ZddedB def‡ fdd„Zd	d
„ Zdd„ Z‡  Z	S )ÚConformerOnnxModelc                    s4   t ƒ  |||¡ t| ƒ| _t| | j| j| jƒ| _d S ©N)ÚsuperÚ__init__r   Zattention_maskr   Úhidden_sizeÚ	num_headsÚattention_fusion)ÚselfÚmodelr   r
   ©Ú	__class__© úg/home/kim/smarthome/.venv/lib/python3.10/site-packages/onnxruntime/transformers/onnx_model_conformer.pyr	      s   
zConformerOnnxModel.__init__NFÚoptionsÚadd_dynamic_axesc                    s>   |d u rdn|j | j_ |d u rdn|j| j_tƒ  ||¡ d S ©NF)Zuse_multi_head_attentionr   Z!disable_multi_head_attention_biasr   Úoptimize)r   r   r   r   r   r   r      s   ÿzConformerOnnxModel.optimizec                 C   s   | j  ¡  d S r   )r   Úapply©r   r   r   r   Úfuse_attention   s   z!ConformerOnnxModel.fuse_attentionc                 C   s   |   ¡  d S r   )Zadjust_reshape_and_expandr   r   r   r   Ú
preprocess   s   zConformerOnnxModel.preprocessr   )
Ú__name__Ú
__module__Ú__qualname__r	   r   Úboolr   r   r   Ú__classcell__r   r   r   r   r      s
    r   )ÚloggingZfusion_attentionr   Zfusion_conformer_attentionr   Zfusion_optionsr   Zonnx_model_bertr   Ú	getLoggerr   Úloggerr   r   r   r   r   Ú<module>   s   
