
    i                         S SK JrJrJrJr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  S SKJrJrJr  S SKJr  \" S	5       " S
 S\5      5       rg)    )CallableDictListOptionalTupleN)experimental)CompileSpec)DelegationSpecPartitionerPartitionResult)tag_constant_datatag_mutated_buffer)	is_bufferis_lifted_tensor_constantis_param)ExportedProgramzHThis API and all of cuda backend related functionality are experimental.c            	           \ rS rSrSrS\S\\   SS4S jrS\	S\
4S	 jrS
\	S\\\R                  R                     \\\R$                  R&                  /\4      4   4S jrSrg)AotiPartitioner   a  
Base partitioner for AOTInductor-driven backend integration.

This partitioner creates a single partition containing all operators from the input graph.
It skips core ATen decomposition, allowing the backend to handle decomposition using
AOTInductor's backend-specific decomposition table.

Only operators that cannot be handled by the aoti library will be excluded from
the partition and fall back to ExecuTorch's default or custom handling.
backend_namecompile_specreturnNc                 $    [        X5      U l        g)z
Initialize the AOTI partitioner.

Args:
    backend_name: The name of the backend (e.g., "CudaBackend", "MetalBackend")
    compile_spec: List of compilation specifications
N)r
   delegation_spec)selfr   r   s      h/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/aoti/aoti_partitioner.py__init__AotiPartitioner.__init__%   s      .lI    exported_programc                    0 nSnS[         R                  R                  S[        4S jnUR                  R
                   Hf  nUR                  S:X  a  X5R                  S'   M#  UR                  S:X  d  M5  UR                   H!  nU" U5      (       d  M  X5R                  S'     Md     Mh     U R                  X#'   [        U5        [        U5        UR                  R
                   Hg  nUR                  S:X  d  M  [        X5      (       d"  [        X5      (       d  [        X5      (       d  MG  SUR                  ;  d  MY  X5R                  S'   Mi     [        XS	9$ )
zU
Fully delegate the graph to AOTInductor by tagging all nodes as a single partition.
tag0noder   c                    U R                   S:H  =(       ax    U R                  [        R                  R                  R
                  [        R                  R                  R                  [        R                  R                  R                  4;   $ )Ncall_function)optargettorchopshigher_ordercondmap_impl
while_loop)r#   s    r   is_control_flow2AotiPartitioner.partition.<locals>.is_control_flow8   sb    77o- $++		&&++		&&//		&&11B 3 r   r%   delegation_tagget_attrplaceholder)tagged_exported_programpartition_tags)r(   fxNodeboolgraphnodesr&   metausersr   r   r   r   r   r   r   )r   r    r4   tagr.   r#   users          r   	partitionAotiPartitioner.partition/   s$   
 57	%((-- 	D 	 %**00Dww/).1		*+J& JJD&t,,69		"23 ' 1 #22*++,
 %**00Dww-')00-44,-=DD#499425II./ 1 $4
 	
r   epc                 .   [        5       nUR                  R                   He  nUR                  S:X  d  M  [	        UR
                  [        R                  R                  5      (       d  MJ  UR                  UR
                  5        Mg     [        U5      S4$ )z
Return a list of operations that should not be decomposed and let the AOT compiler handle them.
Currently we skip ATen decompositon for all ops, and let the backend handle them.
r%   N)setr8   r9   r&   
isinstancer'   r(   _ops
OpOverloadaddlist)r   r@   do_not_decomposer#   s       r   ops_to_not_decompose$AotiPartitioner.ops_to_not_decompose_   sp     5HHNNDww/)jUZZ22/ / !$$T[[1	 #
 $%t++r   )r   )__name__
__module____qualname____firstlineno____doc__strr   r	   r   r   r   r>   r   r(   rD   rE   r   r   r5   r6   r7   rI   __static_attributes__ r   r   r   r      s    	JS J[8I Jd J.
/ .
o .
`,!,	tEJJ))*HXuxx}}ot>S5T,UU	V,r   r   )typingr   r   r   r   r   r(   executorch.exir._warningsr   +executorch.exir.backend.compile_spec_schemar	   #executorch.exir.backend.partitionerr
   r   r   executorch.exir.backend.utilsr   r   torch._export.utilsr   r   r   torch.export.exported_programr   r   rR   r   r   <module>rZ      sU    9 8  2 C 
 P N N 9 NT,k T,T,r   