
    #Ki/                         S SK r S SKrS SKJr  S SKrS SKrS SKJrJrJ	r	J
r
Jr  S SKJrJrJrJrJrJr  S/r\" SSS9 " S S5      5       rS	 rg)
    N)
deprecated)_disable_profiler_legacy_enable_profiler_legacy
DeviceTypeProfilerConfigProfilerState)_filter_name_filter_stack_entry_rewrite_name	EventListFunctionEventMEMORY_EVENT_NAMEprofilez`torch.autograd.profiler_legacy.profile` is deprecated and will be removed in a future release. Please use `torch.profiler` instead.)categoryc                      \ rS rSrSr SSSSSSSS.S jjrS rS rS rS	 r	S
 r
S rS r       SS jr\R                  R                  \l        S r\R                  R                  \l        SS\S\4S jjrSS jr\R$                  R                  \l        S r\R&                  R                  \l        \S 5       rSrg)r      z'DEPRECATED: use torch.profiler instead.F)use_cudarecord_shapes
with_flopsprofile_memory
with_stackwith_modulesc                   Xl         U R                   (       d  g X l        S U l        SU l        X0l        X@l        U =R                  U R
                  -  sl        XPl        X`l        Xpl        U R                  (       a?  [        R                  R                  5       (       d  [        R                  " SSS9  SU l        U R                  (       a  [        R                  U l        g [        R"                  U l        g )NFz/CUDA is not available, disabling CUDA profiling   )
stacklevel)enabledr   function_eventsenteredr   r   r   r   r   torchcudais_availablewarningswarnr   CUDAprofiler_kindCPU)selfr   r   r   r   r   r   r   s           `/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/torch/autograd/profiler_legacy.py__init__profile.__init__$   s     %|| #*$doo-,$(==!8!8!:!:MMA "DM==!.!3!3D!.!2!2D    c           
          [        U R                  U R                  U R                  U R                  U R
                  U R                  [        R                  R                  R                  5       5      $ N)r   r%   r   r   r   r   r   r   _C	_profiler_ExperimentalConfigr'   s    r(   configprofile.configH   sW    OOOOHH224	
 		
r+   c                     U R                   (       d  g U R                  (       a  [        S5      eSU l        U R                  5         U $ )Nz)Profiler context manager is not reentrantT)r   r   RuntimeError_start_tracer1   s    r(   	__enter__profile.__enter__T   s7    ||<<JKKr+   c                 6    [        U R                  5       5        g r-   )r   r2   r1   s    r(   r6   profile._start_trace]   s    .r+   c                 T   U R                   (       d  g U R                  (       a  [        R                  R	                  5         [        5       n[        U5      n[        UU R                  (       a  SOS U R                  U R                  S9U l
        U R                  R                  5         g)Nr    )
use_devicer   r   F)r   r   r   r    synchronizer   _parse_legacy_recordsr   r   r   r   _build_tree)r'   exc_typeexc_valexc_tbrecordsparsed_resultss         r(   __exit__profile.__exit__`   sw    ||==JJ""$*,.w7(!%vD..	 
 	((*r+   c                 H    U R                   c  g[        U R                   5      $ )Nz$<unfinished profiler_legacy.profile>)r   reprr1   s    r(   __repr__profile.__repr__s   s"    '9D(())r+   c                 H    U R                   c  g[        U R                   5      $ )Nz,<unfinished profile.profiler_legacy.profile>)r   strr1   s    r(   __str__profile.__str__x   s"    'A4''((r+   c                 4    U R                   c  [        S5      eg )NzProfiler didn't finish running)r   r5   r1   s    r(   _check_finishprofile._check_finish}   s    '?@@ (r+   Nc           
          U R                  5         U R                  c  [        S5      eU R                  R                  UUUUUUUS9$ )NExpected profiling results)sort_by	row_limitmax_src_column_widthmax_name_column_widthmax_shapes_column_widthheadertop_level_events_only)rP   r   AssertionErrortable)r'   rT   rU   rV   rW   rX   rY   rZ   s           r(   r\   profile.table   s[     	' !=>>##))!5"7$;"7 * 
 	
r+   c                     U R                  5         U R                  c  [        S5      eU R                  R                  U5      $ NrS   )rP   r   r[   export_chrome_trace)r'   paths     r(   r`   profile.export_chrome_trace   s=    ' !=>>##77==r+   ra   metricc                     U R                  5         U R                  c  [        S5      eU R                  (       d  [        S5      eU R                  R	                  X5      $ )NrS   z(export_stacks() requires with_stack=True)rP   r   r[   r   export_stacks)r'   ra   rc   s      r(   re   profile.export_stacks   sP    ' !=>> !KLL##11$??r+   c                     U R                  5         U R                  c  [        S5      eU R                  R                  X5      $ r_   )rP   r   r[   key_averages)r'   group_by_input_shapegroup_by_stack_ns      r(   rh   profile.key_averages   s>    ' !=>>##001EXXr+   c                     U R                  5         U R                  c  [        S5      eU R                  R                  5       $ r_   )rP   r   r[   total_averager1   s    r(   rm   profile.total_average   s;    ' !=>>##1133r+   c                 ~    U R                  5         U R                  c  [        S5      eU R                  R                  $ )z;Return CPU time as the sum of self times across all events.rS   )rP   r   r[   self_cpu_time_totalr1   s    r(   rp   profile.self_cpu_time_total   s:     	' !=>>##777r+   )
r   r   r   r   r%   r   r   r   r   r   )T)Nd   K   7   P   NF)rp   )Fr   )__name__
__module____qualname____firstlineno____doc__r)   r2   r7   r6   rE   rI   rM   rP   r\   r   r`   rL   re   rh   rm   propertyrp   __static_attributes__ r+   r(   r   r      s     2 "3 "3H

/&*
)
A   "#
. OO++EM> #,"?"?"G"G@# @s @Y %1199L4 &33;;M8 8r+   c                 	   S nS n/ n[         R                  R                  U 5       H"  nUR                  5       nUb  M  US:X  d  M   UnM$     Ub  UR	                  5       (       a  [        S5      eU  GH2  n0 n0 n0 n	[        5       n
S nU GH  nU" U5      n[        UR                  5       5      (       d  X;   a  U
R                  U5        MB  UR                  5       S:X  a  Ub  UR                  5       UR                  5       :H  =(       aI    UR                  5       UR                  5       :H  =(       a!    UR                  5       UR                  5       :H  nU(       a  U
R                  U5        M  XIU'   SX|'   SX'   GO!UR                  5       S:X  Ga9  X;  a  [        SU S35      eX   nX|   nX   nUR                  5       =(       d!    UR                  5       UR                  5       :g  nUR	                  5       nUR                  5       n[        S(0 S	UR                  5       _S
UR                  5       _S[!        UR                  5       SS9_S[!        UR                  5       SS9_SUR                  5       _SUR#                  U5      _SUR#                  U5      _SUR%                  5       _SUR'                  5       _SUR)                  5        Vs/ s H  n[+        U5      (       d  M  UPM     sn_SUR-                  5       _SUR/                  5       (       a  SOS _SU_SU_SU_SU_SUR1                  5       _S[2        R4                  _SS_S U_6nU(       d[  UR/                  5       (       aF  UR7                  U5      nUS:  a/  UR9                  UR                  5       UR;                  5       U5        UR=                  U5        X	 X|	 X	 OUR                  5       S!:X  a  [?        U5      n[?        U5      nUU:w  a  [        S"U S#U S$35      eU H  nUU==   URA                  5       -  ss'   M      U H  nUU==   URC                  5       -  ss'   M      US:X  aC  [        S[D        S SSS/ URA                  5       URC                  5       SS%9
nUR=                  U5        UnGM     GM5     URG                  S& S'9  U$ s  snf ))Nc                 B    U R                  5       U R                  5       4$ )zPReturn a tuple for correlating start and end records in `_parse_legacy_records`.)handlenode_id)records    r(   _get_record_key._parse_legacy_records.<locals>._get_record_key   s    !122r+   __start_profilez#Expected a valid local start_recordpushr   popzExpected record with key z[ to exist in range_starts. This means that the pop event did not have a corresponding push.idr   nameT)r   with_wildcard
trace_nameFthreadstart_usend_us
fwd_threadinput_shapesstackscoper<   r    cpu_memory_usagedevice_memory_usageis_async	is_remotesequence_nrdevice_type	is_legacyflopsmemory_alloczBExpected CPU and CUDA memory allocation handles to match, but got z	 CPU and z CUDA)
r   r   r   r   r   r   r   r   r   r   c                 \    U R                   R                  U R                   R                  * /$ r-   )
time_rangestartend)evts    r(   <lambda>'_parse_legacy_records.<locals>.<lambda>F  s     CNN$8$83>>;M;M:M#Nr+   )keyr}   )$	itertoolschainfrom_iterabler   r   r[   setr	   addkindr   r   	thread_idr   r   r   r   cpu_elapsed_usfwd_thread_idshapesr   r
   r   has_cudar   r   r&   cuda_elapsed_usappend_kerneldeviceappendlenr   cuda_memory_usager   sort)thread_recordsr   start_record	functionsr   r   thread_record_listcpu_memory_allocscuda_memory_allocsrange_startsfiltered_handlesprev_record
record_key	duplicater   r   r   r   is_remote_eventstart_flopsentryfedurationnum_open_handles_cpunum_open_handles_cudar   s                             r(   r>   r>      s   3 LI ////?{{}D,=$=!L @
 |5577BCC,5(F(0JFKKM**j.L $$Z0{{}& *#((*fkkm; F',,.&++-?F'//1V^^5EE 
 !(,,Z8 +1Z(01!-12".%'1(3J< @[ [ 
 %0#4#@ $6$B! >>+X0AVEUEUEW0W"("2"2"4#kkm" }}"NN, 'EJJLM  -%**,eT	
 !??, *88? (66v>  %224 "' ,1;;=+8%<OPU<V=  ++- */)9)9vt &6  ):!" &#$ .%& !& 1 1 3'( !+)* #+, &-2  ENN$4$4$44V<H!|((u||~xP  $ ,%1&2.0'*+<'=$(+,>(?%'+@@(##7"8	BWAXX]_  0F%f-1H1H1JJ- 00F&v.&2J2J2LL. 1'1,&.#' !"  )/)@)@)B,2,D,D,F"&B $$R( KC ) -d NNNNOws   R;&R;)r   r"   typing_extensionsr   r   
torch.cudatorch.autogradr   r   r   r   r   torch.autograd.profiler_utilr	   r
   r   r   r   r   __all__r   r>   r}   r+   r(   <module>r      sa      (     + +
_8 _8
_8DDr+   