U
    T?h
                     @   sJ   d dl 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)Fusion)helper)	OnnxModelc                       s*   e Zd Zed fddZdd Z  ZS )FusionQuickGelu)modelc                    s   t  |ddg d S )N	QuickGeluMul)super__init__)selfr   	__class__ [/var/www/html/venv/lib/python3.8/site-packages/onnxruntime/transformers/fusion_quickgelu.pyr
      s    zFusionQuickGelu.__init__c           
      C   sT  |j dkrtd d S |}|jd }| j|dgdg}|d krPtd d S |d }| j|dgdg}|d krtd d S |d }| j|jd  }t|d d	krtd
 d S |jd |krtd d S t	j
d|g|jd g| jdd}	d|	_|	jt	d|g | j|||g | j|	 | j| j|	j< | d d S )Nr   z/fuse_quickgelu: failed to match second Mul noder   ZSigmoid   z,fuse_quickgelu: failed to match Sigmoid nodez.fuse_quickgelu: failed to match first Mul nodeg     <?gMbP?z3fuse_quickgelu: failed to match approximation valuezFfuse_quickgelu: failed to match root input with first Mul node's inputr   )inputsoutputsnamezcom.microsoftalpha)Zop_typeloggerdebuginputr   Zmatch_parent_pathZget_constant_valueitemabsr   Z	make_nodeoutputZcreate_node_namedomain	attributeextendZmake_attributeZnodes_to_removeZnodes_to_addappendZthis_graph_nameZnode_name_to_graph_namer   Zincrease_counter)
r   nodeZinput_name_to_nodesZoutput_name_to_nodeZsecond_mul_nodeZ
root_inputZsigmoid_nodeZfirst_mul_nodeZapproximation_valuenew_noder   r   r   fuse   sD    








zFusionQuickGelu.fuse)__name__
__module____qualname__r   r
   r!   __classcell__r   r   r   r   r      s   r   )loggingZfusion_baser   Zonnxr   Z
onnx_modelr   	getLoggerr"   r   r   r   r   r   r   <module>   s
   
