
    i                        S SK r S SKJr  S SK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KJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr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r$\ RJ                  " \&5      r'\'RQ                  \ RR                  5        \ " S S5      5       r*S\#S\RV                  RX                  S\\RV                  RZ                  \*4   4S jr.S\RV                  RX                  SS4S jr/\ " S S\5      5       r0g)    N)	dataclass)DictfinalList)XNNPACKPassManager)ConvertToLinearPass)get_node_visitors)ConstantDataOffsetXNNGraph)serialize_xnnpack_binary)get_xnnpack_edge_compile_config)is_param_node)XNN_VALUE_FLAG_EXTERNAL_INPUTXNN_VALUE_FLAG_EXTERNAL_OUTPUT)NamedDataStore)BackendDetailsCompileSpecPreprocessResult)EXIREdgeDialectVerifier)ExportedProgrami  c                   *    \ rS rSr% \\S'   \\S'   Srg)ExternalMeta/   external_idio_type N)__name__
__module____qualname____firstlineno__int__annotations____static_attributes__r       m/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/xnnpack/xnnpack_preprocess.pyr   r   /   s    Lr$   r   exported_programedge_graph_modulereturnc                    0 nUR                   R                   H@  nUR                  S:X  d  M  [        X5      (       a  M'  [	        [        U5      [        S9X#'   MB     UR                   R                   H^  nUR                  S:X  d  M  UR                   H9  nU H0  nXR;   a  [        SU S35      e[	        [        U5      [        S9X%'   M2     M;     M`     U$ )Nplaceholder)r   r   outputzOutput node 'zv' is already in the inputs. This is likely due to pass through arguments, which are not supported in XNNPACK Delegate.)
graphnodesopr   r   lenr   argsRuntimeErrorr   )r&   r'   node_to_external_mapnodeoutput_nodesoutput_nodes         r%   generate_node_to_external_mapr6   5   s     !''-- 77m#M:J,Q,Q)5 455* & . "''--77h $		#/K":*+K= 9y y  9E$'(<$= >9(5 $0 !* .  r$   c           
         U R                   R                   H  nUR                  S:w  a  M  UR                  R	                  SS 5      nUc  M6  [        USS 5      c  MF  [        [        UR                  5       5      5      nUR                  5       U:w  d  M~  [        SU SUR                  S   R                  5        SU S35      e   g )Nr*   val	dim_orderzWXNNPACK backend only supports contiguous memory format for inputs.Expecting dim_order: z
, but got z for a placeholder node .)r,   r-   r.   metagetgetattrtuplerangedimr9   r1   )r'   r3   tdefault_dim_orders       r%   assert_default_dim_orderrC   V   s    !''--77m# IIMM%&=WQT:F %eAEEGn 5{{} 11",,=+>jSXIYIcIcIeHff~  @D  E  EFG  .r$   c                   :    \ rS rSr\S\S\\   S\4S j5       r	Sr
g)XnnpackBackendf   edge_programcompile_specsr(   c                    [        5       n[        5       n[        U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  [        USS9/S9	n/ nU H*  nUR                  S:X  d  M  UR                  [        5        M,     [        U5      S:  a  UOS n[!        XES9R#                  5       nUR                  n[%        XG5      n0 n	['        S/ / [        U5      / / [)        SS5      /S9n
[+        5       n[-        XHU5      nUR                  R.                   GH  nUR0                  S	:X  a  [2        R5                  S
U SUR6                  R8                   35        UR6                  R8                  U;   aJ  XR6                  R8                     R;                  UU
U	UR<                  R?                  S[@        5      5        M  [C        SU SUR0                   SUR6                  R8                   S35      eUR0                  S;   a  M  [C        UR0                   S35      e   [E        [G        X5      0 URI                  5       S9$ )NT)edge_compile_config
class_only)	rootr,   graph_signature
state_dictrange_constraintsmodule_call_graphexample_inputs	constants	verifiersdqlinear_partitionerr   )passes0)versionxnodesxvaluesnum_externs	input_ids
output_idsconstant_datacall_functionz
Visiting: z, debug_handlezFor :z% is not supported in XNNPACK Delegate)get_attrr*   r+   z is not supported in XNNPACK)processed_bytesdebug_handle_mapdata_store_output)%r   r   r   graph_moduler,   rM   rN   rO   rP   rQ   rR   r   keyappendr   r/   r   	transformr6   r   r
   	bytearrayr	   r-   r.   loggerinfotargetr   define_noder;   r<   DEFAULT_DEBUG_HANDLEr1   r   r   get_named_data_store_output)rG   rH   named_data_storexnnpack_edge_compile_configeprU   specre   r2   vals_to_idsxnnpack_graphconstant_data_bytesnode_visitorsr3   s                 r%   
preprocessXnnpackBackend.preprocessh   sO   
 *+&E&G# **$$(88#..*<<*<<'66",,'(CPT
  !Dxx1112 " v;?2<<><RN
  01-a34
 (k)"DTU &&,,Dww/)jb1E1E0FGH;;''=8!++"6"67CC%#		n6JK	 'tfBtwwiq1E1E0FFkl    
 "dggY.J#KLL+ -,  4  .JJL
 	
r$   r   N)r   r   r   r    staticmethodr   r   r   r   rx   r#   r   r$   r%   rE   rE   f   s8    Y
%Y
K(Y
 
Y
 Y
r$   rE   )1loggingdataclassesr   typingr   r   r   torch#executorch.backends.xnnpack._passesr   5executorch.backends.xnnpack._passes.convert_to_linearr   2executorch.backends.xnnpack.operators.node_visitorr	   >executorch.backends.xnnpack.serialization.xnnpack_graph_schemar
   r   Aexecutorch.backends.xnnpack.serialization.xnnpack_graph_serializer   )executorch.backends.xnnpack.utils.configsr   'executorch.backends.xnnpack.utils.utilsr   3executorch.backends.xnnpack.utils.xnnpack_constantsr   r   ,executorch.exir._serialize._named_data_storer   'executorch.exir.backend.backend_detailsr   r   r   %executorch.exir.verification.verifierr   torch.export.exported_programr   rn   	getLoggerr   rj   setLevelWARNINGr   fxGraphModuleNoder6   rC   rE   r   r$   r%   <module>r      s    ! $ $  B U P V A H 
 J 9 			8	$      
 % xx++  
%((--
%& B0D0D    [
^ [
 [
r$   