a
    h                     @   sf   d dl Z d dlmZ d dlZd dlmZ dddZdd Zejj	ee
 dd	d
ZdedddZdS )    N)Optional)
LazyStringc                    sl   fdd dvrdd< dv rXzt j s:dd< W n tyV   dd< Y n0 t fddS )z;
    Returns a LazyString that formats the graph code.
    c                      s    d ur d  S S d S )N  r   )maybe_idnamer   =/var/www/auris/lib/python3.9/site-packages/torch/fx/_utils.pyformat_name   s    z+lazy_format_graph_code.<locals>.format_nameZprint_outputFZcoloredc                      s(   t d   djjjjf i S )Nz===== z =====
)_format_graph_codeZforward__code__co_filenameZprint_readabler   )r	   gmkwargsr   r   <lambda>   s   z(lazy_format_graph_code.<locals>.<lambda>)sysstdoutisattyAttributeErrorr   )r   r   r   r   r   )r	   r   r   r   r   r   lazy_format_graph_code	   s    
r   c                 C   s   d|  d| d| dS )z7
    Returns a string that formats the graph code.
    zTRACED GRAPH
 r   
r   )r   filenameZ	graph_strr   r   r   r
   '   s    r
   )graphreturnc                 C   s2   | j D ]&}|jdkrd|jv r|jd   S qdS )zF
    Returns the nn_module_stack of the first call_function node.
    call_functionZnn_module_stackN)nodesopmeta)r   noder   r   r   #first_call_function_nn_module_stack.   s    
r      )r   c                 C   sL   g }| }t |D ]&}||  |jdkr0 q8|j}qd|ddd S )zD
    Returns a string of the last num_nodes nodes in the graph.
    rootr   N)rangeappendZformat_noder   prevjoin)r   Z	num_nodesZnode_contextscur_r   r   r   get_node_context8   s    
r(   )N)r   )r   typingr   ZtorchZtorch._loggingr   r   r
   ZfxZGraphdictr   strr(   r   r   r   r   <module>   s   

