
    Χg?(                         d dl mZ d dlmZmZ d dlZd dlZd dlZd dlZd dl	Z
ej        d             ZdddZdddd	Zd
 Z G d d          Zd ZdS )    )TracebackType)ListOptionalNc               #     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              R/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr3   /   sF     S* Q* Q* Q* n{)5H[*../CDDF:%%&*<2 0c%PUVVV $Z[GGFOOO$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 9166JJ||EL,@|AA5<88   <<%*\%>',|'B (  D "O.0'2F  
 (*bk2<  W%%%%R   BG nL 5// 	 	B BJGG  )))cQ*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)fnr5   prefixs      r2   shorten_filenamerA      s    |wrwx8899$##RJ// #f++/""##    			s   !B   BBF)r5   linec                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  # r4   :z in )rB   rA   r+   linenor   )r.   r5   rB   
extra_lines       r2   format_framerH      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.)rH   	traceback
extract_tbr)   s    r2   format_traceback_shortrO      s     	,R004555rI   c                   l    e Zd ZddgZddZd Zd Zd Zedddd	d
            Z	d Z
ed             ZdS )CapturedTracebackr)   skipr   c                 "    || _         || _        d S Nr)   rR   )selfr)   rR   s      r2   __init__zCapturedTraceback.__init__   s    			rI   c                     d | _         d S rT   rN   rV   s    r2   cleanupzCapturedTraceback.cleanup   s    rI   c                     dd l }| j        t          j                    S t	          |j        j                            | j        g          d         | j                  S )Nr   )	torch._C._profilerr)   rL   StackSummary_extract_symbolized_tb_C	_profilersymbolize_tracebacksrR   )rV   torchs     r2   summaryzCapturedTraceback.summary   sZ    !!!!7?)+++%H33TWI>>qAI
 
 	
rI   c                     d d | j         dfS )NrU   )rR   rY   s    r2   __getstate__zCapturedTraceback.__getstate__   s!    I
 
  	rI   F)scriptcpprR   c                     ddl }| s|r|dk    s
J 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)pythonrf   rg   r7   )r\   rQ   r_   r`   gather_traceback)rf   rg   rR   rb   s       r2   extractzCapturedTraceback.extract   sz     	"!!! 	9S 	919998999 H//tFPS/TT ,3,AAD1H	
 
 	
rI   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
        )rL   format_listrc   rY   s    r2   formatzCapturedTraceback.format   s     $T\\^^444rI   c                     ddl }g }g }t                     D ]L\  }}|j        |                    g            "|                    d           |                    |           M|j        j                             fd|D                       }t          ||          D ]4\  }}t          j	         |         
                                          ||<   5|S )z_
        Bulk version of CapturedTraceback.format.  Returns a list of list of strings.
        r   Nc                 *    g | ]}|         j         S  rN   ).0itbss     r2   
<listcomp>z0CapturedTraceback.format_all.<locals>.<listcomp>   s    7X7X7XaA	7X7X7XrI   )r\   	enumerater)   r$   r_   r`   ra   ziprL   rm   rc   )rt   rb   rsdelayed_idxsrs   r)   stbsstbs   `       r2   
format_allzCapturedTraceback.format_all   s    
 	"!!! )+s^^ 	' 	'EAru}		"		$##A&&&&x!667X7X7X7X<7X7X7XYY,-- 	< 	<FAs)#a&..*:*:;;BqEE	rI   N)r   )__name__
__module____qualname__	__slots__rW   rZ   rc   re   staticmethodrk   rn   r|   rq   rI   r2   rQ   rQ      s        vI     

 

 

   U 
 
 
 
 \
.5 5 5   \  rI   rQ   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+   rB   r   )rL   r]   r&   r$   FrameSummary)r)   rR   r*   r-   s       r2   r^   r^      sh    
 "$$Ebi   R RY+AjM1V9aiPPQQQQLrI   )typesr   typingr   r   r   rL   
contextlibr    os.pathr8   contextmanagerr3   rA   rH   rO   rQ   r^   rq   rI   r2   <module>r      s"         ! ! ! ! ! ! ! !           N T* T* T*l "& 
$ 
$ 
$ 
$ 
$ !%5 	g 	g 	g 	g 	g6 6 6S S S S S S S Sl    rI   