o
    °ƒðjº  ã                   @   sX   d dl m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 )	é    )Ú	getLogger)ÚFusion)ÚNumpyHelper)Úhelper)Ú	OnnxModelc                       s*   e Zd Zdef‡ fdd„Zdd„ Z‡  ZS )ÚFusionBiasGeluÚmodelc                    s.   |rt ƒ  |ddd¡ d S t ƒ  |dd¡ d S )NÚFastGeluzadd biasÚBiasGeluÚGelu)ÚsuperÚ__init__)Úselfr   Úis_fastgelu©Ú	__class__© úª/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/onnxruntime/transformers/fusion_biasgelu.pyr      s   zFusionBiasGelu.__init__c              	   C   s:  |j }|dkr	dnd}t|jƒdkrd S | j |ddgdd g¡}|d u r&d S |\}}d }	d}
t|jƒD ]\}}| j |¡}|d u rBq3|}
t |¡}	 |	d u rPd S t|	j	ƒdkrYd S ||g}| j 
||jd g||¡sld S | j |¡ tj||jd |j|
 g|j| j ||d	 ¡d
�}d|_| j |¡ | j| j|j< d S )Nr   r
   r	   é   ÚAddÚMatMulr   éÿÿÿÿÚ	_AddBias_)ÚinputsÚoutputsÚnamezcom.microsoft)Úop_typeÚlenÚinputr   Úmatch_parent_pathÚ	enumerateÚget_initializerr   Úto_arrayÚshapeÚis_safe_to_fuse_nodesÚoutputÚnodes_to_removeÚextendr   Ú	make_nodeÚcreate_node_nameÚdomainÚnodes_to_addÚappendÚthis_graph_nameÚnode_name_to_graph_namer   )r   ÚnodeÚinput_name_to_nodesÚoutput_name_to_nodeÚgelu_op_typeÚfuse_op_typeÚnodesÚaddÚmatmulÚbias_weightÚ
bias_indexÚir   ÚinitializerÚsubgraph_nodesÚ
fused_noder   r   r   Úfuse   sH   
ÿüzFusionBiasGelu.fuse)Ú__name__Ú
__module__Ú__qualname__r   r   r=   Ú__classcell__r   r   r   r   r      s    r   N)Úloggingr   Úfusion_baser   Úfusion_utilsr   Úonnxr   Ú
onnx_modelr   r>   Úloggerr   r   r   r   r   Ú<module>   s   