
    i                     Z   S SK JrJrJrJrJr  S SKrS SKJs  J	s  J
s  Jr  S SK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  S SKJr  S SKJr  S S	KJrJr  S S
KJ r   S SK!J"r"   " S S\RF                  5      r# " S S\RH                  5      r$ " S S\RJ                  5      r% " S S\5      r&g)    )AnyListOptionalSequenceTupleN)QnnPassManager)QnnPartitioner)QnnQuantizer)generate_htp_compiler_spec%generate_qnn_executorch_compiler_specget_soc_to_chipset_map)Tester)	StageType)EdgeCompileConfigto_edge_transform_and_lower)Partitioner)ExportedProgramc                   d   ^  \ rS rSr    S	S\S\\   S\S\\\      S\\   4
U 4S jjjr	Sr
U =r$ )
Quantize   	quantizerquantization_config	calibratecalibration_samplesis_qatc                 (   > [         TU ]  UUUUSS9  g )NF)r   r   r   r   
set_global)super__init__)selfr   r   r   r   r   	__class__s         h/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/qualcomm/tests/tester.pyr   Quantize.__init__   s&     	 3 	 	
     )NTNF)__name__
__module____qualname____firstlineno__r
   r   r   boolr   r   __static_attributes____classcell__r!   s   @r"   r   r      s\     .27;!&

 &c]
 	

 &hsm4
 
 
r$   r   c                   :   ^  \ rS rSrSS\\   4U 4S jjjrSrU =r$ )	Partition.   partitionerc                 :   > [         TU ]  U=(       d    [        S9  g )N)r1   )r   r   r	   )r    r1   r!   s     r"   r   Partition.__init__/   s    #5~ 	 	
r$   r%   )N)	r&   r'   r(   r)   r   r   r   r+   r,   r-   s   @r"   r/   r/   .   s    
H[$9 
 
r$   r/   c            	       v   ^  \ rS rSr    SS\\\      S\\   S\S\	4U 4S jjjr
 SS\S	\	S
S4S jjrSrU =r$ )ToEdgeTransformAndLower5   Npartitionersedge_compile_config	soc_modeluse_fp16c                    > [        US9n[        5       U   U l        [        U R                  US9U l        [
        TU ]  U=(       d    [        U R                  5      /U=(       d	    [        SS9[        S9  g )N)r:   )r9   backend_optionsF)_check_ir_validity)r7   r8   default_partitioner_cls)	r   r   chipsetr   compiler_specsr   r   r	   r   )r    r7   r8   r9   r:   r<   r!   s         r"   r    ToEdgeTransformAndLower.__init__6   sr     5hG-/	:Cll+

 	%N.9L9L*M)N 3 !; E:$2	 	 	
r$   artifactgenerate_etrecordreturnc                     [        5       R                  U5      n[        5       R                  U5      n[        UUU R                  U R
                  US9U l        g )N)transform_passesr1   compile_configrC   )r   transform_for_export_pipelineget_to_edge_transform_passesr   r7   edge_compile_confedge_dialect_program)r    rB   inputsrC   eprF   s         r"   runToEdgeTransformAndLower.runK   sS     ;;HE)+HHL$?-))11/%
!r$   )r?   r@   rK   )NNSM8650T)NF)r&   r'   r(   r)   r   r   r   r   strr*   r   r   rN   r+   r,   r-   s   @r"   r5   r5   5   sz     59;?!
tK01
 &&78
 	

 
 
, QV
'
IM
	
 
r$   r5   c            	          ^  \ rS rSr  SS\R
                  R                  S\\R                     S\	\\
      S\4U 4S jjjrSrU =r$ )	QualcommTesterZ   moduleexample_inputsdynamic_shapesr:   c                    >^ U4S jn[         R                  R                  R                  R                  R                  5       [        R                  [        [        R                  U0-  n[        TU ]-  UUUUS9  g )Nc                  $   > TUS'   [        U 0 UD6$ )Nr:   )r5   )argskwargsr:   s     r"   "create_to_edge_transform_and_lowerCQualcommTester.__init__.<locals>.create_to_edge_transform_and_lowerb   s    !)F:*D;F;;r$   )rU   stage_classesrV   rW   )
executorchbackendstestharnessr   default_stage_classesr   	PARTITIONr/   TO_EDGE_TRANSFORM_AND_LOWERr   r   )r    rU   rV   rW   r:   r\   r^   r!   s       `  r"   r   QualcommTester.__init__[   sr    	<
 #++0088??UUW113U[
 

 	'))	 	 	
r$   r%   )NT)r&   r'   r(   r)   torchnnModuler   Tensorr   r   r*   r   r+   r,   r-   s   @r"   rS   rS   Z   sU    
 04

 ell+
 !s,	

 
 
r$   rS   )'typingr   r   r   r   r   r_   'executorch.backends.test.harness.stagesr`   ra   rb   stages
BaseStagesrg   5executorch.backends.qualcomm._passes.qnn_pass_managerr   6executorch.backends.qualcomm.partition.qnn_partitionerr	   0executorch.backends.qualcomm.quantizer.quantizerr
   (executorch.backends.qualcomm.utils.utilsr   r   r    executorch.backends.test.harnessr   
TesterBaser   executorch.exirr   r   #executorch.exir.backend.partitionerr   torch.exportr   r   r/   r5   rS   r%   r$   r"   <module>rx      s    8 7  < <  P Q I 
 B = J ; (
z"" 
$

$$ 
"
j@@ "
J
Z 
r$   