
    i
                         S SK JrJr  S SKJr  S SKJr  S SKJrJ	r	J
r
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   " S	 S
\5      r\ " S S5      5       r " S S\5      rg)    )ABCabstractmethod)	dataclass)MappingProxyType)CallableDictListMapping
NamedTupleOptionalTupleUnionN)enforcedmethod)CompileSpec)ExportedProgramc                   0    \ rS rSr% \\S'   \\   \S'   Srg)DelegationSpec   
backend_idcompile_specs N)	__name__
__module____qualname____firstlineno__str__annotations__r	   r   __static_attributes__r       b/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/backend/partitioner.pyr   r      s    O$$r   r   c                   8    \ rS rSr% Sr\\S'   \\\	4   \S'   Sr
g)PartitionResult   a  
tagged_exported_program: the graph with nodes that intend to be delegated containing a "DelegationSpec" metadata
partition_tags: A dictionary that will be used to keep track of the tags and it's corresponding DelegationSpec. The tag is defined by users and used
in the node.meta.
tagged_exported_programpartition_tagsr   N)r   r   r   r   __doc__r   r   r   r   r   r   r   r   r    r"   r"      s     -,n,--r   r"   c            	       <   \ rS rSrSr\" 0 5      4S\\\\	\
\4   \4   4S jjrS\S\4S jr\S\\\\	\
\4   \4   4S j5       r\\S\S\4S	 j5       5       rS
\S\\\R2                  R4                     \\\R:                  R<                  /\4      4   4S jrSr g)Partitioner$   a  
Defines a callable interface for partitioning an exported program for
backend delegation.
A partitioner implementation would receive an exported program, determine what portions of
the it can be delegated to certain backend (though a partitioner can target multiple
backends as well), and return the PartitionResult including:
- the same input module with specific nodes in the input graph tagged for delegation
- the "partition_tags" to indicate how the tag is mapped to Delegation Spec.

The nodes that intend to be delegated must be tagged (by setting
node.meta["delegation_tag"]) and this tag must be provided in the
`partition_tags` dictionary mapping to an instance of
DelegationSpec(backend_id, method_compilation_spec). Each tag must represent
a distinct submodule that we intend on lowering and should be fully contained.

For details on method_compilation_spec see the to_backend API, as these objects follow
the same format.

Args:
    exported_program: An ExportedProgram in Edge dialect to be partitioned for backend delegation.
specc                     Xl         g N_spec)selfr*   s     r    __init__Partitioner.__init__;   s	     
r   exported_programreturnc                 $    U R                  U5      $ r,   )	partitionr/   r2   s     r    __call__Partitioner.__call__A   s    ~~.//r   c                     U R                   $ r,   r-   )r/   s    r    r*   Partitioner.specD   s    zzr   c                     g)a  
Returns the input exported program with newly created sub-Modules encapsulating
specific portions of the input "tagged" for delegation.

The specific implementation is free to decide how existing computation in the
input exported program should be delegated to one or even more than one specific
backends.

The contract is stringent in that:
* Each node that is intended to be delegated must be tagged
* No change in the original input exported program (ExportedProgram) representation can take
place other than adding sub-Modules for encapsulating existing portions of the
input exported program and the associated metadata for tagging.

Args:
    exported_program: An ExportedProgram in Edge dialect to be partitioned for backend delegation.

Returns:
    PartitionResult: includes the tagged graph and the delegation spec to indicate what backend_id and compile_spec is used for each node and the tag created by the backend developers.
Nr   r6   s     r    r5   Partitioner.partitionH   s    . 	r   epc                 
    / S4$ )a  
Returns a list of operator names that should not be decomposed. When these ops are
registered and the `to_backend` is invoked through to_edge_transform_and_lower it will be
guaranteed that the program that the backend receives will not have any of these ops
decomposed.

Returns:
    List[torch._ops.OpOverload]: a list of operator names that should not be decomposed.
    Optional[Callable[[torch.fx.Node], bool]]]: an optional callable, acting as a filter, that users can provide
    which will be called for each node in the graph that users can use as a filter for certain
    nodes that should be continued to be decomposed even though the op they correspond to is
    in the list returned by ops_to_not_decompose.
Nr   )r/   r=   s     r    ops_to_not_decompose Partitioner.ops_to_not_decomposea   s    " Dzr   r-   N)!r   r   r   r   r&   r   r
   r   r   intfloatboolobjectr0   r   r"   r7   propertyr*   r   r   r5   r   r	   torch_ops
OpOverloadr   r   fxNoder?   r   r   r   r    r(   r(   $   s    0 ?Or>ReCeT12F:;0 0_ 0 geCeT$9:FBC   / o   . 
tEJJ))*HXuxx}}ot>S5T,UU	Vr   r(   )abcr   r   dataclassesr   typesr   typingr   r   r	   r
   r   r   r   r   rF   'executorch.exir.backend.backend_detailsr   +executorch.exir.backend.compile_spec_schemar   torch.exportr   r   r"   r(   r   r   r    <module>rR      sX    $ ! " T T T  B C (%Z %
 . . .N# Nr   