+
    G-jõ ã                  óÞ  € ^ RI Ht ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	t
^ RIt^ RIHt ^ RIHt ^RIHtHt ^R	IHt ^R
IHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t) ^RI*H+t+  ! R R]4      t,] ! R R4      4       t- ! R R4      t.] ! R R4      4       t/] ! R R4      4       t0] ! R R4      4       t1] ! R R4      4       t2] ! R R4      4       t3 ! R R]4      t4R# )é    )ÚannotationsN)Ú	dataclass)ÚEnum)ÚAny)ÚTensorProto)Úonnx_pb)ÚBaseQuantizerÚQuantizationParams)Ú
TensorData)ÚDEQUANT_OP_NAMEÚONNX_TYPE_TO_NP_TYPEÚQUANT_OP_NAMEÚQuantizedValueÚQuantizedValueTypeÚ__producer__Ú__version__Úadd_dequant_output_suffixÚadd_dequant_suffixÚadd_quant_input_suffixÚadd_quant_output_suffixÚadd_quant_suffixÚcompute_data_quant_paramsÚcompute_scale_zpÚcompute_scale_zp_float8Úfind_by_nameÚget_qmin_qmax_for_qTypeÚ	ms_domainÚnormalize_axisÚquantize_onnx_initializerÚtensor_proto_to_array)ÚCreateQDQQuantizerc                  ó"   € ] tR t^.t^ t^t^tRtR# )ÚQDQQuantTensorType© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú
ACTIVATIONÚWEIGHTÚBIASÚ__static_attributes__r$   ó    Úw/Volumes/fast/ai/experiments/nudenet-smoke/.venv/lib/python3.14/site-packages/onnxruntime/quantization/qdq_quantizer.pyr#   r#   .   s   † Ø€JØ€FØ„Dr-   r#   c                  ó,   € ] tR t^7t$ R]R&   R]R&   RtR# )ÚQDQQuantParamProviderÚstrÚ
input_nameÚ	node_namer$   N©r%   r&   r'   r(   Ú__annotations__r,   r$   r-   r.   r0   r0   7   s   ‡ àƒOØ‡Nr-   r0   c                  ó<   € ] tR t^?t]P
                  RRR3R ltRtR# )ÚQDQTensorQuantInfoNc                	óT   € Wn         W n        W0n        VR JV n        Vf   Q hW@n        R # ©N)Útensor_typeÚquant_para_providerÚaxisÚ	is_sharedÚ	data_type)Úselfr:   r;   r<   r>   s   &&&&&r.   Ú__init__ÚQDQTensorQuantInfo.__init__@   s0   € Ø&ÔØ#6Ô ØŒ	Ø,°DÐ8ˆŒØÒ$Ð$Ð$Ø"Žr-   )r<   r>   r=   r;   r:   )r%   r&   r'   r(   r#   r)   r@   r,   r$   r-   r.   r7   r7   ?   s   † Ø#5×#@Ñ#@ÐVZÐaeÐqu÷ #ð #r-   r7   c                  ó@   € ] tR t^Jt$ R]R&   R]R&   R]R&   R]R&   RtR# )	ÚQDQBiasQuantInfor1   r3   r2   Úweight_nameÚfloatÚbetar$   Nr4   r$   r-   r.   rC   rC   J   s   ‡ àƒNØƒOØÓØ
‡Kr-   rC   c                  óB   € ] tR t^Ut$ R]R&   R]R&   R]R&   R R ltR	tR
# )ÚQDQTensorQuantParamsr
   ÚoriginalzQuantizationParams | NoneÚ	convertedúset[str] | NoneÚconverted_recv_nodesc               ó   € V ^8„  d   QhRR/# )é   Úreturnr
   r$   )Úformats   "r.   Ú__annotate__Ú!QDQTensorQuantParams.__annotate__[   s   € ÷ 
fñ 
fÐ6Hñ 
fr-   c                	óº   € V P                   f   V P                  # V P                  f   V P                   # WP                  9   d   V P                   # V P                  # r9   ©rJ   rI   rL   ©r?   Úconsumer_node_names   &&r.   Úget_for_consumerÚ%QDQTensorQuantParams.get_for_consumer[   óO   € Ø�>‰>Ò!Ø—=‘=Ð à×$Ñ$Ò,Ø—>‘>Ð!ð
 #5×8QÑ8QÔ"Qˆt�~‰~ÐeÐX\×XeÑXeÐer-   r$   N©r%   r&   r'   r(   r5   rW   r,   r$   r-   r.   rH   rH   U   s    ‡ à Ó Ø(Ó(Ø)Ó)÷
fñ 
fr-   rH   c                  ó,   € ] tR t^it$ R]R&   R]R&   RtR# )ÚQDQScaleZpInitializersr   ÚscaleÚ
zero_pointr$   Nr4   r$   r-   r.   r\   r\   i   s   ‡ àÓØ×r-   r\   c                  ó6   € ] tR t^rt$ R]R&   R]R&   R]R&   RtR# )	ÚQDQTensorScaleZpInitializersr\   rI   zQDQScaleZpInitializers | NonerJ   rK   rL   r$   Nr4   r$   r-   r.   r`   r`   r   s   ‡ à$Ó$Ø,Ó,Ø)×)r-   r`   c                  óB   € ] tR t^|t$ R]R&   R]R&   R]R&   R R ltR	tR
# )ÚQDQTensorQuantizedValuer   rI   zQuantizedValue | NonerJ   rK   rL   c               ó   € V ^8„  d   QhRR/# )rN   rO   r   r$   )rP   s   "r.   rQ   Ú$QDQTensorQuantizedValue.__annotate__‚   s   € ÷ 
fñ 
f°nñ 
fr-   c                	óº   € V P                   f   V P                  # V P                  f   V P                   # WP                  9   d   V P                   # V P                  # r9   rT   rU   s   &&r.   rW   Ú(QDQTensorQuantizedValue.get_for_consumer‚   rY   r-   r$   NrZ   r$   r-   r.   rb   rb   |   s    ‡ àÓØ$Ó$Ø)Ó)÷
fñ 
fr-   rb   c                  ó„  € ] tR t^�tR6R ltR tR tR]P                  3R lt	R R lt
R R	 ltR
 R ltR tR R ltR7R ltR R ltR tR tR tR tR tR6R R lltR6R R lltR6R ltR R ltR6R ltR tR  tR! tR" tR# R$ ltR6R% R& llt R' R( lt!R) R* lt"R8R+ R, llt#R- R. lt$R/ R0 lt%R1 R2 lt&R3 R4 lt'R5t(R# )9ÚQDQQuantizerNc                	ód  a€ \         P                  ! V VVVVVVVVV	V
4       / V n        / V n        . V n        V
P                  R . 4      V n        V
P                  RR4      V n        V
P                  RR4      V n        V
P                  RR4      V n	        / V n
        / V n        V
P                  R/ 4      V n        V
P                  RR4      '       d   \        MRV n        V
P                  R	R4      V n        V
P                  R
R4      V n        V P"                  ^8  dò   \$        P&                  \$        P(                  \$        P*                  \$        P,                  3o\.        ;QJ d)    V3R lV P0                   4       F  '       g   K   RM	  RM! V3R lV P0                   4       4      pV P                  '       gT   V P2                  S9   g   V P4                  S9   g	   V'       d*   \6        P8                  ! R\         R24       \        V n        V P;                  4       V n        / V n        / V n         R# )Ú"OpTypesToExcludeOutputQuantizationÚAddQDQPairToWeightFÚQuantizeBiasTÚDedicatedQDQPairÚ QDQOpTypePerChannelSupportToAxisÚUseQDQContribOpsNÚQDQKeepRemovableActivationsÚ"QDQDisableWeightAdjustForInt32Biasc              3  ó@   <"  € T F  qP                   S9   x € K  	  R # 5ir9   )r:   )Ú.0ÚtÚopset21_typess   & €r.   Ú	<genexpr>Ú(QDQQuantizer.__init__.<locals>.<genexpr>Ü   s   øé € ð /Ù8Y°1—‘ Ö.Ó8Yùs   ƒzÉONNX QuantizeLinear and DequantizeLinear operators do not support 16-bit/4-bit integer quantization types prior to opset 21. The domain of QuantizeLinear and DequantizeLinear operators will be set to 'z' to enable support.)!r	   r@   Útensors_to_quantizeÚbias_to_quantizeÚnodes_to_removeÚgetÚ'op_types_to_exclude_output_quantizationÚadd_qdq_pair_to_weightÚquantize_biasÚdedicated_qdq_pairÚtensor_to_its_receiving_nodesÚtensor_to_producing_dqÚ'qdq_op_type_per_channel_support_to_axisr   Úqdq_op_domainÚqdq_keep_removable_activationsÚ(qdq_disable_weight_adjust_for_int32_biasÚopset_versionr   ÚUINT16ÚINT16ÚUINT4ÚINT4ÚanyÚtensor_quant_override_qtypesÚactivation_qTypeÚweight_qTypeÚloggingÚwarningÚcalc_graph_quant_paramsÚquantization_paramsÚinitializer_quant_paramsÚquantized_value_map)r?   ÚmodelÚper_channelÚreduce_rangerŽ   r�   Útensors_rangeÚnodes_to_quantizeÚnodes_to_excludeÚop_types_to_quantizeÚextra_optionsÚoverrides_have_opset21_typesru   s   &&&&&&&&&&& @r.   r@   ÚQDQQuantizer.__init__�   s  ø€ ô 	×ÒØØØØØØØØØØ Øô	
ð CEˆÔ Ø=?ˆÔà!ˆÔð 8E×7HÑ7HÐImÐoqÓ7rˆÔ4ð
 '4×&7Ñ&7Ð8LÈeÓ&TˆÔ#ð +×.Ñ.¨~¸tÓDˆÔð #0×"3Ñ"3Ð4FÈÓ"NˆÔØNPˆÔ*ð BDˆÔ#ð 8E×7HÑ7HÐIkÐmoÓ7pˆÔ4à*7×*;Ñ*;Ð<NÐPU×*VÒ*V�YÐ\`ˆÔð /<×.?Ñ.?Ð@]Ð_dÓ.eˆÔ+ð 9F×8IÑ8IÐJnÐpuÓ8vˆÔ5ð
 ×Ñ Ô"Ü(×/Ñ/´×1BÑ1BÄK×DUÑDUÔWb×WgÑWgÐhˆMß+.«3ô /Ø8<×8YÒ8Yó/¯3¯3ª3ô /Ø8<×8YÒ8Yó/ó ,Ð(ð ×%×%Ð%Ø×%Ñ%¨Ô6Ø×$Ñ$¨Ô5ß/ä—’ðcäclÐbmð n&ð&ôô &/�Ô"à#'×#?Ñ#?Ó#AˆÔ ØGIˆÔ%ð $&ˆÖ r-   c                ó4  € \        WP                  P                  4       4      pVe   VP                  # WP                  9   dU   V P                  V,          pVP
                  P                  R4      '       d!   VP
                  P                  P                  # R# )ú"
Check if tensor can be quantized
Nr:   )	r   r•   Úinitializerr>   Úvalue_infosÚtypeÚHasFieldr:   Ú	elem_type©r?   Útensor_nameÚweightÚvis   &&  r.   Ú_get_tensor_typeÚQDQQuantizer._get_tensor_typeò   sw   € ô ˜k¯:©:×+AÑ+AÓ+CÓDˆØÒØ×#Ñ#Ð#Ø×,Ñ,Ô,Ø×!Ñ! +Õ.ˆBØ�w‰w×Ñ ×.Ò.Ø—w‘w×*Ñ*×4Ñ4Ð4Ùr-   c                ó.  € \        WP                  P                  4       4      pVeI   VP                  \        P
                  P                  \        P
                  P                  39   d   R#  R# WP                  9   d|   V P                  V,          pVP                  P                  R4      '       dF   VP                  P                  P                  \
        P                  \
        P                  39   d   R# R# \        P                  ! RV R24       R# )r    Tr:   z$failed to infer the type of tensor: z6. Skip to quantize it. Please check if it is expected.F)r   r•   r¡   r>   Ú
onnx_protor   ÚFLOATÚFLOAT16r¢   r£   r¤   r:   r¥   r�   r�   r¦   s   &&  r.   Ú_is_tensor_quantizableÚ#QDQQuantizer._is_tensor_quantizableÿ   sæ   € ô ˜k¯:©:×+AÑ+AÓ+CÓDˆØÒØ×Ñ¤J×$:Ñ$:×$@Ñ$@Ä*×BXÑBX×B`ÑB`Ð#aÔaÙð bñ ð ×,Ñ,Ô,Ø×!Ñ! +Õ.ˆBØ�w‰w×Ñ ×.Ò.°2·7±7×3FÑ3F×3PÑ3PÜ×!Ñ!Ü×#Ñ#ðUô 4ñ ñ ô	 �OŠOØ6°{°mÐCyÐzôñ r-   c                óv  € V P                  V4      '       d¢   V'       d\   \        V\        4      '       g   \        R\	        V4       R24      hV P                  V4      p\        W2VR7      V P                  V&   R# WP                  9  d-   V P                  V4      p\        W4R7      V P                  V&   R# R# R# )a±  
Adds a tensor to the list (actually a dict) of tensors to quantize. Called indirectly by op quantizers that
want to quantize a tensor (i.e., "mark" a tensor for quantization).

If quant_sharing_provider is not None, tensor with name tensor_name will be quantized with the same
quantization parameters as the node input specified in quant_sharing_provider. Ex: A Tranpose node's output
will typically use the same quantization parameter initializers used at the Transpose node's input.

Args:
    tensor_name: name of the tensor to quantize
    quant_sharing_provider: name of the tensor and node that provides quantization parameter
    tensor_type: QDQQuantTensorType default ACTIVATION
zBquant_sharing_provider must be of type QDQQuantParamProvider, not Ú.)r:   r;   r>   )r:   r>   N)r°   Ú
isinstancer0   Ú	TypeErrorr£   rª   r7   rx   )r?   r§   Úquant_sharing_providerr:   r>   s   &&&& r.   Ú__quantize_tensorÚQDQQuantizer.__quantize_tensor  s´   € ð ×&Ñ& {×3Ò3ß%Ü!Ð"8Ô:O×PÒPÜ#Ø\Ô]aÐbxÓ]yÐ\zÐz{Ð|óð ð !×1Ñ1°+Ó>�	Ü8JØ +Ðclô9�×(Ñ(¨Ó5ð ×$<Ñ$<Ô<Ø ×1Ñ1°+Ó>�	Ü8JÐWbÔ8x�×(Ñ(¨Ó5ñ =ñ 4r-   c               ó   € V ^8„  d   QhRR/# ©rN   r§   r1   r$   )rP   s   "r.   rQ   ÚQDQQuantizer.__annotate__2  s   € ÷ Xñ X°cñ Xr-   c                óD   € V P                  VR\        P                  4      # )zË
Adds a tensor to the list of tensors to quantize. Called by op quantizers that
want to quantize a tensor (i.e., "mark" a tensor for quantization).

Args:
    tensor_name: name of the tensor to quantize
N)Ú_QDQQuantizer__quantize_tensorr#   r)   ©r?   r§   s   &&r.   Úquantize_activation_tensorÚ'QDQQuantizer.quantize_activation_tensor2  s    € ð ×%Ñ% k°4Ô9K×9VÑ9VÓWÐWr-   c               ó$   € V ^8„  d   QhRRRRRR/# )rN   Úoutput_namer1   r2   r3   r$   )rP   s   "r.   rQ   r»   <  s"   € ÷ 
ñ 
¸ð 
È#ð 
ÐZ]ñ 
r-   c                óV   € V P                  V\        W#4      \        P                  4      # )aP  
Adds a tensor to the list of tensors to quantize. Called by op quantizers that
want to quantize an output tensor using the same quantization parameters as one of the node's inputs.

Ex: A Tranpose node's output will typically use the same quantization parameter initializers used at
the Transpose node's input.

Args:
    output_name: name of the node output to quantize so that it uses the same quantization params as an input.
    input_name: name of the node input from which the output tensor will get its quantization params.
    node_name: name of the node that consumes `input_name`.
)r½   r0   r#   r)   )r?   rÂ   r2   r3   s   &&&&r.   Úquantize_output_same_as_inputÚ*QDQQuantizer.quantize_output_same_as_input<  s+   € ð ×%Ñ%ØÔ.¨zÓEÔGY×GdÑGdó
ð 	
r-   c               ó   € V ^8„  d   QhRR/# rº   r$   )rP   s   "r.   rQ   r»   M  s   € ÷ Tñ T°#ñ Tr-   c                óD   € V P                  VR\        P                  4      # )zÒ
Adds a tensor to the list of weight tensors to quantize. Called by op quantizers that
want to quantize a weight (i.e., "mark" a weight for quantization).

Args:
    tensor_name: name of the weight to quantize
N)r½   r#   r*   r¾   s   &&r.   Úquantize_weight_tensorÚ#QDQQuantizer.quantize_weight_tensorM  s    € ð ×%Ñ% k°4Ô9K×9RÑ9RÓSÐSr-   c                	ó‚  € \        WP                  P                  4       4      pV'       dz   VP                  \        P
                  P                  \        P
                  P                  39   d5   \        \        P                  W#P                  R 7      V P                  V&   R# R# \        P                  ! RV R24       R# ))r:   r<   r>   z9only support per-channel quantization on weight. Tensor: z is not quantized.N)r   r•   r¡   r>   r­   r   r®   r¯   r7   r#   r*   rx   r�   r�   )r?   r§   r<   r¨   s   &&& r.   Ú"quantize_weight_tensor_per_channelÚ/QDQQuantizer.quantize_weight_tensor_per_channelW  sŽ   € Ü˜k¯:©:×+AÑ+AÓ+CÓDˆßØ×Ñ¤J×$:Ñ$:×$@Ñ$@Ä*×BXÑBX×B`ÑB`Ð#aÔaÜ8JÜ 2× 9Ñ 9À×P`ÑP`ô9�×(Ñ(¨Ó5ñ bô
 �OŠOÐWÐXcÐWdÐdvÐwÖxr-   c               ó    € V ^8„  d   QhRRRR/# )rN   r¡   úonnx.TensorProtorO   r$   )rP   s   "r.   rQ   r»   a  s   € ÷ 
ñ 
Ð,<ð 
ÐAQñ 
r-   c                ó  € V P                   P                  VP                  4      ^,           pVP                   V 2p\        P                  ! 4       pVP                  V4       W4n        V P                   P                  V4       V# )z[
Duplicates an existing initializer and adds it to the model. Returns the new initializer.
)r•   Ú#get_largest_initializer_name_suffixÚnameÚonnxr   ÚCopyFromÚadd_initializer)r?   r¡   Úname_suffixÚnew_initializer_nameÚnew_initializers   &&   r.   Ú_dup_initializerÚQDQQuantizer._dup_initializera  st   € ð  Ÿ:™:×IÑIÈ+×JZÑJZÓ[Ð^_Õ_ˆØ"-×"2Ñ"2Ð!3°K°=ÐAÐÜ×*Ò*Ó,ˆØ× Ñ  Ô-Ø3ÔØ�
‰
×"Ñ" ?Ô3ØÐr-   c                óJ  € V P                   P                  V4      '       d^   \        P                  ! RV R24       V P	                  V^ R7      w  rgV'       d   V P                  W'4       R# V P                  V4       R# \        W P                  P                  4       4      pVf   \        P                  ! RV R24       R# VP                  \        P                  P                  \        P                  P                  39  d   \        P                  ! RV R24       R# Tp	W P                   9   dX   V P#                  V4      p
V
P$                  p	V P                  P'                  W)V04       \        P                  ! RV R	V	 R
24       \)        WWE4      V P                   V	&   R# )an  
Adds a bias tensor to the list of bias tensors to quantize. Called by op quantizers that
want to quantize a bias with bias_zero_point = 0 and bias_scale = input_scale * weight_scale * beta.
TODO: Explain the reasoning for using this formula.

Args:
    node_name: name of the node that consumes the bias, input, and weight tensors.
    bias_name: name of the bias tensor to quantize.
    input_name: name of the input tensor whose scale is used to compute the bias's scale.
    weight_name: name of the weight tensor whose scale is used to compute the bias's scale.
    beta: Multiplier used to compute the bias's scale.
zQuantizing bias tensor 'z=' as a weight due to the presence of user-specified overrides)Údefault_axisNzExpected bias 'z' to be an initializerz%' to be an floating-point initializerzCreated a copy of bias input 'z
' called 'Ú')Útensor_quant_overridesr{   r�   ÚinfoÚis_tensor_per_channelrË   rÈ   r   r•   r¡   r�   r>   r­   r   r®   r¯   ry   rØ   rÑ   Úreplace_input_of_nodesrC   )r?   r3   Ú	bias_namer2   rD   rF   Úis_per_channelr<   Úbias_initializerÚactual_bias_nameÚnew_bias_initializers   &&&&&&     r.   Úquantize_bias_tensorÚ!QDQQuantizer.quantize_bias_tensorm  sx  € ð ×&Ñ&×*Ñ*¨9×5Ò5Ü�LŠLØ*¨9¨+Ð5rÐsôð $(×#=Ñ#=¸iÐVWÐ#=Ó#XÑ ˆNßØ×7Ñ7¸	ÔHñ ð ×+Ñ+¨IÔ6Ùä'¨	·:±:×3IÑ3IÓ3KÓLÐØÒ#Ü�OŠO˜o¨i¨[Ð8NÐOÔPÙà×%Ñ%¬j×.DÑ.D×.JÑ.JÌJ×LbÑLb×LjÑLjÐ-kÔkÜ�LŠL˜?¨9¨+Ð5ZÐ[Ô\Ùà$ÐØ×-Ñ-Ô-ð $(×#8Ñ#8Ð9IÓ#JÐ Ø3×8Ñ8Ðð �J‰J×-Ñ-¨iÈIÈ;ÔWÜ�LŠLÐ9¸)¸ÀJÐO_ÐN`Ð`aÐbÔcô 3CÀ9ÐZeÓ2lˆ×ÑÐ.Ó/r-   c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )rN   Úinput_scalez
np.ndarrayÚweight_scalerD   r1   Úbias_tprÎ   râ   ÚboolrO   ztuple[bool, np.ndarray | None]r$   )rP   s   "r.   rQ   r»   ž  sN   € ÷ N-ñ N-àðN-ð !ðN-ð ð	N-ð
 "ðN-ð ðN-ð 
(ñN-r-   c                óÚ  € VP                   '       g   R# \        V4      p\        P                  ! \        P                  4      pRp\        P
                  ! VP                  \        P                  R7      \        P
                  ! VP                  ^,           \        P                  R7      ,
          p	VP                  p
RpV'       Egº   \        P                  ! VP                  4       \        P
                  ! ^ \        P                  R7      4      p\        P                  ! VP                  4       \        P
                  ! ^ \        P                  R7      4      p\        P                  ! \        P                  ! V4      \        P                  ! V4      4      pVRV,          ,          V	,          p\        P
                  ! VP                  4       \        P                  R7      p\        P
                  ! VP                  4       \        P                  R7      pVV,          pVV8  dW   VR8”  dP   VV,          p\        P                  ! RV RV RVP                    R	24       VV,          pVP#                  V
4      pR
pW²3# VP$                  '       EdV   \'        VP$                  4      ^8X  Ed;   VP$                  ^ ,          p\)        V4       EF  p\        P                  ! VV,          4      pVRV,          ,          V	,          p\        P
                  ! VP                  4       \        P                  R7      p\        P
                  ! VV,          P                  4       \        P                  R7      pVV,          pVV8  g   K¹  VR8”  g   KÂ  VV,          p\        P                  ! RV RV RV RVP                    R	2	4       VV,          pVP#                  V
4      VV&   R
pEK  	  W²3# )aÙ  
Checks if the bias scale (input_scale * weight_scale) that we intend to use is too small.
A bias scale that is too small leads to quantized bias values that fall outside the range of a int32 and have to
be clipped, which decreases accuracy. If this function detects such a scenario, the weight_scale value will be
increased to prevent this from happening.

Although the adjustment method and amount differs, the idea to adjust the weight's scale came from the following
reference:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/optimize/quantization_utils.cc#L252

:param input_scale: The input's scale.
:param weight_scale: The weight scale to potentially adjust.
:param weight_name: The weight initializer's name. Used for logging.
:param bias_tp: The bias ONNX initializer.
:param is_per_channel: True if the bias and weight are quantized per-channel.
:return: A tuple with a bool indicating if the weight's scale was adjusted and the new weight scale.
Fgq¬‹Ûh ð?©Údtypeg       @g        zIncreasing scale for weight `z` by the ratio z to ensure bias input `z` has a valid scale.TzIncreased scale[z] for weight `z` by ratio ©FN)Úsizer    ÚnpÚiinfoÚint32ÚarrayÚmaxÚfloat64Úminrï   ÚminimumÚmaximumÚabsÚitemr�   rÞ   rÑ   ÚastypeÚshapeÚlenÚrange)r?   ré   rê   rD   rë   râ   Úbias_float_dataÚ
int32_infoÚmultiplicative_epsilonÚqrangeÚweight_scale_dtypeÚupdated_an_elemÚrminÚrmaxÚabsmaxÚbias_smallest_valid_scaleÚinput_scale_fp64Úweight_scale_fp64Úbias_candidate_scaleÚratioÚ	new_scaleÚ	num_elemsÚiÚ	bias_rmaxs   &&&&&&                  r.   Ú#_adjust_weight_scale_for_int32_biasÚ0QDQQuantizer._adjust_weight_scale_for_int32_biasž  s
  € ð2 × × Ð ØÐä/°Ó8ˆä—X’XœbŸh™hÓ'ˆ
Ø!'ÐÜ—’˜*Ÿ.™.´·
±
Ô;¼b¿hºhÀzÇ~Á~ÐXYÕGYÔac×akÑakÔ>lÕlˆØ)×/Ñ/ÐØˆçˆ~Ü—:’:˜o×1Ñ1Ó3´R·X²X¸aÄrÇzÁzÔ5RÓSˆDÜ—:’:˜o×1Ñ1Ó3´R·X²X¸aÄrÇzÁzÔ5RÓSˆDÜ—Z’Z¤§¢ t£¬b¯fªf°T«lÓ;ˆFØ(>À#ÈÅ,Õ(OÐRXÕ(XÐ%ä!Ÿxšx¨×(8Ñ(8Ó(:Ä"Ç*Á*ÔMÐÜ "§¢¨×):Ñ):Ó)<ÄBÇJÁJÔ OÐØ#3Ð6GÕ#GÐ à$Ð'@Ô@ÐG[Ð^aÔGaà1Ð4HÕH�Ü—’Ø3°K°=ÀÐPUÈwð W*Ø*1¯,©,¨Ð7KðMôð .°Õ5�	Ø(×/Ñ/Ð0BÓC�Ø"&�ð. Ð,Ð,ð- ××Ñ¤C¨×(:Ñ(:Ó$;¸qÕ$@à$×*Ñ*¨1Õ-ˆIä˜9×%�ÜŸFšF ?°1Õ#5Ó6�	Ø,BÀcÈIÅoÕ,VÐY_Õ,_Ð)ä#%§8¢8¨K×,<Ñ,<Ó,>ÄbÇjÁjÔ#QÐ Ü$&§H¢H¨\¸!­_×-AÑ-AÓ-CÌ2Ï:É:Ô$VÐ!Ø'7Ð:KÕ'KÐ$Ø(Ð+DÖDÐK_ÐbeÖKeà5Ð8LÕL�EÜ—L’LØ*¨1¨#¨^¸K¸=ÈÐTYÐSZð [1Ø18·±°Ð>RðTôð !2°EÕ 9�IØ&/×&6Ñ&6Ð7IÓ&J�L ‘OØ&*“Oñ! &ð$ Ð,Ð,r-   c                ó4  € V P                   '       d   R# V P                  P                  4        EFä  w  rVP                  V P                  9  g7   VP                  V P
                  9  g   VP                  V P                  9  d   KY  V P                  VP                  ,          P                  VP                  4      pV P
                  VP                  ,          p\        P                  ! VR,          \        P                  P                  VP                  4      R7      pV P                  VP                  ,          pVR,          pV\        P                   P"                  \        P                   P$                  39  d   EKT  VR,          pVP'                  4       '       d   EKv  VR,          p	VP)                  RR4      RJp
V P+                  VV	VP                  \-        WP.                  P1                  4       4      V
4      w  r¼V'       g   EKà  WÆR&   EKç  	  R# )a  
Iterates through all bias inputs that should be quantized to int32. If the intended
bias scale (equal to input_scale * weight_scale) is too small, this function will increase
the associated weight's scale to ensure the bias does not overflow the int32 range when quantized.
Nr]   rî   Ú
quant_typer^   r<   )r…   ry   Úitemsr2   r’   rx   rD   r“   rW   r3   rò   ÚasarrayrÒ   ÚhelperÚtensor_dtype_to_np_dtyper>   r   ÚINT8rˆ   r‹   r{   r  r   r•   r¡   )r?   rá   Ú	bias_infoÚinput_qparamsÚ
input_inforé   Úweight_quant_paramsÚweight_quant_typeÚweight_zero_pointrê   râ   Údid_update_weight_scaleÚnew_weight_scales   &            r.   Ú,_adjust_weight_quant_params_for_bias_tensorsÚ9QDQQuantizer._adjust_weight_quant_params_for_bias_tensorsî  sµ  € ð ×8×8Ð8áà$(×$9Ñ$9×$?Ñ$?×$AÑ ˆIà×$Ñ$¨D×,DÑ,DÔDØ×'Ñ'¨t×/GÑ/GÔGØ×(Ñ(°×0MÑ0MÔMáð !×4Ñ4°Y×5IÑ5IÕJ×[Ñ[Ð\e×\oÑ\oÓpˆMØ×1Ñ1°)×2FÑ2FÕGˆJÜŸ*š*Ø˜gÕ&¬d¯k©k×.RÑ.RÐS]×SgÑSgÓ.hôˆKð #'×"?Ñ"?À	×@UÑ@UÕ"VÐØ 3°LÕ AÐØ ¬×)9Ñ)9×)>Ñ)>Ä×@PÑ@P×@VÑ@VÐ(WÔWÚà,?ÀÕ,MÐØ ×$Ñ$×&Ò&âà':¸7Õ'CˆLØ0×4Ñ4°V¸TÓBÈ$ÐNˆNð 9=×8`Ñ8`ØØØ×%Ñ%Ü˜Y¯
©
×(>Ñ(>Ó(@ÓAØó9Ñ5Ð#÷ 'Ò&Ø/? GÔ,óM %Br-   c                	ó<   € V P                   P                  V4       R # r9   )rz   Úappend)r?   Únodes   &&r.   Úremove_nodeÚQDQQuantizer.remove_node!  s   € Ø×Ñ×#Ñ# DÖ)r-   c                	óP   € V P                   P                  V P                  4       R # r9   )r•   Úremove_nodesrz   )r?   s   &r.   r,  ÚQDQQuantizer.remove_nodes$  s   € Ø�
‰
×Ñ × 4Ñ 4Ö5r-   c                	ó  € V P                   P                  4        FÁ  pV P                  V4      '       dp   \        W4      pVP	                  4        VP
                   FD  pW0P                  9  d   . V P                  V&   V P                  V,          P                  V4       KF  	  VP                  \        8X  g   K   VP                   F  pWP                  V&   K  	  KÃ  	  V P                  4       V n        V P                  4        V P                  4        V P!                  4        V P"                  '       d   V P%                  4        V P'                  4        V P(                  '       g   V P                   P+                  4        \,        V P                   P                   n        \0        V P                   P                   n        V P4                  \6        8X  d!   V P                   P9                  \6        ^4       V P                   P                   # )é   )r•   ÚnodesÚshould_quantize_noder!   ÚquantizeÚinputr€   r'  Úop_typer   Úoutputr�   Ú_calc_initializer_quant_paramsr“   r$  Ú_quantize_normal_tensorsÚ_quantize_sharing_param_tensorsr~   Ú_quantize_bias_tensorsr,  r}   Úclean_initializersr   Úproducer_namer   Úproducer_versionrƒ   r   Úset_opset_import)r?   r(  Úop_quantizerr§   s   &   r.   Úquantize_modelÚQDQQuantizer.quantize_model'  sz  € Ø—J‘J×$Ñ$Ö&ˆDØ×(Ñ(¨×.Ò.Ü1°$Ó=�Ø×%Ñ%Ô'à#'§:¤:�KØ"×*LÑ*LÔLØJL˜×:Ñ:¸;ÑGØ×6Ñ6°{ÕC×JÑJÈ4ÖPñ $.ð �|‰|œÖ.Ø#'§;¤;�KØ?C×/Ñ/°Ó<ó $/ñ 'ð )-×(KÑ(KÓ(MˆÔ%Ø×9Ñ9Ô;Ø×%Ñ%Ô'Ø×,Ñ,Ô.Ø××ÐØ×'Ñ'Ô)Ø×ÑÔØ×*×*Ð*Ø�J‰J×)Ñ)Ô+ä)5ˆ�
‰
×ÑÔ&Ü,7ˆ�
‰
×ÑÔ)Ø×Ñ¤Ô*Ø�J‰J×'Ñ'¬	°1Ô5à�z‰z×ÑÐr-   c                	óø  € W P                   9   dê   V P                   V,          P                  fË   V P                   V,          P                  f¬   \        V P                  P	                  4       V,          4      ^8X  d}   V P                  P                  V4      '       g\   V P                  P                  V4      '       g;   V P                  P                  W4       WP                  9   d   V P                  V R# R# )NTF)	r’   rJ   rÿ   r•   Úinput_name_to_nodesÚis_graph_outputÚis_graph_inputÚreplace_output_of_all_nodesrx   )r?   Úupstream_output_namerÂ   s   &&&r.   Útry_replacing_upstream_outputÚ*QDQQuantizer.try_replacing_upstream_outputF  s½   € à×3Ñ3Ô3Ø×(Ñ(¨Õ5×?Ñ?ÒGØ×(Ñ(Ð)=Õ>×HÑHÒPÜ�D—J‘J×2Ñ2Ó4Ð5IÕJÓKÈqÔPØ—J‘J×.Ñ.Ð/C×DÒDØ—J‘J×-Ñ-Ð.B×CÒCà�J‰J×2Ñ2Ð3GÔUØ#×'?Ñ'?Ô?Ø×,Ñ,Ð-AÐBÙÙr-   c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# )	rN   Úq_inputr1   Úq_outputÚquant_node_nameÚ
scale_nameÚzp_namer<   ú
int | Noner$   )rP   s   "r.   rQ   r»   U  sF   € ÷ -ñ -àð-ð ð-ð ð	-ð
 ð-ð ð-ð ñ-r-   c           	     óª   € \         P                  P                  \        WV.V.VVV P                  R7      pV P
                  P                  V.4       R# )z9
Creates a QuantizeLinear node and adds it to the model.
©r<   ÚdomainN)rÒ   r  Ú	make_noder   rƒ   r•   Ú	add_nodes)r?   rJ  rK  rL  rM  rN  r<   Úqlinear_nodes   &&&&&&& r.   Ú_create_q_nodeÚQDQQuantizer._create_q_nodeU  sR   € ô —{‘{×,Ñ,ÜØ 'Ð*ØˆJØØØ×%Ñ%ð -ó 
ˆð 	�
‰
×Ñ˜l˜^Ö,r-   c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# )	rN   Údq_inputr1   Ú	dq_outputÚdequant_node_namerM  rN  r<   rO  r$   )rP   s   "r.   rQ   r»   k  sF   € ÷ -ñ -àð-ð ð-ð ð	-ð
 ð-ð ð-ð ñ-r-   c           	     óª   € \         P                  P                  \        WV.V.VVV P                  R7      pV P
                  P                  V.4       R# )z;
Creates a DequantizeLinear node and adds it to the model.
rQ  N)rÒ   r  rS  r   rƒ   r•   rT  )r?   rY  rZ  r[  rM  rN  r<   Údequant_nodes   &&&&&&& r.   Ú_create_dq_nodeÚQDQQuantizer._create_dq_nodek  sR   € ô —{‘{×,Ñ,ÜØ 7Ð+ØˆKØØØ×%Ñ%ð -ó 
ˆð 	�
‰
×Ñ˜l˜^Ö,r-   c
           	     	ó  € \         P                  P                  \        WV.V.VV	V P                  R 7      p
\         P                  P                  \
        WGV.V.VV	V P                  R 7      pV P                  P                  W«.4       R# )rQ  N)rÒ   r  rS  r   rƒ   r   r•   rT  )r?   rJ  rK  rL  rY  rZ  r[  rM  rN  r<   rU  r]  s   &&&&&&&&&&  r.   Ú_create_qdq_nodesÚQDQQuantizer._create_qdq_nodes�  s�   € ô —{‘{×,Ñ,ÜØ 'Ð*ØˆJØØØ×%Ñ%ð -ó 
ˆô —{‘{×,Ñ,ÜØ 7Ð+ØˆKØØØ×%Ñ%ð -ó 
ˆð 	�
‰
×Ñ˜lÐ9Ö:r-   c               ó   € V ^8„  d   QhRR/# )rN   Úweight_protorÎ   r$   )rP   s   "r.   rQ   r»   –  s   € ÷ Aeñ AeÐ;Kñ Aer-   c                óP  € VP                   pW P                  9   d   R# V P                  V,          pVP                  R4      pV P	                  W#4      pRp\        V4      pV P                  P                  W'4       V P                  '       d`   \        V4      pV P                  VV\        V4      VV\        V4      VP                  P                   VP                  P                   V4	       MØ\        VVR,          VR,          VR,          V4      p	V P                  P!                  V	4       V	P                   p\"        P$                  P'                  \(        V	P                   VP                  P                   VP                  P                   .V.\        V4      VV P*                  R7      p
V P                  P-                  V
4       \/        VVVP                  P                   VP                  P                   \0        P2                  VR7      p\5        VRR4      V P                  V&   R# )zã
Adds Q/DQ nodes for an initializer. If `self.add_qdq_pair_to_weight` is true, creates
the sequence (weight_f32 -> Q -> DQ -> ). Otherwise, this function quantizes the initializer
and adds the sequence (weight_quant -> DQ ->).
Nr<   r  r^   r]   rQ  )r<   )rÑ   r”   r“   r{   Ú_make_scale_zp_initializersr   r•   Úreplace_input_of_all_nodesr}   r   ra  r   r   r]   r^   r   rÔ   rÒ   r  rS  r   rƒ   Úadd_noder   r   ÚInitializerrb   )r?   rd  rD   Úquant_paramsr<   Úscale_zp_initializersÚq_weight_nameÚweight_dequant_outputÚweight_quant_outputÚquant_weightr]  Úquantized_values   &&          r.   Ú_add_qdq_nodes_for_initializerÚ+QDQQuantizer._add_qdq_nodes_for_initializer–  sì  € ð #×'Ñ'ˆØ×2Ñ2Ô2Ùà+/×+HÑ+HÈÕ+UˆØ ×$Ñ$ VÓ,ˆØ $× @Ñ @ÀÓ [ÐØ$(ˆÜ 9¸+Ó FÐØ�
‰
×-Ñ-¨kÔQà×&×&Ð&ô #:¸+Ó"FÐà×"Ñ"ØØ#Ü  Ó-Ø#Ø%Ü" ;Ó/Ø%×+Ñ+×0Ñ0Ø%×0Ñ0×5Ñ5Øõ
ô 5ØØ˜\Õ*Ø˜\Õ*Ø˜WÕ%ØóˆLð �J‰J×&Ñ& |Ô4à(×-Ñ-ˆMÜŸ;™;×0Ñ0ÜØ×"Ñ"Ð$9×$?Ñ$?×$DÑ$DÐF[×FfÑFf×FkÑFkÐlØ&Ð'Ü" ;Ó/ØØ×)Ñ)ð 1ó ˆLð �J‰J×Ñ Ô-ô )ØØØ!×'Ñ'×,Ñ,Ø!×,Ñ,×1Ñ1Ü×*Ñ*Øô
ˆô 1HÈÐY]Ð_cÓ0dˆ× Ñ  Ó-r-   c                	óˆ  € V P                   '       EdH   WP                  9   Ed7   \        V P                  V,          4      ^8”  Ed   \        V P                  V,          4      p\        V4       Fç  pRV^,            2p\	        V4      V,           p\        V4      V,           p	\        V4      V,           p
\        V4      V,           pV P                  VVV
VV	VVV4       V P                  V,          V,          pV P                  P                  WÁV	4       V^ 8X  g   K®  \        VV	VV\        P                  VR7      p\        VRR4      V P                  V&   Ké  	  R# Tp\        V4      pV P                  P!                  V4      '       d*   \#        V4      pTpV P                  P%                  W4       MV P                  P'                  W4       V P                  V\	        V4      \        V4      \	        V4      V\        V4      VV4       \        VVVV\        P                  VR7      p\        VRR4      V P                  V&   R# )r/  Ú_©Ú
scale_typeN)r   r€   rÿ   r   r   r   r   r   ra  r•   Úreplace_node_inputr   r   ÚInputrb   r”   rC  r   rE  rg  )r?   r§   rM  rN  r>   Únum_dedicated_qdq_pairr  ÚpostfixÚ tensor_name_quant_output_postfixÚ"tensor_name_dequant_output_postfixÚquant_node_name_postfixÚdequant_node_name_postfixr(  rp  rJ  rZ  s   &&&&&           r.   Ú_add_qdq_pair_for_activationÚ)QDQQuantizer._add_qdq_pair_for_activationÙ  s  € à×#×#Ñ#Ø×AÑAÕAÜ�D×6Ñ6°{ÕCÓDÀqÕHä%(¨×)KÑ)KÈKÕ)XÓ%YÐ"ÜÐ1Ö2�Ø˜a !�e˜W˜+�Ü3JÈ;Ó3WÐZaÕ3aÐ0Ü5NÈ{Ó5[Ð^eÕ5eÐ2Ü*:¸;Ó*GÈ'Õ*QÐ'Ü,>¸{Ó,KÈgÕ,UÐ)Ø×&Ñ&ØØ4Ø+Ø4Ø6Ø-ØØô	ð ×9Ñ9¸+ÕFÀqÕI�Ø—
‘
×-Ñ-¨dÐAcÔdØ˜–6Ü&4Ø#Ø:Ø"ØÜ*×0Ñ0Ø#,ô'�Oô =TÐTcÐeiÐkoÓ<p�D×,Ñ,¨[Ó9ó9 3ð< "ˆGÜ1°+Ó>ˆIØ�z‰z×)Ñ)¨+×6Ò6Ü0°Ó=�Ø'�	Ø—
‘
×6Ñ6°{ÕLà—
‘
×5Ñ5°kÔMà×"Ñ"ØÜ'¨Ó4Ü  Ó-Ü'¨Ó4ØÜ" ;Ó/ØØô	ô -ØØØØÜ"×(Ñ(Ø$ôˆOô 5LÈOÐ]aÐcgÓ4hˆD×$Ñ$ [Ó1r-   c           	     ó|  € V P                   P                  V. 4       Uu0 uF  qˆP                  kK  	  p	pV P                  '       d=   WP                   9   d-   \	        V P                   V,          4      ^8”  d   \        R4      hT	p
Vf   T	p\        4       p
MW§,
          p
\	        V4      \	        V	4      8H  pV P                  P                  V4      pTpV'       d'   \        V4      pV P                  P                  W4       \        V4      pV P                  WÞ\        V4      W#4       \        V4      pV'       d   V'       g   TpV
'       d#   Wñ8w  d   V P                  P                  WV
4       V P!                  Wï\#        V4      W#4       TpV'       g0   \        V R24      pV P!                  VV\#        V R24      VV4       \        V R24      pV P                  VV\        V R24      VV4       \        V R24      pV'       d   V'       d   TpV'       d%   VV8w  d   V P                  P                  VVV4       V P!                  VV\#        V R24      VV4       \%        VVVV\&        P(                  VR7      p\%        VVVV\&        P(                  VR7      p\+        VVV4      V P,                  V&   R# u upi )a¾  
Adds Q and DQ ops to a tensor whose quantized data type is converted. That is, some consumers may use the
original data type from the producer, while other consumers use the converted data type.
This is generally done by adding a sequence of ops that convert from one data type (e.g., uint8) to another (e.g., uint16).

T_float ---> Quant(to u8) ---> Convert(to u16) ---> Dequant(to float) ---> T_float'
where Convert(to u16) is equivalent to: ---> Dequant(to float) ---> Quant(to u16) --->

This function handles the following scenarios:

1) Tensor T is not a graph output; all consumers use the converted type

    <Producer> ---> Q1 ---> DQ1 ---> Q2 ---> DQ2 ---> <Consumers>

2) Tensor T is not a graph output; some consumers use the original type, others use the converted type

    <Producer> ---> Q1 -+-> DQ1 ---> <Consumers of original type>
                        |
                        +-> DQ1' ---> Q2 ---> DQ2 ---> <Consumers of converted type>

3) Tensor T is a graph output; all consumers use the converted type

    <Producer> ---> Q1 ---> DQ1 ---> Q2 ---> DQ2 -+-> <Consumers>
                                                  |
                                                  +-> <Graph output>

4) Tensor T is a graph output; some consumers use the original type, others use the converted type

    <Producer> ---> Q1 -+-> DQ1 -+-> <Consumers of original type>
                        |        |
                        |        +-> <Graph output>
                        |
                        +-> DQ1' ---> Q2 ---> DQ2 ---> <Consumers of converted type>

5) Tensor T is a graph output that is not consumed by any other nodes.

    <Producer> ---> Q1 ---> DQ1 ---> Q2 ---> DQ2 ---> <Graph output>
z|Do not currently support converted quant_types in TensorQuantOverrides when the `dedicated_qdq_pair` extra_option is enabledNÚ_convertÚ_convert_cloneru  )r€   r{   rÑ   r   rÿ   Ú
ValueErrorÚsetr•   rC  r   rE  r   rV  r   r   rà   r^  r   r   r   rx  rb   r”   )r?   r§   Úfirst_scale_nameÚfirst_zp_nameÚscale_data_typeÚconvert_scale_nameÚconvert_zp_nameÚconvert_recv_nodesr(  Útensor_recv_nodesÚoriginal_recv_nodesÚall_use_convertedrC  Úfirst_q_inputÚfirst_q_outputÚfirst_dq_outputÚsecond_q_inputÚsecond_q_outputÚsecond_dq_outputÚoriginal_quantized_valueÚconverted_quantized_values   &&&&&&&&             r.   Ú%_add_qdq_ops_for_converted_activationÚ2QDQQuantizer._add_qdq_ops_for_converted_activation  sÄ  € ð` 48×3UÑ3U×3YÑ3YÐZeÐgiÔ3jÓkÑ3j¨4ŸYœYÑ3jÐÐkð ×#×#Ð#Ø×AÑAÔAÜ�D×6Ñ6°{ÕCÓDÀqÔHô ð Oóð ð 0ÐØÒ%Ø!2ÐÜ"%£%Ñà"5Õ"JÐäÐ 2Ó3´sÐ;LÓ7MÑMÐØŸ*™*×4Ñ4°[ÓAˆð $ˆßÜ2°;Ó?ˆMØ�J‰J×2Ñ2°;ÔNä0°Ó=ˆØ×ÑØÔ+;¸KÓ+HÐJZô	
ô
 4°KÓ@ˆß×#4Ø)ˆOß ?Ô#AØ�J‰J×-Ñ-¨kÐL_Ô`à×ÑØÔ-?ÀÓ-LÐN^ô	
ð )ˆß Ü3°{°mÀ8Ð4LÓMˆNØ× Ñ ØØÜ" k ]°.Ð#AÓBØ Øôô 2°[°MÀÐ2JÓKˆØ×ÑØØÜ ˜}¨HÐ5Ó6ØØô	
ô 5¸°}ÀHÐ5MÓNÐß×0Ø*ÐßÐ"2°kÔ"AØ�J‰J×-Ñ-¨kÐ;KÐM_Ô`Ø×ÑØØÜ + ¨hÐ7Ó8ØØô	
ô $2ØØØØÜ×$Ñ$Ø&ô$
Ð ô %3ØØØØÜ×$Ñ$Ø&ô%
Ð!ô 1HØ$Ð&?ÐASó1
ˆ× Ñ  Ó-ùòS ls   ŸJ9c           
     óX  € V P                   P                  4       P                  4        EFü  w  rWP                  9   d   K  VP                  '       d   K,  \        WP                  P                  4       4      pV'       d   V P                  V4       EM…WP                  9   d   V P                   V K‰  V P                  V4      pV'       g   \        RV R24      hVP                  f]   V P                  VVP                  P                  P                   VP                  P"                  P                   VP$                  R7       MÔVP$                  VP                  P                  P$                  8X  g   Q hV P'                  VVP                  P                  P                   VP                  P"                  P                   VP$                  VP                  P                  P                   VP                  P"                  P                   VP(                  4       V P                   V EKÿ  	  R# )zm
Adds Q/DQ ops to tensors (activations and weights) that have been marked for quantization by op quantizers.
z4Quantization parameters are not specified for param zb. In static mode quantization params for inputs and outputs of nodes to be quantized are required.N)r>   )rx   Úcopyr  r”   r=   r   r•   r¡   rq  r�   Ú"_make_tensor_scale_zp_initializersr„  rJ   r  rI   r]   rÑ   r^   r>   r—  rL   )r?   r§   Útensor_infor¡   Útensor_qparam_initializerss   &    r.   r7  Ú%QDQQuantizer._quantize_normal_tensors¹  sÌ  € ð )-×(@Ñ(@×(EÑ(EÓ(G×(MÑ(M×(OÑ$ˆKØ×6Ñ6Ô6Ùà×(×(Ò(ä*¨;¿
¹
×8NÑ8NÓ8PÓQ�ßØ×7Ñ7¸ÖDð #×&AÑ&AÔAØ ×4Ñ4°[ÐAÙ à15×1XÑ1XÐYdÓ1eÐ.ß5Ü(ØRÐS^ÐR_ð `ð óð ð
 2×;Ñ;ÒCà×9Ñ9Ø'Ø6×?Ñ?×EÑE×JÑJØ6×?Ñ?×JÑJ×OÑOØ&1×&;Ñ&;ð	 :õ ð  +×4Ñ4Ð8R×8[Ñ8[×8aÑ8a×8kÑ8kÔkÐkÐkØ×BÑBØ'Ø6×?Ñ?×EÑE×JÑJØ6×?Ñ?×JÑJ×OÑOØ'×1Ñ1Ø6×@Ñ@×FÑF×KÑKØ6×@Ñ@×KÑK×PÑPØ6×KÑKôð ×,Ñ,¨[Ó9óa )Pr-   c           
     óð  € V P                   '       Edã   V P                   P                  4       P                  4        EF²  w  rVP                  pV'       g   K  VP                  V P
                  9   g   K9  V P                   V V P
                  VP                  ,          P                  VP                  4      pV P                  V4      '       d   \        R4      hWP                  9   d   \        RV R24      hRpRpWP                  9   dN   V P                  V,          pVP                  '       d)   V P                  WP                  R4      pVP                  pVf*   V P                  WP                   VP"                  4       EKK  V P%                  VVP                   VP"                  VP&                  P(                  VP&                  P*                  VP,                  P*                  V4       EKµ  	  EKõ  R# )aS  
Adds Q/DQ ops to tensors that have been marked for quantization by op quantizers.
Only operates on tensors that want to use the quantization parameter initializers from an upstream tensor.
For example, a Transpose node's output tensor will typically want to use the same quantization parameter
initializers as the Transpose node's input.
zBQuantization parameter shared mode is not supported for weight yetz5Quantization parameter sharing is invalid for tensor z& because it has already been quantizedNr‚  )rx   rš  r  r;   r2   r”   rW   r3   Úis_input_a_initializerr„  r�   r’   rJ   rf  rL   r  rM  rN  r—  r]   r>   rÑ   r^   )r?   r§   rœ  Úquant_providerrp  Úconverted_qparam_initsrL   Útensor_paramss   &       r.   r8  Ú,QDQQuantizer._quantize_sharing_param_tensorsï  sÀ  € ð ×&×&Ñ&Ø,0×,DÑ,D×,IÑ,IÓ,K×,QÑ,Q×,SÑ(�Ø!,×!@Ñ!@�ß!‘> n×&?Ñ&?À4×C[ÑC[Ö&[Ø×0Ñ0°Ð=à&*×&>Ñ&>¸~×?XÑ?XÕ&Y×&jÑ&jØ&×0Ñ0ó'�Oð ×2Ñ2°;×?Ò?Ü(Ð)mÓnÐnà"×&AÑ&AÔAÜ(ØSÐT_ÐS`ð aDð Dóð ð .2Ð*Ø+/Ð(Ø"×&>Ñ&>Ô>Ø(,×(@Ñ(@ÀÕ(M˜Ø(×2×2Ð2Ø59×5UÑ5UØ +×-DÑ-DÀjó6Ð2ð 4A×3UÑ3UÐ0à-Ò5à×9Ñ9Ø'×)CÑ)CÀ_×E\ÑE\÷ð ×BÑBØ'Ø+×6Ñ6Ø+×3Ñ3Ø2×8Ñ8×BÑBØ2×8Ñ8×=Ñ=Ø2×=Ñ=×BÑBØ0÷ôM -Tñ 'r-   c           
     ó`  € V P                   P                  4        EFŽ  w  rWP                  9   d   K  V P                  W4       \	        WP
                  P                  4       4      pV P
                  P                  V4       V P                  V,          P                  pVP                  R8X  d—   \        VP                  \        4      '       g0   \        R\        VP                  4       RVP                  : 24      h\!        V4      p\"        P$                  P'                  RVP(                  .V.VVP                  R7      pEMHVP                  R9   Ed   VP*                  \"        P,                  P.                  \"        P,                  P0                  \"        P,                  P2                  09   d   \5        RVP*                   R24      hVP(                  VP6                  VP8                  .p\!        V4      pVP:                  e<   \"        P$                  P'                  RVV.VVP:                  V P<                  R	7      pMJ\"        P$                  P'                  RVV.VV P<                  R
7      pM\5        RVP                  : R24      hV P
                  P?                  V4       EK‘  	  R# )za
Adds DQ ops (or Cast) for bias tensors that have been marked for quantization by op quantizers.
ÚCastúUnexpected type z for input=)rÑ   ÚtoNÚDequantizeLinearzUnexpected quantize type z for DequantizeLinear.rQ  )rR  zUnexpected operator type r³   )Nr©  ) ry   r  r”   Úquantize_bias_staticr   r•   r¡   Úremove_initializerrI   Ú	node_typer´   r>   Úintrµ   r£   r2   r   rÒ   r  rS  Úq_nameÚ
node_qtyper   r¯   ÚBFLOAT16r®   ÚRuntimeErrorrM  rN  r<   rƒ   rh  )r?   rá   r  ÚinitÚquant_valuer3   r]  Úinputss   &       r.   r9  Ú#QDQQuantizer._quantize_bias_tensors'  sK  € ð %)×$9Ñ$9×$?Ñ$?×$AÑ ˆIØ×4Ñ4Ô4Ùà×%Ñ% iÔ;Ü 	¯:©:×+AÑ+AÓ+CÓDˆDØ�J‰J×)Ñ)¨$Ô/Ø×2Ñ2°9Õ=×FÑFˆKØ×$Ñ$¨Ô.ô " $§.¡.´#×6Ò6Ü#Ð&6´t¸D¿N¹NÓ7KÐ6LÈKÐXa×XlÑXlÑWoÐ$pÓqÐqÜ.¨yÓ9�	Ü#Ÿ{™{×4Ñ4ØØ ×'Ñ'Ð(Ø�KØ"Ø—~‘~ð  5ó  ’ð ×&Ñ&Ð*DÕDØ×)Ñ)Ü×$Ñ$×,Ñ,Ü×$Ñ$×-Ñ-Ü×$Ñ$×*Ñ*ð.ô ô
 'Ð)BÀ;×CYÑCYÐBZÐZpÐ'qÓrÐrØ%×,Ñ,¨k×.DÑ.DÀk×FYÑFYÐZ�Ü.¨yÓ9�	Ø×#Ñ#Ò/Ü#'§;¡;×#8Ñ#8Ø*ØØ"˜Ø!Ø(×-Ñ-Ø#×1Ñ1ð $9ó $‘Lô $(§;¡;×#8Ñ#8Ø*ØØ"˜Ø!Ø#×1Ñ1ð $9ó $‘Lô #Ð%>¸{×?TÑ?TÑ>WÐWXÐ#YÓZÐZØ�J‰J×Ñ ×-óc %Br-   c               ó   € V ^8„  d   QhRR/# rº   r$   )rP   s   "r.   rQ   r»   ^  s   € ÷ _ñ _¨sñ _r-   c                	óJ   € WP                   9   ;'       g    WP                  9   # r9   )rx   ry   r¾   s   &&r.   Úis_tensor_quantizedÚ QDQQuantizer.is_tensor_quantized^  s"   € Ø×6Ñ6Ñ6×^Ð^¸+×I^ÑI^Ñ:^Ð^r-   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rN   r§   r1   rÛ   r­  r4  z
str | NonerO   ztuple[bool, int | None]r$   )rP   s   "r.   rQ   r»   a  s2   € ÷ /ñ /àð/ð ð/ð ð	/ð
 
!ñ/r-   c                óF  € V P                   P                  V4      pVf   R# V P                  P                  V4      '       d   R# V P                  P	                  V4      pV P
                  '       g   V'       g   R# V'       d   V P                  P                  W24      MTpV'       d,   V P                  P                  V4      pV^ ,          R,          p\        VP                  4      p\        Wh4      w  r–V	'       g"   \        P                  ! RV RV RV 24       R# RV3# )a^  
Checks if a given tensor is configured to be quantized per-channel. If so, also returns the channel axis.

ORT only supports per-channel quantization on static weights (i.e., ONNX initializers). If the user did not provide
tensor quantization overrides for this tensor, then the value of self.per_channel determines if the weight
is to be quantized per-channel.

Params:
    tensor_name: The name of the tensor to check.
    default_axis: The default channel axis. This method checks if the normalized axis is within bounds.
                  Can be overridden via the extra_options 'QDQOpTypePerChannelSupportToAxis'
                  and 'TensorQuantOverrides'.
    op_type: Optional, defaults to None. The operator type that is the only consumer of this weight.
             Used to access the extra option 'QDQOpTypePerChannelSupportToAxis'.
Returns:
    A tuple (is_per_channel, axis) in which the first element indicates whether the tensor is
    quantized per-channel and the second element is the channel axis.
    The returned axis is only None if the tensor is not per-channel or the axis is out of bounds.
r<   zAxis z is out-of-range for weight 'z' with rank Trð   )Úinitializersr{   rÝ   Úhas_per_tensor_overridesÚhas_per_channel_overridesr–   r‚   Úget_per_channel_overridesrÿ   Údimsr   r�   r�   )
r?   r§   rÛ   r4  Úweight_initializerÚhas_per_chan_overridesr<   Úper_chan_overridesÚweight_rankÚ
axis_valids
   &&&&      r.   rß   Ú"QDQQuantizer.is_tensor_per_channela  s
  € ð2 "×.Ñ.×2Ñ2°;Ó?ÐØÒ%ØÐà×&Ñ&×?Ñ?À×LÒLØÐà!%×!<Ñ!<×!VÑ!VÐWbÓ!cÐØ××Ð×(>ØÐçZaˆt×;Ñ;×?Ñ?ÀÔVÐgsˆß!Ø!%×!<Ñ!<×!VÑ!VÐWbÓ!cÐØ% aÕ(¨Õ0ˆDäÐ,×1Ñ1Ó2ˆÜ)¨$Ó<Ñˆ
ßÜ�OŠO˜e D 6Ð)FÀ{ÀmÐS_Ð`kÐ_lÐmÔnØÐà�TˆzÐr-   c               ó$   € V ^8„  d   QhRRRRRR/# )rN   r§   r1   rV   rO   znp.ndarray | Noner$   )rP   s   "r.   rQ   r»   ’  s(   € ÷ cñ c¸#ð cÐSVð cÐ[lñ cr-   c                ón  € V P                   P                  4       pRpWP                  9   d9   V P                  V,          P                  V4      P                  p\        WS4      pMAV P                  P                  VR4      pV'       d   \        VP                  ^,          V4      pVe   \        V4      # R# )aÀ  
Returns the quantization scale of a tensor that is consumed by the given node.
:parameter tensor_name: The name of the tensor.
:parameter consumer_node_name: The name of the node that consumes the tensor as input. Necessary in case
                               the quantization type of the tensor was converted.
                               Refer: QDQQuantizer::_add_qdq_ops_for_converted_activation.
:returns: The quantization scale or None.
N)
r•   r¡   r”   rW   rM  r   r�   r{   r3  r    )r?   r§   rV   r¼  Úscale_initializerrM  Údq_nodes   &&&    r.   Ú_get_tensor_quantization_scaleÚ+QDQQuantizer._get_tensor_quantization_scale’  s    € ð —z‘z×-Ñ-Ó/ˆØ59Ðà×2Ñ2Ô2à×1Ñ1°+Õ>×OÑOÐPbÓc×nÑnˆJÜ ,¨ZÓ FÑð ×1Ñ1×5Ñ5°kÀ4ÓHˆGßÜ$0°·±¸qÕ1AÀ<Ó$PÐ!à;LÒ;XÔ$Ð%6Ó7ÐbÐ^bÐbr-   c               ó$   € V ^8„  d   QhRRRRRR/# )rN   rá   r1   r  rC   rO   r$   )rP   s   "r.   rQ   r»   ª  s#   € ÷ .#ñ .#¨cð .#Ð>Nð .#ÐSVñ .#r-   c                ón  € WP                   9   d(   V P                   V,          P                  P                  # V P                  VP                  VP
                  4      pVf   \        RVP                   RV R24      hV P                  VP                  VP
                  4      pVf   \        RVP                   RV R24      hV P                  WW2P                  4      w  ppppp	p
\        TTTT\        P                  VP                  ^8”  d   ^ MRV	V
R7      p\        VRR4      V P                   V&   V# )zM
Quantized the bias. Zero Point == 0 and Scale == Input_Scale * Weight_Scale
Nz9Unable to get valid quantization scale for weight input 'z' when quantizing bias 'z' to int32.z2Unable to get valid quantization scale for input ')r¬  r¯  )r”   rI   r®  rË  rD   r3   r„  r2   Úquantize_bias_static_implrF   r   r   ri  rñ   rb   )r?   rá   r  rê   ré   Úquantized_bias_nameÚquantized_bias_scale_nameÚquantized_bias_zp_nameÚbias_scale_datar¬  r¯  rp  s   &&&         r.   rª  Ú!QDQQuantizer.quantize_bias_staticª  sc  € ð ×0Ñ0Ô0Ø×+Ñ+¨IÕ6×?Ñ?×FÑFÐFð ×:Ñ:¸9×;PÑ;PÐR[×ReÑReÓfˆØÒÜØKÈI×LaÑLaÐKbð c)Ø)2¨°;ð@óð ð ×9Ñ9¸)×:NÑ:NÐPY×PcÑPcÓdˆØÒÜØDÀY×EYÑEYÐDZð [)Ø)2¨°;ð@óð ð ×*Ñ*¨9À<×Q_ÑQ_Ó`ñ	
ØØ%Ø"ØØØô )ØØØ%Ø"Ü×*Ñ*Ø ×%Ñ%¨Ô)‰A¨tØØ!ô	
ˆô /FÀoÐW[Ð]aÓ.bˆ× Ñ  Ñ+à"Ð"r-   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rN   Ú
param_namer1   rj  r
   Úinit_name_suffixrO   r\   r$   )rP   s   "r.   rQ   r»   Ú  s,   € ÷ $;ñ $;Øð$;Ø-?ð$;ØSVð$;à	ñ$;r-   c                óF  € VR,          pVR,          pVR,          pVP                  R4      pVe   \        VP                  4      ^8X  g&   Vf   \        VP                  4      ^ 8X  g   Q R4       h\        VP                  4      \        VP                  4      8X  g   Q R4       hVR,           V,           pVR,           V,           p	\        P                  P                  W†VP                  VP                  4       P                  4       4      p
V P                  P                  V
4       VP                  \        P                  8X  d   \        P                  P                  pMVVP                  \        P                   8X  d   \        P                  P"                  pM\%        R	VP                   R
V: 24      h\        P                  P                  W›VP                  VP                  4       P                  4       4      pV P                  P                  V4       \'        WÊ4      # )zÑ
Creates and returns scale and zero-point initializers for the given quantization params. The initializers are
named:
    - {param_name}_zero_point{init_name_suffix}
    - {param_name}_scale{init_name_suffix}
r^   r]   r  r<   zWrong scale/zp shapesz,Scale and zero-point must have the same rankÚ_zero_pointÚ_scalezUnexpected dtype=z for param_name=)r{   rÿ   rþ   rÒ   r  Úmake_tensorÚravelÚtolistr•   rÔ   rï   rò   Úfloat32r­   r   r®   Úfloat16r¯   r„  r\   )r?   rÖ  rj  r×  r^   r]   Úzero_point_typer<   Úzero_point_namerM  Úinit_zprv  Ú
init_scales   &&&&         r.   rf  Ú(QDQQuantizer._make_scale_zp_initializersÚ  s°  € ð " ,Õ/ˆ
Ø˜WÕ%ˆØ& |Õ4ˆØ'×+Ñ+¨FÓ3ˆØÒ ¤S¨¯©Ó%5¸Ô%:ÀÂÔQTÐUZ×U`ÑU`ÓQaÐefÔQfð 	
Ø#ó	
Ðgô �5—;‘;Ó¤3 z×'7Ñ'7Ó#8Ô8ÐhÐ:hÓhÐ8à$ }Õ4Ð7GÕGˆØ (Õ*Ð-=Õ=ˆ
ô —+‘+×)Ñ)Ø¨j×.>Ñ.>À
×@PÑ@PÓ@R×@YÑ@YÓ@[ó
ˆð 	�
‰
×"Ñ" 7Ô+à�;‰;œ"Ÿ*™*Ô$Ü#×/Ñ/×5Ñ5‰JØ�[‰[œBŸJ™JÔ&Ü#×/Ñ/×7Ñ7‰JäÐ0°·±°Ð=MÈjÉ^Ð\Ó]Ð]Ü—[‘[×,Ñ,¨ZÀUÇ[Á[ÐRW×R]ÑR]ÓR_×RfÑRfÓRhÓiˆ
Ø�
‰
×"Ñ" :Ô.ä% jÓ:Ð:r-   c               ó    € V ^8„  d   QhRRRR/# )rN   r§   r1   rO   z#QDQTensorScaleZpInitializers | Noner$   )rP   s   "r.   rQ   r»      s   € ÷ qñ q¸cð qÐFiñ qr-   c                óÂ  € V P                   e   WP                   9  d   \        P                  ! RV R24       R# V P                   V,          p\        V\        4      '       g   \        R\        V4       RV: R24      hV P                  WP                  4      pVP                  '       d   V P                  WP                  R4      MRp\        W4VP                  4      # )zÿ
Create and returns all scale/zero_point initializers for a given tensor. If the tensor is converted
to a different quantization type, this function creates two pairs of zp/scale initializers. Otherwise,
only one pair of zp/scale initializers is created.
Nz$Quantization parameters for tensor:"z" not specifiedr§  ú for r³   r‚  )r’   r�   rÞ   r´   rH   rµ   r£   rf  rI   rJ   r`   rL   )r?   r§   r£  Úoriginal_initsÚconverted_initss   &&   r.   r›  Ú/QDQQuantizer._make_tensor_scale_zp_initializers   sÎ   € ð ×#Ñ#Ò+¨{×BZÑBZÔ/ZÜ�LŠLÐ?À¸}ÈOÐ\Ô]Ùà×0Ñ0°Õ=ˆÜ˜-Ô)=×>Ò>ÜÐ.¬t°MÓ/BÐ.CÀ5ÈÉÐWXÐYÓZÐZà×9Ñ9¸+×G]ÑG]Ó^ˆð ×&×&Ð&ð ×,Ñ,¨[×:QÑ:QÐS]Ô^àð 	ô ,¨NÈ]×MoÑMoÓpÐpr-   c               ó$   € V ^8„  d   QhRRRRRR/# )rN   Útensor_datar   Úquant_overrideszdict[str, Any]rO   r
   r$   )rP   s   "r.   rQ   r»     s'   € ÷ kñ k¨Zð kÈ.ð kÐ]oñ kr-   c                ó–  € V P                   pRV9   d   VR,          P                  pRV9   d   RV9   d   VR,          VR,          rTMÚV\        P                  P                  8X  d    \        W1P                  ^,          4      w  rEMœVP                  RVP                  ^ ,          4      pVP                  RVP                  ^,          4      pVP                  RV P                  4      pVP                  RR4      p	\        W9VR	7      w  r«\        WgW«W€P                  4      w  rE\        VP                  4       VP                  4       VR
7      # )z|
Calculates quantization parameters (scale/zero-point) given a tensor's min/max range and optional
user-provided overrides.
r  r]   r^   r  r  Ú	symmetricr—   F)r—   rï  ©r^   r]   r  )r�   r:   rÒ   r   ÚFLOAT8E4M3FNr   Úavg_stdr{   Úrange_valueÚis_activation_symmetricr   r   Úmin_real_ranger
   Úsqueeze)r?   rì  rí  r  Úzeror]   r  r  rï  r—   ÚqminÚqmaxs   &&&         r.   Úcalc_quant_paramsÚQDQQuantizer.calc_quant_params  s  € ð
 ×*Ñ*ˆ
Ø˜?Ô*Ø(¨Õ6×BÑBˆJà�oÔ%¨,¸/Ô*IØ)¨,Õ7¸ÈÕ9Q‘%Øœ4×+Ñ+×8Ñ8Ô8Ü1°*×>QÑ>QÐRSÕ>TÓU‰KˆD�%à"×&Ñ& v¨{×/FÑ/FÀqÕ/IÓJˆDØ"×&Ñ& v¨{×/FÑ/FÀqÕ/IÓJˆDØ'×+Ñ+¨K¸×9UÑ9UÓVˆIØ*×.Ñ.¨~¸uÓEˆLÜ0°ÐbkÔl‰JˆDÜ*¨4°tÀ9×NaÑNaÓb‰KˆDä!¨T¯\©\«^À5Ç=Á=Ã?Ð_iÔjÐjr-   c               ó   € V ^8„  d   QhRR/# )rN   rO   zdict[str, QDQTensorQuantParams]r$   )rP   s   "r.   rQ   r»   .  s   € ÷ #ñ #Ð)Hñ #r-   c                óè  € V P                   f   / # V P                  4        / pV P                    F¿  pV P                   V,          p\        V\        4      '       g   \	        R\        V4       RV: R24      hV P                  P                  V/ R7      pV P                  W44      pRpRpRV9   d1   V P                  W4R,          4      pVR,          P                  R4      p\        WVV4      W&   KÁ  	  V# )zœ
Calculates quantization parameters (scale/zero-point) for all tensors in the graph using each tensor's min/max range
and optional user-provided overrides.
Nr§  rç  r³   )Údefault_valÚconvertÚ
recv_nodes)r˜   Úadjust_tensor_rangesr´   r   rµ   r£   rÝ   Úget_per_tensor_overridesrú  r{   rH   )r?   r’   r§   Útdrí  rI   rJ   rL   s   &       r.   r‘   Ú$QDQQuantizer.calc_graph_quant_params.  sø   € ð
 ×ÑÒ%ØˆIà×!Ñ!Ô#à ÐØ×-Ô-ˆKØ×#Ñ# KÕ0ˆBÜ˜b¤*×-Ò-ÜÐ"2´4¸³8°*¸EÀ+ÁÐPQÐ RÓSÐSà"×9Ñ9×RÑRÐS^ÐlnÐRÓoˆOØ×-Ñ-¨bÓBˆHØˆIØ#'Ð à˜OÔ+Ø ×2Ñ2°2ÀyÕ7QÓR�	Ø'6°yÕ'A×'EÑ'EÀlÓ'SÐ$ä/CÀHÐYmÓ/nÐÓ,ñ .ð  #Ð"r-   c               ó   € V ^8„  d   QhRR/# )rN   rO   zdict[str, QuantizationParams]r$   )rP   s   "r.   rQ   r»   K  s   € ÷ z#ñ z#Ð0Mñ z#r-   c                ó
  € / pV P                   P                  4        EFÝ  w  r#\        W P                  P	                  4       4      pV'       g   K3  \        V4      p\        VP                  4      pVP                  \        P                  J pV'       d   V P                  MV P                  pV P                  P                  V4      '       Ed±   V P                  V,          p	RV	^ ,          9   d   V	^ ,          R,          P                  p\        V,          p
RV	^ ,          9   pV'       gc   \!        \"        P$                  ! V	^ ,          R,          V
R7      \"        P$                  ! V	^ ,          R,          VP&                  4      VR7      W&   Mï. p. pV	 Fh  pVP)                  \"        P$                  ! VR,          V
4      4       VP)                  \"        P$                  ! VR,          VP&                  R7      4       Kj  	  V	^ ,          R,          p\+        Wö4      w  ppV'       g   \-        RVP.                   RV R	V 24      h\!        \"        P$                  ! V4      \"        P$                  ! V4      VVR
7      W&   EKa  V P                  P1                  V/ .4      p	RV	^ ,          9   d   V	^ ,          R,          P                  pV	^ ,          P1                  RVP2                  4      pVRJpT;'       g&    V'       d   V P5                  V4      MV P6                  pV	^ ,          P1                  RV4      pV	^ ,          P1                  RV P8                  4      pRpRpV'       g\   \;        VP=                  4       VVVV P>                  V	^ ,          P1                  R4      V	^ ,          P1                  R4      R7      w  ppEM-\+        Wö4      w  ppV'       g   \-        RVP.                   RV R	V 24      hTpVP                  V,          p. p. p\A        V4       F¥  pVPC                  VV4      pV	'       d   V\        V	4      8  d
   V	V,          M/ p\;        VPE                  4       VVVV P>                  VP1                  R4      VP1                  R4      R7      w  ppVP)                  V4       VP)                  V4       K§  	  \"        PF                  ! V4      p\"        PF                  ! V4      p\!        VVVVR
7      W&   EKà  	  V# )zU
Returns quantization parameters (scale/zero_point/quant_type) for all initializers.
r  r<   r^   rî   r]   rð  zWeight z# has a per-channel axis with value z  that is out-of-bounds for rank )r^   r]   r  r<   Nrï  r—   r  r  )r—   rõ  Úrmin_overrideÚrmax_override)$rx   r  r   r•   r¡   r    rÿ   rþ   r:   r#   r*   rŽ   r�   rÝ   Úoverrides_scale_zpr   r
   rò   rõ   rï   r'  r   r„  rÑ   r{   r<   Úis_weight_symmetricrô  r—   r   Úflattenrõ  r   ÚtakerÜ  r  )r?   r’   r§   rœ  r¡   Úinitializer_dataÚinitializer_rankÚ	is_weightr  Ú	overridesÚzp_dtyperâ   Úzero_points_listÚscales_listÚchan_overridesÚchannel_axisÚis_axis_validÚnorm_channel_axisÚis_symmetric_defaultÚis_symmetricr—   r^   r]   Úchannel_countr  Úper_channel_dataÚchannel_overridesÚchannel_zero_pointÚchannel_scales   &                            r.   r6  Ú+QDQQuantizer._calc_initializer_quant_paramsK  sš  € ð
 >@ÐØ(,×(@Ñ(@×(FÑ(F×(HÑ$ˆKÜ& {·J±J×4JÑ4JÓ4LÓMˆKßÙä4°[ÓAÐÜ"Ð#3×#9Ñ#9Ó:Ðð $×/Ñ/Ô3E×3LÑ3LÐLˆIß.7˜×*Ò*¸T×=RÑ=RˆJð ×*Ñ*×=Ñ=¸k×JÓJØ ×7Ñ7¸ÕD�	Ø 9¨Q¥<Ô/Ø!*¨1¥¨lÕ!;×!GÑ!G�Jä/°
Õ;�Ø!'¨9°Q­<Ñ!7�ß%Ü7IÜ#%§8¢8¨I°a­L¸Õ,FÈhÔ#WÜ Ÿhšh y°¥|°GÕ'<Ð>N×>TÑ>TÓUØ#-ô8Ð'Ò4ð (*Ð$Ø"$�KÛ*3˜Ø(×/Ñ/´·²¸ÈÕ9UÐW_Ó0`ÔaØ#×*Ñ*¬2¯8ª8°NÀ7Õ4KÐSc×SiÑSiÔ+jÖkñ +4ð $-¨Q¥<°Õ#7�LÜ7EÀlÓ7eÑ4�MÐ#4ß(Ü(Ø% k×&6Ñ&6Ð%7Ð7ZÐ[gÐZhð i6Ø6FÐ5GðIóð ô
 8JÜ#%§8¢8Ð,<Ó#=Ü Ÿhšh {Ó3Ø#-Ø.ô	8Ð'Ñ4ò ð ×3Ñ3×7Ñ7¸ÀbÀTÓJˆIØ˜y¨�|Ô+Ø& q�\¨,Õ7×CÑC�
à$ Q�<×+Ñ+¨F°K×4DÑ4DÓEˆLØ)°Ð5ˆNð $2÷ $ð $ß8A�×(Ñ(¨Ô4Àt×GcÑGcð !ð % Q�<×+Ñ+¨KÐ9MÓNˆLØ$ Q�<×+Ñ+¨N¸D×<MÑ<MÓNˆLØ,0ˆJØ'+ˆEç!Ü$=Ø$×,Ñ,Ó.ØØ Ø!-Ø#'×#6Ñ#6Ø"+¨A¥,×"2Ñ"2°6Ó":Ø"+¨A¥,×"2Ñ"2°6Ó":ô%Ñ!�
šEô 4BÀ,Ó3aÑ0�Ð0ß$Ü$Ø! +×"2Ñ"2Ð!3Ð3VÐWcÐVdð e2Ø2BÐ1CðEóð ð
  1�Ø 0× 6Ñ 6°|Õ D�Ø#%Ð Ø �Ü˜}Ö-�AØ'7×'<Ñ'<¸QÀÓ'MÐ$ß8AÀaÌ#ÈiË.ÔFX¨	°!®Ð^`Ð%Ü8QØ(×.Ñ.Ó0Ø"Ø$Ø%1Ø'+×':Ñ':Ø&7×&;Ñ&;¸FÓ&CØ&7×&;Ñ&;¸FÓ&Cô9Ñ5Ð&¨ð %×+Ñ+Ð,>Ô?Ø×&Ñ& }Ö5ñ .ô  ŸZšZÐ(8Ó9�
ÜŸ
š
 ;Ó/�ä/AØ%ØØ%Ø!ô	0ÐÔ,ñ[ )Iðh #Ð"r-   )r}   ry   r   r“   rz   r|   r…   r„   rƒ   r‚   r’   r~   r”   r€   r�   rx   r9   )g      ð?)Ú ))r%   r&   r'   r(   r@   rª   r°   r#   r)   r½   r¿   rÄ   rÈ   rË   rØ   ræ   r  r$  r)  r,  r?  rG  rV  r^  ra  rq  r  r—  r7  r8  r9  r¸  rß   rË  rª  rf  r›  rú  r‘   r6  r,   r$   r-   r.   rh   rh   �   sá   † ô`&òDòð, EIÐVh×VsÑVsô yõ:Xõ
õ"Tòyõ
ô/mõbN-ò`1@òf*ò6ò ò>÷-÷,-ô,;õ*AeôFAiòF[
òz4:òl6òp5.õn_÷/õbcõ0.#÷`$;õLqõ.kõ.#÷:z#ñ z#r-   rh   )5Ú
__future__r   r�   Údataclassesr   Úenumr   Útypingr   Únumpyrò   rÒ   r   r   r­   Úbase_quantizerr	   r
   Ú	calibrater   Úquant_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    Úregistryr!   r#   r0   r7   rC   rH   r\   r`   rb   rh   r$   r-   r.   Ú<module>r*     s  ðõ #ã Ý !Ý Ý ã Û Ý Ý &ç =Ý !÷÷ ÷ ÷ ÷ õ õ. )ô˜ô ð ÷ð ó ð÷#ñ #ð ÷ð ó ðð ÷fð fó ðfð& ÷ð ó ðð ÷*ð *ó ð*ð ÷fð fó ðfô$v#�=ö v#r-   