
    ie                         S SK Jr  S SKJr  S SK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JrJr  S r\ " S	 S
5      5       r\" \" \
5      \" \
5      \" \5      S5      rS\4S jr " S S\5      rg)    )	dataclass)ListN)module_to_annotator)fx)find_sequential_partitionsHistogramObserverMinMaxObserver)OperatorConfigQuantizationSpec	Quantizerc           	      V    [        [        R                  SS[        R                  SU S9$ )Nr      F)dtype	quant_min	quant_maxqscheme
is_dynamicobserver_or_fake_quant_ctr)r   torchuint8per_tensor_affine)r   s    l/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/example/example_quantizer.pyget_uint8_tensor_specr      s+    kk''#=     c                   >    \ rS rSr% \\S'   \\S'   \\S'   \\S'   Srg)ExampleQuantConfig$   input_quant_specoutput_quant_specweight_quant_specbias_quant_spec N)__name__
__module____qualname____firstlineno__r   __annotations____static_attributes__r"   r   r   r   r   $   s    &&''''%%r   r   returnc                     U SS  HF  n[        UR                  5      S:w  a    g[        UR                  S   R                  5      S:w  d  MF    g   g)z
Make sure that all the users of this partiton are within the delegatable subgraph,
except the last partition. If we quantize partitions that have users outside this
subgraph then delegation of this partition to the backend will not be possible.
N   Tr   F)lenoutput_nodesusers)
partitionssource_partitions     r   check_for_outside_usersr2   5   sS     'sO,,-2,,Q/556!;	 ,
 r   c                   v   ^  \ rS rSrS
U 4S jjrS rS\R                  SS4S jr\	S\
\   4S j5       rS	rU =r$ )ExampleQuantizerC   Nc                    > [         TU ]  5         Ub=  Xl        U R                   H&  nU[        R                  " 5       ;  d  M   U S35       e   O[        R                  " 5       U l        Ub  X l        g [        U l        g )Nz# is not supported by this quantizer)super__init__quantizer_supported_modulesr   keysquant_configdefault_static_config)selfr9   r;   module	__class__s       r   r8   ExampleQuantizer.__init__D   sv    &2/J,::!4!9!9!;;L(KLL1 ; 0C/G/G/ID,# , 5Dr   c                     U R                    Hh  n[        U[        U5      5      nU HJ  n[        U5      (       a  M  SnU H  nXV4-  nM
     [        U   R
                  nU" X@R                  5        ML     Mj     U$ )Nr"   )r9   r   listr2   r   annotate_handler;   )r=   modelsupported_modulesfused_partitionsr0   source_module_list	partition	annotators           r   annotateExampleQuantizer.annotateR   s    !%!A!A9&' 
 /
*:66%'"!+I&,6& ", 00ABRR	*&7&78 / "B$ r   rD   r)   c                     g Nr"   )r=   rD   s     r   validateExampleQuantizer.validateg   s    r   c                     / $ rM   r"   )clss    r   get_supported_operators(ExampleQuantizer.get_supported_operatorsj   s    	r   )r;   r9   )NN)r#   r$   r%   r&   r8   rJ   r   GraphModulerN   classmethodr   r
   rR   r(   __classcell__)r?   s   @r   r4   r4   C   sD    6*bnn   ^(<  r   r4   )dataclassesr   typingr   r   1executorch.backends.example.example_operators.opsr   r   torchao.quantization.pt2er   r   r	   #torchao.quantization.pt2e.quantizerr
   r   r   r   r   r<   boolr2   r4   r"   r   r   <module>r]      s    "   Q  
  & & & ++,+,.) 4 )y )r   