
    i                         S SK Jr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  S S
KJr  S SKJr  \ " S S\5      5       rg)    )DictfinalN)ExampleBackend)module_to_annotator)&generate_partitions_from_list_of_nodes)DelegationSpecPartitionerPartitionResult)ops)get_control_flow_submodules)ExportedProgram)OperatorSupportBase)find_sequential_partitionsc                   x    \ rS rSrSrSS jrS\R                  R                  S\	\
\4   4S jrS\S\4S	 jrS
rg)ExamplePartitioner   z2
Partitions all add/mul nodes regardless of order
returnNc                     [         R                  " 5       U l        [        [        R
                  / 5      U l         " S S[        5      nU" 5       U l        g )Nc                   N    \ rS rSrS\R
                  R                  S\4S jrSr	g)@ExamplePartitioner.__init__.<locals>.DequantQuantOperatorSupport%   noder   c                     UR                   S:H  =(       ai    UR                  [        R                  R                  R
                  R                  [        R                  R                  R                  R                  4;   $ )Ncall_function)optargetexir_opsedgequantized_decomposedquantize_per_tensordefaultdequantize_per_tensor)self_submodulesr   s      n/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/example/example_partitioner.pyis_node_supportedRExamplePartitioner.__init__.<locals>.DequantQuantOperatorSupport.is_node_supported&   s[    ww/1 dkkMM66JJRRMM66LLTTF 7      N)
__name__
__module____qualname____firstlineno__torchfxNodeboolr&   __static_attributes__r)   r(   r%   DequantQuantOperatorSupportr   %   s    588== T r(   r3   )	r   keyspatternsr   r   r*   delegation_specr   dequant_quant_support)r#   r3   s     r%   __init__ExamplePartitioner.__init__!   sB    +002-n.E.ErJ	*= 	 &A%B"r(   edge_graph_modulec                    0 n/ nU R                    H<  n[        UU5      nU H'  nU H  nUR                  UR                  5        M      M)     M>     [	        XU R
                  5      nU H  nUR                   H  n	SUR                   3n
XR                  S'   U	R                  S:X  a^  U	R                   HN  n[        U[        R                  R                  5      (       d  M.  UR                  S:X  d  M@  XR                  S'   MP     U R                  X*'   M     M     [        U5       H(  u  pnU R!                  U5      nUR#                  U5        M*     U$ )Ntagdelegation_tagr   get_attr)r5   r   appendnodesr   r7   idmetar   args
isinstancer.   r/   r0   r6   r   _partition_graph_moduleupdate)r#   r:   partition_tagspartition_nodespatternfused_partitionsfused_partition	partition
partitionsr   r=   arg_node_	submodulesubmodule_partition_tagss                  r%   rE   *ExamplePartitioner._partition_graph_module.   s:    57}}G9! 
 $4!0I#**9??; "1 $4 % <0J0J

 $I!#&y||n!5.<		*+77o-$(II&x?? (z 9>LMM*:; %. 261E1E. ( $  ;;LMOA!'+'C'CI'N$!!":;  N r(   exported_programc                 J    U R                  UR                  5      n[        XS9$ )N)tagged_exported_programrG   )rE   graph_moduler
   )r#   rS   partition_tags      r%   rL   ExamplePartitioner.partitionT   s)    445E5R5RS$4
 	
r(   )r6   r7   r5   )r   N)r*   r+   r,   r-   __doc__r8   r.   r/   GraphModuler   strr   rE   r   r
   rL   r2   r)   r(   r%   r   r      sJ    C$!&!5!5$	c>!	"$L
/ 
o 
r(   r   )typingr   r   r.   +executorch.backends.example.example_backendr   1executorch.backends.example.example_operators.opsr   Eexecutorch.exir.backend.canonical_partitioners.pattern_op_partitionerr   #executorch.exir.backend.partitionerr   r	   r
   executorch.exir.dialects._opsr   r   executorch.exir.graph_moduler   torch.exportr    torch.fx.passes.operator_supportr   torchao.quantization.pt2er   r   r)   r(   r%   <module>rf      sN      F Q 
 : D ( @ @ <
 <
 <
r(   