
    [i"(                         d dl Z d dlZd dlZd dlZd dlZd dlmZ e j        d             Z	dddZ
ddddefd	Zd
 Z G d d          Zd ZdS )    N)TracebackTypec               #     K   	 d V  d S # t           $ r} | j        }g }|w|j        j        j        }|j        j                            d          }|dk    r!|t          j        ddd          5 }|	                    |           d d d            n# 1 swxY w Y   |j        }t          d|j        d          }|                    |j        j        	          }t          |j        d
          r+|                    |j        j        |j        j                  }t#          ||j        i |j        dt&          j        i          }t+          d ||j        |j                  }	|                    |	           n|                    |           |j        }|wd }
t5          |          D ]}|
|_        |}
|                     |
          d } ~ ww xY w)N__compile_source__z<string>wFz.py)modedeletesuffixz__inspect_currentframe()eval)co_nameco_linetable)r   co_firstlineno__inspect_currentframe)	Exception__traceback__tb_framef_codeco_filename	f_globalsgettempfileNamedTemporaryFilewritecompilenamereplacer   hasattrr   r   r
   f_localsinspectcurrentframer   tb_lasti	tb_linenoappendtb_nextreversedwith_traceback)exctbstackfilenamesourcefframecode
fake_framefake_tbr#   s              I/var/www/icac/venv/lib/python3.11/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr1   0   s<     P* N* N* N* n{)5H[*../CDDF:%%&*<2 0U5   $GGFOOO$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 9166JJ||EL,@|AA5<88   <<%*\%>',|'B (  D "OVu~V'?AUVV 

 (j"+r|TTW%%%%R   BA nF 5// 	 	B BJGG  )))]N*s:   
 GAG
2BG
B	G
B	D.G

Gbasec                $   |At           j                            t           j                            t                              }	 t           j                            | |g          }| t          |          dz   d         S # t          $ r | cY S w xY w)ziShorten a source filepath, with the assumption that torch/ subdirectories don't need to be shown to user.N   )ospathdirname__file__
commonpathlen
ValueError)fnr3   prefixs      r0   shorten_filenamer?      s    |wrwx8899%##RJ// #f++/##$$    			s   !B   BBF)r3   linereturnc                r    d}|r
| j          d}| t          | j        |           d| j         d| j         S )z
    Format a FrameSummary in a short way, without printing full absolute path or code.

    The idea is the result fits on a single line.
     z  # r2   :z in )r@   r?   r)   linenor   )r,   r3   r@   
extra_lines       r0   format_framerG      sX     J )
(((
f*5>EEEffffZ_Zdfff    c                 P    t          t          j        |           d                   S )zJFormat a TracebackType in a short way, printing only the inner-most frame.)rG   	traceback
extract_tbr'   s    r0   format_traceback_shortrN      s     	,R004555rH   c                   p    e Zd ZddgZdddZddZd Zd	 Zed
d
ddd            Z	d Z
ed             ZdS )CapturedTracebackr'   skipr   rA   Nc                 "    || _         || _        d S Nr'   rQ   )selfr'   rQ   s      r0   __init__zCapturedTraceback.__init__   s    			rH   c                     d | _         d S rS   rM   rU   s    r0   cleanupzCapturedTraceback.cleanup   s    rH   c                     dd l }| j        t          j                    S t	          |j        j                            | j        g          d         | j                  S )Nr   )	torch._C._profilerr'   rK   StackSummary_extract_symbolized_tb_C	_profilersymbolize_tracebacksrQ   )rU   torchs     r0   summaryzCapturedTraceback.summary   sY    !!!!7?)+++%H33TWI>>qA49
 
 	
rH   c                     d d | j         dfS )NrT   )rQ   rX   s    r0   __getstate__zCapturedTraceback.__getstate__   s!    	 
 	
rH   F)scriptcpprQ   c                     ddl }| s|r|dk    rt          d          t          |j        j                            d| |          | s|rdn|dz             S )a  
        Like traceback.extract_stack(), but faster (approximately 20x faster); it
        is fast enough that you can unconditionally log stacks this way as part of
        normal execution.  It returns a torch._C._profiler.CapturedTraceback
        object that must be formatted specially with format_captured_tb.

        By default, this only reports Python backtraces (like extract_stack).  You
        can set the script/cpp kwargs to also turn on TorchScript/C++ trace
        reporting.
        r   Nzskip with script/cpp NYIT)pythonre   rf   r5   )r[   AssertionErrorrP   r^   r_   gather_traceback)re   rf   rQ   ra   s       r0   extractzCapturedTraceback.extract   s     	"!!! 	AS 	Aqyy$%?@@@ H//tFPS/TT ,3,AAD1H	
 
 	
rH   c                 N    t          j        |                                           S )al  
        Formats a single torch._C._profiler.CapturedTraceback into a list of
        strings equivalent to the output of traceback.format_list.  Note that if
        pass it CapturedTraceback with C++ traces,  it is better not to use this
        function and use the batch formatting API format_captured_tbs to amortize
        the cost of symbolization
        )rK   format_listrb   rX   s    r0   formatzCapturedTraceback.format   s     $T\\^^444rH   c                     ddl }g }g }t                     D ]L\  }}|j        |                    g            "|                    d           |                    |           M|j        j                             fd|D                        |D ]1}t          j         |         	                                          ||<   2|S )z_
        Bulk version of CapturedTraceback.format.  Returns a list of list of strings.
        r   Nc                 *    g | ]}|         j         S  rM   ).0itbss     r0   
<listcomp>z0CapturedTraceback.format_all.<locals>.<listcomp>   s    0Q0Q0QqQ0Q0Q0QrH   )
r[   	enumerater'   r"   r^   r_   r`   rK   rm   rb   )rt   ra   rsdelayed_idxsrs   r'   s   `     r0   
format_allzCapturedTraceback.format_all   s    
 	"!!! &(s^^ 	' 	'EAru}		"		$##A&&&&//0Q0Q0Q0QL0Q0Q0QRRR 	< 	<A)#a&..*:*:;;BqEE	rH   )r   )rA   N)__name__
__module____qualname__	__slots__rV   rY   rb   rd   staticmethodrk   rn   ry   rq   rH   r0   rP   rP      s        vI       	
 	
 	

 
 
 U 
 
 
 
 \
05 5 5   \  rH   rP   c           	          t          j                    }t          | |d                   D ]=}|                    t          j        |d         |d         |d                              >|S )z
    Given a symbolized traceback from symbolize_tracebacks, return a StackSummary object of
    pre-processed stack trace entries.
    Nr)   r@   r   )rK   r\   r$   r"   FrameSummary)r'   rQ   r(   r+   s       r0   r]   r]      sh    
 "$$Ebi   R RY+AjM1V9aiPPQQQQLrH   )
contextlibr   os.pathr6   r   rK   typesr   contextmanagerr1   r?   strrG   rN   rP   r]   rq   rH   r0   <module>r      s                   R Q* Q* Q*h "& 
% 
% 
% 
% 
% !%5 	g 	g 	gS 	g 	g 	g 	g6 6 6
V V V V V V V Vr    rH   