L i(ddlZddlZddlZddlZddlZddlmZddlm Z ejdZ dddZ dddd Z d ZGd d Zd Zy)N) TracebackType)Optionalc#K dy#t$r}|j}g}||jjj}|jj j d}|dk(rE|Btjddd5}|j|dddn #1swYnxYw|j}tdjd}|j|jj }t|jd r;|j|jj|jj }t#||j i|j$d t&j(i}t+d||j,|j.} |j1| n|j1||j2}|d} t5|D] }| |_|} |j7| d}~wwxYww) N__compile_source__zwFz.py)modedeletesuffixz__inspect_currentframe()eval)co_name co_linetable)r co_firstlineno__inspect_currentframe) Exception __traceback__tb_framef_code co_filename f_globalsgettempfileNamedTemporaryFilewritecompilenamereplacer hasattrr rr f_localsinspect currentframertb_lasti tb_linenoappendtb_nextreversedwith_traceback) exctbstackfilenamesourcefframecode fake_framefake_tbr$s \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr21sP* N*   n{{))55H[[**../CDF:%&*<200U5$GGFO$$$  91666J||ELL,@,@|A5<<8 <<%*\\%>%>',||'B'B(D"OOVu~~V'?AUAUV (j"++r||T W% R BAnF5/ B BJG   ))]N*sDH  H  HA7H B% H%B. *D)H,HHH basec|@tjjtjjt} tjj ||g}|t |dzdS#t $r|cYSwxYw)ziShorten a source filepath, with the assumption that torch/ subdirectories don't need to be shown to user.N)ospathdirname__file__ commonpathlen ValueError)fnr4prefixs r1shorten_filenamer@sq |wwrwwx89%##RJ/#f+/#$$  s!A66 BBF)r4linecd}|r|jd}|t|j|d|jd|jS)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 # r3:z in )rAr@r*linenor)r-r4rA extra_lines r1 format_framerGsQ J  |4( \*5>>EFa ~UYZ_ZdZdYe ffcDttj|dS)zJFormat a TracebackType in a short way, printing only the inner-most frame.)rG traceback extract_tbr(s r1format_traceback_shortrNs  ,,R04 55rHc^eZdZddgZddZdZdZdZedddd d Z d Z ed Z y )CapturedTracebackr(skiprc ||_||_yNr(rQ)selfr(rQs r1__init__zCapturedTraceback.__init__s rHcd|_yrSrMrUs r1cleanupzCapturedTraceback.cleanups rHcddl}|jtjSt |j j j|jgd|jS)Nr) torch._C._profilerr(rK StackSummary_extract_symbolized_tb_C _profilersymbolize_tracebacksrQ)rUtorchs r1summaryzCapturedTraceback.summarysS! 77?))+ +% HH   3 3TWWI >q A499  rHc$dd|jdfS)NrT)rQrXs r1 __getstate__zCapturedTraceback.__getstate__s     rHF)scriptcpprQcddl}|s|r |dk(sJdt|jjj d|||s|rdS|dzS)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. rNzskip with script/cpp NYIT)pythonrerfr6)r[rPr^r_gather_traceback)rerfrQras r1extractzCapturedTraceback.extractsg " S19 88 89 HH   / /tFPS / T3A   %)1H   rHcHtj|jS)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_listrbrXs r1formatzCapturedTraceback.formats$$T\\^44rHcddl}g}g}t|D]E\}}|j|jg$|jd|j|G|jj j |Dcgc]}||jc}|D]+}tj||j||<-|Scc}w)z_ Bulk version of CapturedTraceback.format. Returns a list of list of strings. rN) r[ enumerater(r#r^r_r`rKrlrb)tbsrars delayed_idxsir(s r1 format_allzCapturedTraceback.format_alls ")+ s^ 'EAruu} "  $##A&  ' //L0QqQ0QR rsfR Q*Q*h"& %!%5 g6 UUprH