
    i                     (   S SK r S SKrS SKrS SKJrJr  S SKJrJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJrJrJ r   \RB                  RE                  S5         " S S\ RF                  5      r$g)    N)!get_symmetric_quantization_configXNNPACKQuantizer)EdgeCompileConfigto_edge)QuantFusionPass)SpecPropPass)compute_sqnr)QConfigMapping)get_executorch_backend_config)-default_per_channel_symmetric_qnnpack_qconfig)
prepare_fx)export)	FileCheck)override_quantized_engine)#_convert_to_reference_decomposed_fxconvert_pt2eprepare_pt2ez7//executorch/kernels/quantized:custom_ops_generated_libc                   "    \ rS rSrSrSS jrSrg)TestQuantization'   zprepare_pt2e and convert_pt2e are OSS APIs, the rest are all meta-only

APIs for now, but we plan to open source them in the future
Nc           	         SS K n[        S5         S[        R                  R                  l        [        R                  " SSSS5      4n[        R                  R                  5       R                  5       nUR                  U5      n[        R                  R                  X1R                  U5      SS9R                  5       n[        5       n[        SS9nUR!                  U5        [#        X55      nU R%                  ['        UR(                  5      ['        UR*                  5      5        U" U6 S   n[-        U5      n[/        S	S
9n[1        [        X2SS9US9R3                  [5        5       [7        5       /5      nUR9                  5       R                  5       " U6 S   n	[;        5       R=                  S5      R=                  S5      R?                  UR9                  5       R@                  RB                  5        [D        n
[G        5       R!                  U
5      n[I        5       n[K        XKX,S9nU" U6 n[M        XS9nU" U6 nU RO                  [        RP                  " X~SS95        U RO                  [        RR                  " X-
  5      S:  5        U RO                  [U        X5      S:  5        S S S 5        g ! , (       d  f       g = f)Nr   qnnpack         T)strict)is_per_channelF)_check_ir_validity)compile_configKexecutorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensorMexecutorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor)backend_configgư>)atolg?#   )+copyr   torchbackends	quantizedenginerandntorchvisionmodelsresnet18evaldeepcopyr   moduler   r   
set_globalr   assertEqualidactivation_post_process_3activation_post_process_2r   r   r   	transformr   r   exported_programr   checkrungraph_modulecoder   r
   r   r   r   
assertTrueallclosemaxr	   )selfr%   example_inputsmm_copy	quantizeroperator_configafter_prepare_resultr   after_quant_resultqconfigqconfig_mappingr"   m_fxafter_prepare_result_fxafter_quant_result_fxs                   f/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/tests/test_quantization.pytest_resnetTestQuantization.test_resnet-   sj   &y1.7ENN$$+#kk!QS9;N""++-224A]]1%F##==0 $ fh  )*I?tTO  1Q*A1../A4O4O1P $%n#5a#8 QA /#(N q6~i*LN;<  "#!3!3!5!<!<!>!OPQ!RK]e_c""$1166 DG,.99'BO:<ND '+N&;#6D %).$9! OO3SWX OO		,DEL OO/G"LM 211s   JJ//
J= )returnN)__name__
__module____qualname____firstlineno____doc__rM   __static_attributes__rO       rL   r   r   '   s    
KrW   r   )%unittestr&   r+   7executorch.backends.xnnpack.quantizer.xnnpack_quantizerr   r   executorch.exirr   r   (executorch.exir.passes.quant_fusion_passr   %executorch.exir.passes.spec_prop_passr   torch.ao.ns.fx.utilsr	   torch.ao.quantizationr
   $torch.ao.quantization.backend_configr   torch.ao.quantization.qconfigr   !torch.ao.quantization.quantize_fxr   torch.exportr   torch.testingr   (torch.testing._internal.common_quantizedr   'torchao.quantization.pt2e.quantize_pt2er   r   r   opsload_libraryTestCaser   rO   rW   rL   <module>ri      sk       7 D > - 0 N W 8  # N  		  P QQx(( QrW   