
    iU                         S SK JrJr  S SKJr  S SKJrJrJrJ	r	J
r
Jr  S SKJr  S SKJr  S SKJr  S r\ " S S	5      5       r  " S
 S\5      rg)    )ABCabstractmethod)	dataclass)AnyDictListOptionalTupleUnion)NamedDataStoreOutput)CompileSpec)ExportedProgramc                     SU l         U $ )NT)__enforcedmethod__)funcs    f/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/backend/backend_details.pyenforcedmethodr      s    "DK    c                       \ rS rSr% \" 5       r\\S'   Sr\\	\
\\\   4   \
\\\   4   4      \S'   Sr\\   \S'   Sr\\   \S'   Srg)PreprocessResult   processed_bytesNdebug_handle_mapdata_store_output_delegate_info_meta )__name__
__module____qualname____firstlineno__bytesr   __annotations__r   r	   r   r   intr
   strr   r   r   r   __static_attributes__r   r   r   r   r      sj    "WOU$ huT#uSz/%:DeCj<Q%QRS  9=x 45<
 *.#-r   r   c            
          ^  \ rS rSrSrU 4S jr\\\S\	S\
\   S\4S j5       5       5       r\S\\\
\	   4   S\\\
\
\      4   S\\\\   4   4S	 j5       rS
rU =r$ )BackendDetails4   z
A base interface to lower the implementation to the according backend. With
the decorators, this interface will be static, abstract and all inheritances are
enforced to implement this method.

c                   > [         TU ]  " S0 UD6  U R                  [        4:X  a  g U R                   HI  n[	        U[        5      (       d  M  U[        Ld  M%  [        SUR                   SU R                   S35      e   g )Nz5ExecuTorch delegate doesn't support nested backend, 'zX'  should be a final backend implementation and should not be subclassed (attempted by 'z').r   )super__init_subclass__	__bases__r'   
issubclass	TypeErrorr   )clskwargsbase	__class__s      r   r+    BackendDetails.__init_subclass__<   sy    !+F+ ==^-- MMD$//D4NKDMM? [&&)ll^38  "r   edge_programcompile_specsreturnc                     g)a  
Preprocesses an edge program and returns the preprocess result fo the given backend

Args:
    edge_program: The original exported program. It will not be modified in place.
    compile_specs: List of values needed for compilation

Returns:
    PreprocessResult: It wraps the following information:
        processed_bytes -> bytes: A compiled blob - a binary that can run the desired
        program in the backend.
        debug_handle_map (Optional[Dict[int, Tuple[int]]]): For profiling purposes, a
        map from the node_id  in the final graph (either EXIR or the user's self-defined
        IR) to debug handle id attached in the original exported program.
Nr   )r4   r5   s     r   
preprocessBackendDetails.preprocessL   s    4 	r   edge_programsc           
      N   0 nUR                  5        H  u  pEXB;   d
   SU 35       eX$   n[        U5      [        U5      :X  d"   SU S[        U5       S[        U5       35       e/ n[        XV5       H'  u  pU R                  X5      n
UR	                  U
5        M)     XsU'   M     U$ )aV  
Runs preprocess on all partitioned Edge Programs across multiple methods. This allows
backends to share information across partitioned graphs. Backend can serialize shared
data by putting the shared data into the data_store_output of the preprocess results.
This will record the shared data used by that specific partition.

Default implementation is running the existing preprocess implementation on all

Args:
    edge_programs: Dictionary mapping the method name to a list of all the partitioned
                   edge_programs from that method to be lowered.
    compile_specs: Dictionary mapping the method name to a list of compile_specs. The
                   list of compile specs maps directly to the list of edge_programs for the
                   same given method name i.e. edge_program[method_name][i] --> compile_specs[method_name][i]

Returns:
    Dictionary mapping the method name to a list of PreprocessResults. The list of
    PreprocessResults maps directly to the list of edge_programs for the same given
    method name. i.e. edge_program[method_name][i] --> result[method_name][i]


z!Error: missing compile specs for zError: method z has z partitions but only )itemslenzipr8   append)r/   r:   r5   preprocess_resultsmethod_nameprogramscompile_specs_for_methodresults_for_methodprogramcompile_spec_for_programpreprocess_results              r   preprocess_multimethod%BackendDetails.preprocess_multimethodh   s    8  %2%8%8%:!K,A2;-@A,'4'A$/0C5  v}E#h-@UVYZrVsUtuv  "$5861 %(NN7$U!"))*;<	6 /A{+ &;" "!r   r   )r   r   r   r    __doc__r+   staticmethodr   r   r   r   r   r   r8   classmethodr   r$   listrH   r%   __classcell__)r2   s   @r   r'   r'   4   s      %K( 
   
. -"Co!667-" Cd;&7!889-" 
c4())	*	-" -"r   r'   N)abcr   r   dataclassesr   typingr   r   r   r	   r
   r   ,executorch.exir._serialize._named_data_storer   +executorch.exir.backend.compile_spec_schemar   torch.export.exported_programr   r   r   r'   r   r   r   <module>rU      sM    $ ! : : M C 9
 . . ."b"S b"r   