
    i
                     P    S SK r S SKJrJr  S SKrS SKJr  S SKJr   " S S5      r	g)    N)AnyOptional)
TensorSpecc                      \ rS rSr% Sr\R                  \S'   \R                  \S'   S\R                  S\R                  SS4S jr	\
S\R                  R                  4S	 j5       rS
\R                  SS4S jrSS\\R                     S\R                  R"                  4S jjrSS\S\\   S\R                  4S jjrSrg)ExportGraph   z
ExportGraph serves as a layer between EXIR and FX Graph API.
It enforces EXIR-specific invariants (ex. having nodes contain specs)
owning_module_graphgraphreturnNc                     Xl         X l        g N)r	   r
   )selfr	   r   s      T/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/graph.py__init__ExportGraph.__init__   s    *    c                 .    U R                   R                  $ )z3
Get the list of Nodes that constitute this Graph.
)r
   nodes)r   s    r   r   ExportGraph.nodes   s    
 {{   r   to_erasec                 8    U R                   R                  U5      $ )zs
Erases a ``Node`` from the ``Graph``. Throws an exception if
there are still users of that node in the ``Graph``.
)r
   
erase_node)r   r   s     r   r   ExportGraph.erase_node%   s    
 {{%%h//r   nc                 8    U R                   R                  U5      $ )z3
Sets the point at which we will insert the graph.
)r
   inserting_before)r   r   s     r   r   ExportGraph.inserting_before,   s     {{++A..r   qualified_name	type_exprc                 (   U R                   R                  X5      nS[        R                  R                  S[
        S[        [        R                     4S jnU" U R                  U5      nUb$  [        R                  " US5      UR                  S'   U$ )z-
Inserts a ``get_attr`` node into the Graph.
modr   r   c                 j   UR                  S5      u  p#n U R                  U5      nXER
                  ;   a  UR
                  U   $ [        XT5      (       a6  [        XT5      n[        U[        R                  R                  5      (       a  U$ g ! [         a    [        R                  " SU S3SS9   g f = f)N.zFailed to fetch module !   )
stacklevel)
rpartitionget_submoduleAttributeErrorwarningswarn_buffershasattrgetattr
isinstancetorchnn	Parameter)r"   r   module_path_namesubmodattrs          r   _maybe_get_attr_value3ExportGraph.get_attr.<locals>._maybe_get_attr_value;   s     $2#<#<S#A KD*-*;*;K*H &t,, v$$v,dEHH$6$677K "  7}AFSTUs   B #B21B2Tspec)r
   get_attrr1   r2   Modulestrr   Tensorr	   r   from_tensormeta)r   r   r    noder9   buffers         r   r<   ExportGraph.get_attr3   s     {{##N>		25	ell#	. 't'9'9>J * 6 6vt DDIIfr   )r
   r	   r   )__name__
__module____qualname____firstlineno____doc__fxGraphModule__annotations__Graphr   propertyr   
_node_listr   Noder   r   _InsertPointr   r>   r   r<   __static_attributes__ r   r   r   r      s    
 >>!HHbnn RXX $  !rxx** ! !0277 0t 0/(277"3 /rxx?T?T /#s #x} #PRPWPW # #r   r   )
r+   typingr   r   r1   torch.fxrJ   executorch.exir.tensorr   r   rS   r   r   <module>rW      s"         -E Er   