o
    ²3Ih“  ã                   @   sX   d dl Z ddlmZmZmZ ddlmZ ddlmZ G dd„ deƒZ	G d	d
„ d
eƒZ
dS )é    Né   )ÚQuantizedValueÚQuantizedValueTypeÚattribute_to_kwargé   )ÚQuantOperatorBase)ÚQDQOperatorBasec                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚQSplitc                    s   t ƒ  ||¡ d S )N)ÚsuperÚ__init__)ÚselfÚonnx_quantizerÚ	onnx_node©Ú	__class__© úh/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/onnxruntime/quantization/operators/split.pyr   	   s   zQSplit.__init__c                    s  | j }| j |dg¡\}}}}|d u rtƒ  ¡ S d}|jr"|jd }i }|jD ]	}| t|ƒ¡ q'g }	|j	D ]}
|
d }|	 
|¡ t|
||d |d tjƒ}|| jj|
< q6t|jƒdkrf| |jdd … ¡ tjj|j||	|fi |¤Ž}| 
|¡ | j j|7  _d S )Nr   Ú Ú_quantÚ	quantizedr   )ÚnodeÚ	quantizerÚquantize_activationr
   ÚquantizeÚnameÚ	attributeÚupdater   ÚoutputÚappendr   r   ÚInputÚquantized_value_mapÚlenÚinputÚextendÚonnxÚhelperÚ	make_nodeÚop_typeÚ	new_nodes)r   r   Úquantized_input_namesÚzero_point_namesÚscale_namesÚnodesÚquantized_node_nameÚkwargsr   Úquantized_output_namesÚoutput_nameÚquantized_output_nameÚq_outputÚquantized_noder   r   r   r      sH   û




û
ÿÿ
zQSplit.quantize)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   r   r   r	      s    r	   c                   @   s   e Zd Zdd„ ZdS )ÚQDQSplitc                 C   sj   | j }|jdks
J ‚| j |jd ¡s| j |jd ¡ | js1|jD ]}| j ||jd |j	¡ q"d S d S )NÚSplitr   )
r   r'   r   Úis_tensor_quantizedr"   Úquantize_activation_tensorÚdisable_qdq_for_node_outputr   Úquantize_output_same_as_inputr   )r   r   r   r   r   r   r   7   s   
þzQDQSplit.quantizeN)r4   r5   r6   r   r   r   r   r   r8   6   s    r8   )r$   Úquant_utilsr   r   r   Úbase_operatorr   Úqdq_base_operatorr   r	   r8   r   r   r   r   Ú<module>   s    .