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   Úattention_maskr   Úhidden_sizeÚ	num_headsÚattention_fusion)ÚselfÚmodelr   r   ©Ú	__class__© úa/home/ubuntu/.local/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)Úuse_multi_head_attentionr   Ú!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   )Ú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   )ÚloggingÚfusion_attentionr   Úfusion_conformer_attentionr   Úfusion_optionsr   Úonnx_model_bertr   Ú	getLoggerr   Úloggerr   r   r   r   r   Ú<module>   s   
