
    Vh                         d dl Z d dlmZ d dlZd dlmZ d
dZd Zdej                  j                  dee
   fdZddefd	Zy)    N)Optional)
LazyStringc                       fddvrdd<   dv r$	 t         j                  j                         sdd<   t	        fd      S # t        $ r dd<   Y  w xY w)z;
    Returns a LazyString that formats the graph code.
    c                        d  S S )N  )maybe_idnames   ?/home/dcms/DCMS/lib/python3.12/site-packages/torch/fx/_utils.pyformat_namez+lazy_format_graph_code.<locals>.format_name   s    V1XJ''K    print_outputFcoloredc            	          t        d          dj                  j                  j                   j                  di       S )Nz===== z =====
r   )_format_graph_codeforward__code__co_filenameprint_readable)r   gmkwargss   r   <lambda>z(lazy_format_graph_code.<locals>.<lambda>   sA    "[]O8,JJ++B''
 r   )sysstdoutisattyAttributeErrorr   )r
   r   r	   r   r   s   ````@r   lazy_format_graph_coder   	   sr    
 V#!&~F	&::$$&$)y! 	
   	& %F9	&s   #A AAc                     d|  d| d| dS )z7
    Returns a string that formats the graph code.
    zTRACED GRAPH
 r   
r   )r
   filename	graph_strs      r   r   r   '   s     TF!H:Qyk<<r   graphreturnc                     | j                   D ]1  }|j                  dk(  sd|j                  v s"|j                  d   c S  y)zF
    Returns the nn_module_stack of the first call_function node.
    call_functionnn_module_stackN)nodesopmeta)r"   nodes     r   #first_call_function_nn_module_stackr+   .   sD      077o%*;tyy*H99.//0 r   c                     g }| }t        |      D ]>  }|j                  |j                                |j                  dk(  r n|j                  }@ dj                  |ddd         S )zD
    Returns a string of the last num_nodes nodes in the graph.
    rootr   N)rangeappendformat_noder(   prevjoin)r*   	num_nodesnode_contextscur_s        r   get_node_contextr8   8   si     M
C9 S__./66Vhh	
 99]4R4())r   )N)   )r   typingr   torchtorch._loggingr   r   r   fxGraphdictr+   strr8   r   r   r   <module>rA      sF    
   %<=uxx~~ (4. *3 *r   