ó
    "Eñio¾  ã                   ó4  • S SK r S SKrS SKrS SKrS SKrS SKJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJrJr  S SKJrJr  S SKJr  S SKrS SKJs  Jr  S S	KJr  S S
KJrJ r J!r!J"r"J#r#  S SK$J%r%  S SK&J'r'  S SK(J)r)J*r*  S SK+J,r,J-r-  / SQr.Sr/\0" 5       r1\2S4S jr3 " S S\Rh                  5      r5S r6 " S S\5      r7 " S S5      r8 " S S\5      r9S S S S.S\:S\:S\:S \:S!\:S"\:S#\	4S$ jjr;S%\:S#\94S& jr< S/S'\=S(\=S-  S)\>4S* jjr? " S+ S,\85      r@ " S- S.\75      rAg)0é    N)ÚABCÚabstractmethod)ÚCallableÚIterable)ÚEnum)Úpartial)ÚAnyÚOptional)Ú
deprecatedÚSelf)Úwarn)Ú_get_privateuse1_backend_name)Ú_add_execution_trace_observerÚ!_disable_execution_trace_observerÚ _enable_execution_trace_observerÚ_ExperimentalConfigÚ _remove_execution_trace_observer)Ú	is_fbcode)Ú1profiler_allow_cudagraph_cupti_lazy_reinit_cuda12)Úkineto_availableÚProfilerActivity)ÚMemoryProfileÚMemoryProfileTimeline)Úsupported_activitiesÚProfilerActionÚscheduleÚtensorboard_trace_handlerÚprofileÚExecutionTraceObserverÚProfilerStepé   c                 óX   • U [         ;  a   [         R                  U 5        [        XUS9  g g )N)ÚcategoryÚ
stacklevel)Ú_WARNINGS_SHOWNÚaddr   )Úmsgr#   r$   s      ÚT/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/profiler/profiler.pyÚ
_warn_oncer)   ,   s'   € Ø
”/Ó!Ü×Ñ˜CÔ ÜˆS°
Ó;ð "ó    c                   ó   • \ rS rSrSrS rSrg)Ú_NumpyEncoderé2   zr
Json encoder for numpy types (np.int, np.float, np.array etc.)
Returns default encoder if numpy is not available
c                 ó�  •  SSK n[        XR                  5      (       a  [        U5      $ [        XR                  5      (       a  [        U5      $ [        XR                  5      (       a  UR                  5       $ [        R                  R	                  X5      $ ! [         a"    [        R                  R	                  X5      s $ f = f)zEncode NumPy types to JSONr   N)ÚnumpyÚImportErrorÚjsonÚJSONEncoderÚdefaultÚ
isinstanceÚintegerÚintÚfloatingÚfloatÚndarrayÚtolist)ÚselfÚobjÚnps      r(   r3   Ú_NumpyEncoder.default8   s—   € ð	7Ûô �cŸ:™:×&Ñ&Ü�s“8ˆOÜ˜Ÿ[™[×)Ñ)Ü˜“:ÐÜ˜ŸZ™Z×(Ñ(Ø—:‘:“<Ðä×#Ñ#×+Ñ+¨DÓ6Ð6øô ó 	7Ü×#Ñ#×+Ñ+¨DÓ6Ò6ð	7ús   ‚B Â)CÃC© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r3   Ú__static_attributes__r?   r*   r(   r,   r,   2   s   † ñõ
7r*   r,   c                  ó>   • [         R                  R                  5       $ )a°  
Returns a set of supported profiler tracing activities.

Note: profiler uses CUPTI library to trace on-device CUDA kernels.
In case when CUDA is enabled but CUPTI is not available, passing
``ProfilerActivity.CUDA`` to profiler results in using the legacy CUDA
profiling code (same as in the legacy ``torch.autograd.profiler``).
This, in turn, results in including CUDA time in the profiler table output,
but not in the JSON trace.
)ÚtorchÚautogradÚ_supported_activitiesr?   r*   r(   r   r   H   s   € ô �>‰>×/Ñ/Ó1Ð1r*   c                   óH   • \ rS rSrSr\S 5       r\S 5       r\S 5       rSr	g)Ú_ITraceObserveréV   zZAbstract interface for a Trace observer.
This satisfies 3 methods: start, stop and cleanupc                 ó   • g ©Nr?   ©r;   s    r(   ÚstartÚ_ITraceObserver.startZ   ó   € àr*   c                 ó   • g rN   r?   rO   s    r(   ÚstopÚ_ITraceObserver.stop^   rR   r*   c                 ó   • g rN   r?   rO   s    r(   ÚcleanupÚ_ITraceObserver.cleanupb   rR   r*   r?   N)
r@   rA   rB   rC   rD   r   rP   rT   rW   rE   r?   r*   r(   rK   rK   V   sC   † ñ9ð ñó ðð ñó ðð ñó ór*   rK   c                   ó¾  • \ rS rSrSrSSSSSSSSSSSS.S\\   S-  S\S\S	\S
\S\S\S-  S\	S-  S\S\
/ \4   S-  S\S-  SS4S jjrS/S jrS/S jrS/S jrS/S jrS/S jrS\4S jrS0S\S\4S jjrS\S\\   SS4S jr   S1S\S\S \4S! jjrS" rS#\S$\SS4S% jrS#\S$\SS4S& jrS#\S$\SS4S' jrS( rS\4S) jr\" S*\ S+9S2S\S,\S-  SS4S- jj5       r!S.r"g)3Ú_KinetoProfileég   aw
  Low-level profiler wrap the autograd profile

Args:
    activities (iterable): list of activity groups (CPU, CUDA) to use in profiling, supported values:
        ``torch.profiler.ProfilerActivity.CPU``, ``torch.profiler.ProfilerActivity.CUDA``,
        ``torch.profiler.ProfilerActivity.XPU``.
        Default value: ProfilerActivity.CPU and (when available) ProfilerActivity.CUDA
        or (when available) ProfilerActivity.XPU.
    record_shapes (bool): save information about operator's input shapes.
    profile_memory (bool): track tensor memory allocation/deallocation (see ``export_memory_timeline``
        for more details).
    with_stack (bool): record source information (file and line number) for the ops.
    with_flops (bool): use formula to estimate the FLOPS of specific operators
        (matrix multiplication and 2D convolution).
    with_modules (bool): record module hierarchy (including function names)
        corresponding to the callstack of the op. e.g. If module A's forward call's
        module B's forward which contains an aten::add op,
        then aten::add's module hierarchy is A.B
        Note that this support exist, at the moment, only for TorchScript models
        and not eager mode models.
    experimental_config (_ExperimentalConfig) : A set of experimental options
        used by profiler libraries like Kineto. Note, backward compatibility is not guaranteed.
    execution_trace_observer (ExecutionTraceObserver) : A PyTorch Execution Trace Observer object.
        `PyTorch Execution Traces <https://arxiv.org/pdf/2305.14516.pdf>`__ offer a graph based
        representation of AI/ML workloads and enable replay benchmarks, simulators, and emulators.
        When this argument is included the observer start() and stop() will be called for the
        same time window as PyTorch profiler.
    acc_events (bool): Enable the accumulation of FunctionEvents across multiple profiling cycles
    post_processing_timeout_s (float): Optional timeout in seconds for post-processing profiler
        results. In this context, post-processing happens after the profiling itself has finished.
        If specified, event parsing will stop after this duration and return partial results. Useful
        for handling large traces that may take too long to process.


.. note::
    This API is experimental and subject to change in the future.

    Enabling shape and stack tracing results in additional overhead.
    When record_shapes=True is specified, profiler will temporarily hold references to the tensors;
    that may further prevent certain optimizations that depend on the reference count and introduce
    extra tensor copies.
NF©Ú
activitiesÚrecord_shapesÚprofile_memoryÚ
with_stackÚ
with_flopsÚwith_modulesÚexperimental_configÚexecution_trace_observerÚ
acc_eventsÚcustom_trace_id_callbackÚpost_processing_timeout_sr]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   Úreturnc                óŽ  • U(       a  [        U5      O	[        5       U l        X l        XPl        X0l        X@l        X`l        Xpl        X€l	        X�l
        X l        X°l        S U l        SU l        S U l        S U l        ["        R$                  U R                  ;   a  SU l        OŸ["        R&                  U R                  ;   a  SU l        Oy["        R(                  U R                  ;   a  SU l        OS["        R*                  U R                  ;   a  SU l        O-["        R,                  U R                  ;   a  [/        5       U l        0 U l        g )NFÚcudaÚxpuÚmtiaÚhpu)Úsetr   r]   r^   ra   r_   r`   rb   rc   rd   re   rf   rg   ÚprofilerÚhas_cudagraphsÚmem_tlÚ
use_devicer   ÚCUDAÚXPUÚMTIAÚHPUÚPrivateUse1r   Úpreset_metadata)r;   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   s               r(   Ú__init__Ú_KinetoProfile.__init__“   s÷   € ö .8œ#˜jœ/Ô=QÓ=SˆŒØ*ÔØ$ŒØ,ÔØ$ŒØ(ÔØ#6Ô Ø(@Ô%Ø$ŒØ(@Ô%Ø)BÔ&Ø-1ˆŒØ#ˆÔØ48ˆŒØˆŒÜ× Ñ  D§O¡OÓ3à$ˆD�OÜ×!Ñ! T§_¡_Ó4à#ˆD�OÜ×"Ñ" d§o¡oÓ5à$ˆD�OÜ×!Ñ! T§_¡_Ó4à#ˆD�OÜ×)Ñ)¨T¯_©_Ó<ä;Ó=ˆDŒOð 02ˆÕr*   c                 óD   • U R                  5         U R                  5         g rN   )Úprepare_traceÚstart_tracerO   s    r(   rP   Ú_KinetoProfile.startÄ   s   € Ø×ÑÔØ×ÑÕr*   c                 ó$   • U R                  5         g rN   )Ú
stop_tracerO   s    r(   rT   Ú_KinetoProfile.stopÈ   s   € Ø�‰Õr*   c                 ó~  • [        [        S5      (       a$  SS KJs  Jn  UR
                  R                  U l        U R                  b  U R                  (       d£  [        R                  " [        R                  U R                  ;   U R                  U R                   U R"                  U R$                  U R&                  U R(                  SU R*                  U R                  U R,                  U R.                  S9U l        U R                  b  U R                  (       d  [1        S5        U R                  R3                  5         g )NÚ	_inductorr   T)Úuse_cpurr   r^   ra   r_   r`   rb   Ú
use_kinetorc   re   rf   rg   zŸWarning: Profiler clears events at the end of each cycle.Only events from the current cycle will be reported.To keep events across cycles, set acc_events=True.)ÚhasattrrG   Útorch._inductor.configrƒ   ÚconfigÚtritonÚ
cudagraphsrp   ro   re   Úprofr   r   ÚCPUr]   rr   r^   ra   r_   r`   rb   rc   rf   rg   r)   Ú_prepare_trace)r;   Úinductor_configs     r(   r|   Ú_KinetoProfile.prepare_traceË   sâ   € Ü”5˜+×&Ñ&ß<Ð<à"1×"8Ñ"8×"CÑ"CˆDÔØ�M‰MÑ!¨4¯?¯?Ü ŸLšLÜ)×-Ñ-°·±Ñ@ØŸ?™?Ø"×0Ñ0ØŸ?™?Ø#×2Ñ2ØŸ?™?Ø!×.Ñ.ØØ$(×$<Ñ$<ØŸ?™?Ø)-×)FÑ)FØ*.×*HÑ*HñˆDŒMð �M‰MÑ%°··ÜðEôð
 	�‰×$Ñ$Õ&r*   c                 ól  • U R                   (       a  U R                   R                  5         U R                  c  [        S5      eU R                  R	                  5         U R
                  (       a  U R                  SS5        U R                  (       a  U R                  SS5        U R                  (       a  U R                  SS5        U R                  (       a  U R                  SS5        U R                  (       a  U R                  SS5        [        5       (       Ga  U R                  5       nU(       a)  U R                  S[        R                  " U[        S	95        S n[!        ["        S
5      (       a'  SSKJn  U" [)        ["        R*                  SS5      5      nU R,                  (       aT  U(       a  US:  d  [/        5       (       d8  S[0        R2                  S'   U R                  SS5        S[0        R2                  S'   U R4                  R7                  5        H  u  pEU R                  XE5        M     g g )Nz2Profiler must be initialized before starting tracer_   Ú1r`   r^   rb   ra   ÚdistributedInfo©ÚclsÚversionr   )ÚTorchVersionrj   z0.0z12.6ÚDISABLE_CUPTI_LAZY_REINITÚ0ÚTEARDOWN_CUPTI)rd   rP   ro   ÚAssertionErrorÚ_start_tracer_   Úadd_metadata_jsonr`   r^   rb   ra   r   Ú_get_distributed_infor1   Údumpsr,   r†   rG   Útorch.torch_versionr–   Úgetattrr•   rp   r   ÚosÚenvironrx   Úitems)r;   Ú	dist_infoÚcuda_versionr–   ÚkÚvs         r(   r}   Ú_KinetoProfile.start_traceç   s   € Ø×(×(Ø×)Ñ)×/Ñ/Ô1Ø�=‰=Ñ Ü Ð!UÓVÐVØ�‰×"Ñ"Ô$à××Ø×"Ñ"Ð#3°SÔ9Ø�?�?Ø×"Ñ" <°Ô5Ø××Ø×"Ñ" ?°CÔ8Ø××Ø×"Ñ" >°3Ô7Ø�?�?Ø×"Ñ" <°Ô5ä×ÒØ×2Ñ2Ó4ˆIÞØ×&Ñ&Ø%¤t§z¢z°)ÄÑ'Oôð  ˆLÜ”u˜i×(Ñ(Ý<á+¬G´E·M±MÀ6È5Ó,QÓR�à×"×"Þ ,°Ó"7ÜH×JÑJà:=”—
‘
Ð6Ñ7Ø×&Ñ&Ð'BÀCÔHð
 03”—
‘
Ð+Ñ,ð ×,Ñ,×2Ñ2Ö4‘�Ø×&Ñ& qÖ,ò 5ð5 r*   c                 óÄ   • U R                   (       a  U R                   R                  5         U R                  c  [        S5      eU R                  R	                  S S S 5        g )Nz2Profiler must be initialized before stopping trace)rd   rT   ro   rš   Ú__exit__rO   s    r(   r€   Ú_KinetoProfile.stop_trace  sI   € Ø×(×(Ø×)Ñ)×.Ñ.Ô0Ø�=‰=Ñ Ü Ð!UÓVÐVØ�‰×Ñ˜t T¨4Õ0r*   Úpathc                 ó&  • U R                   c  [        S5      eUR                  S5      (       a•  [        R                  " SSS9 nU R                   R                  UR                  5      n[        UR                  S5       n[        R                  " US5       nUR                  U5        SSS5        SSS5        SSS5        U$ U R                   R                  U5      $ ! , (       d  f       N;= f! , (       d  f       ND= f! , (       d  f       W$ = f)	zs
Exports the collected trace in Chrome JSON format. If kineto is enabled, only
last cycle in schedule is exported.
Nz:Profiler must be initialized before exporting chrome traceú.gzúw+bú.json©ÚsuffixÚrbÚwb)
ro   rš   ÚendswithÚtempfileÚNamedTemporaryFileÚexport_chrome_traceÚnameÚopenÚgzipÚ
writelines)r;   r¬   ÚfpÚretvalueÚfinÚfouts         r(   r¸   Ú"_KinetoProfile.export_chrome_trace  sÑ   € ð
 �=‰=Ñ Ü ØLóð ð �=‰=˜×ÑÜ×,Ò,¨U¸7ÒCÀrØŸ=™=×<Ñ<¸R¿W¹WÓE�Ü˜"Ÿ'™' 4Ô(¨C´·²¸4ÀÔ1FÈ$Ø—O‘O CÔ(÷ 2G×(÷ Dð ˆOà—=‘=×4Ñ4°TÓ:Ð:÷	 2GÕ1Fú×(Õ(ú÷ DÔCð ˆOús<   Á<DÂ C0ÂCÂ*C0Â2DÃ
C-Ã)C0Ã0
C>	Ã:DÄ
DÚmetricc                 óh   • U R                   c  [        S5      eU R                   R                  X5      $ )z§Save stack traces to a file

Args:
    path (str): save stacks file to this location;
    metric (str): metric to use: "self_cpu_time_total" or "self_cuda_time_total"
z4Profiler must be initialized before exporting stacks)ro   rš   Úexport_stacks)r;   r¬   rÂ   s      r(   rÄ   Ú_KinetoProfile.export_stacks/  s/   € ð �=‰=Ñ Ü Ð!WÓXÐXØ�}‰}×*Ñ*¨4Ó8Ð8r*   Úenablec                 óV   • U R                   c  gU R                   R                  X5        g)aÛ  Toggle collection of activities on/off at any point of collection. Currently supports toggling Torch Ops
(CPU) and CUDA activity supported in Kineto

Args:
    activities (iterable): list of activity groups to use in profiling, supported values:
        ``torch.profiler.ProfilerActivity.CPU``, ``torch.profiler.ProfilerActivity.CUDA``
Examples:

.. code-block:: python

    with torch.profiler.profile(
        activities=[
            torch.profiler.ProfilerActivity.CPU,
            torch.profiler.ProfilerActivity.CUDA,
        ]
    ) as p:
        code_to_profile_0()
        // turn off collection of all CUDA activity
        p.toggle_collection_dynamic(False, [torch.profiler.ProfilerActivity.CUDA])
        code_to_profile_1()
        // turn on collection of all CUDA activity
        p.toggle_collection_dynamic(True, [torch.profiler.ProfilerActivity.CUDA])
        code_to_profile_2()
    print(p.key_averages().table(
        sort_by="self_cuda_time_total", row_limit=-1))
N)ro   Útoggle_collection_dynamic)r;   rÆ   r]   s      r(   rÈ   Ú(_KinetoProfile.toggle_collection_dynamic:  s#   € ð: �=‰=Ñ ØØ�‰×/Ñ/°ÕCr*   Úgroup_by_input_shapeÚgroup_by_stack_nÚgroup_by_overload_namec                 ój   • U R                   c  [        S5      eU R                   R                  XU5      $ )zîAverages events, grouping them by operator name and (optionally) input shapes, stack
and overload name.

.. note::
    To use shape/stack functionality make sure to set record_shapes/with_stack
    when creating profiler context manager.
z8Profiler must be initialized before getting key averages)ro   rš   Úkey_averages)r;   rÊ   rË   rÌ   s       r(   rÎ   Ú_KinetoProfile.key_averages[  s=   € ð �=‰=Ñ Ü ØJóð ð �}‰}×)Ñ)Ø Ð4Jó
ð 	
r*   c                 ó^   • U R                   c  [        S5      eU R                   R                  $ )zw
Returns the list of unaggregated profiler events,
to be used in the trace callback or after the profiling is finished
z4Profiler must be initialized before accessing events)ro   rš   Úfunction_eventsrO   s    r(   ÚeventsÚ_KinetoProfile.eventsp  s*   € ð
 �=‰=Ñ Ü Ð!WÓXÐXØ�}‰}×,Ñ,Ð,r*   ÚkeyÚvaluec                 ór   • SUR                  SS5      -   S-   n[        R                  R                  X5        g)zW
Adds a user defined metadata with a string key and a string value
into the trace file
Ú"z\"N)ÚreplacerG   rH   Ú_add_metadata_json)r;   rÔ   rÕ   Úwrapped_values       r(   Úadd_metadataÚ_KinetoProfile.add_metadatay  s0   € ð
 ˜eŸm™m¨C°Ó7Ñ7¸#Ñ=ˆÜ�‰×)Ñ)¨#Õ=r*   c                 óB   • [         R                  R                  X5        g)z[
Adds a user defined metadata with a string key and a valid json value
into the trace file
N)rG   rH   rÙ   ©r;   rÔ   rÕ   s      r(   rœ   Ú _KinetoProfile.add_metadata_json�  s   € ô
 	�‰×)Ñ)¨#Õ5r*   c                 ó    • X R                   U'   g)z§
Preset a user defined metadata when the profiler is not started
and added into the trace file later.
Metadata is in the format of a string key and a valid json value
N)rx   rÞ   s      r(   Úpreset_metadata_jsonÚ#_KinetoProfile.preset_metadata_jsonˆ  s   € ð %*×Ñ˜SÒ!r*   c                 ó®  • SS K Jn  UR                  5       (       a  UR                  5       (       d  g UR	                  5       nUUR                  5       UR                  5       UR                  5       UR                  R                  5       S.nUS:X  aC  [        R                  R                  R                  5       nSR                  S U 5       5      US'   U$ )Nr   )ÚbackendÚrankÚ
world_sizeÚpg_countÚ	pg_configÚncclÚ.c              3   ó8   #   • U  H  n[        U5      v •  M     g 7frN   )Ústr)Ú.0r§   s     r(   Ú	<genexpr>Ú7_KinetoProfile._get_distributed_info.<locals>.<genexpr>¡  s   é € Ð0NÂ¸A´°Q·°Âùs   ‚Únccl_version)Útorch.distributedÚdistributedÚis_availableÚis_initializedÚget_backendÚget_rankÚget_world_sizeÚget_pg_countÚdistributed_c10dÚ_get_all_pg_configsrG   rj   ré   r•   Újoin)r;   Údisträ   r¤   rð   s        r(   r�   Ú$_KinetoProfile._get_distributed_info�  s¯   € Ý(à× Ñ ×"Ñ"¨$×*=Ñ*=×*?Ñ*?Øà×"Ñ"Ó$ˆàØ—M‘M“OØ×-Ñ-Ó/Ø×)Ñ)Ó+Ø×.Ñ.×BÑBÓDñ
ˆ	ð �fÓÜ Ÿ:™:Ÿ?™?×2Ñ2Ó4ˆLà(+¯©Ñ0NÁÓ0NÓ(NˆI�nÑ%ØÐr*   c                 óB  • SnU Vs/ s H  n[        X5      (       a  M  U S3PM     nnU(       a  [        SR                  U5       S35      eU R                  b  U R                  R                  c  [        S5      e[        U R                  R                  5      $ s  snf )N)r^   r_   r`   z=Truez, z required for memory profiling.zDProfiler and kineto_results must be initialized for memory profiling)r    Ú
ValueErrorrû   ro   Úkineto_resultsrš   r   )r;   ÚrequiredÚiÚmissings       r(   Ú_memory_profileÚ_KinetoProfile._memory_profile¤  s�   € ØDˆÙ(0ÓIª 1¼À×8H“;�a�S˜“;©ˆÐIÞÜ §	¡	¨'Ó 2Ð3Ð3RÐSÓTÐTà�=‰=Ñ  D§M¡M×$@Ñ$@Ñ$HÜ ØVóð ô ˜TŸ]™]×9Ñ9Ó:Ð:ùò Js
   ‡BŸ	Bz¾`export_memory_timeline` is deprecated and will be removed in a future version. Please use `torch.cuda.memory._record_memory_history` and `torch.cuda.memory._export_memory_snapshot` instead.)r#   Údevicec                 óÄ  • UcX  U R                   (       a   U R                   S:w  a  U R                   S-   nO'[        R                  R                  5       (       a  SOSn[	        U R                  5       5      U l        UR                  S5      (       a  U R                  R                  X5        gUR                  S5      (       aÑ  [        R                  " SS	S
9 nUR                  S5      (       a'  U R                  R                  UR                  U5        O&U R                  R                  UR                  U5        [        UR                  5       n[        R                  " US5       nUR!                  U5        SSS5        SSS5        SSS5        gU R                  R                  X5        g! , (       d  f       N;= f! , (       d  f       ND= f! , (       d  f       g= f)aÑ  Export memory event information from the profiler collected
tree for a given device, and export a timeline plot. There are 3
exportable files using ``export_memory_timeline``, each controlled by the
``path``'s suffix.

- For an HTML compatible plot, use the suffix ``.html``, and a memory timeline
  plot will be embedded as a PNG file in the HTML file.

- For plot points consisting of ``[times, [sizes by category]]``, where
  ``times`` are timestamps and ``sizes`` are memory usage for each category.
  The memory timeline plot will be saved a JSON (``.json``) or gzipped JSON
  (``.json.gz``) depending on the suffix.

- For raw memory points, use the suffix ``.raw.json.gz``. Each raw memory
  event will consist of ``(timestamp, action, numbytes, category)``, where
  ``action`` is one of ``[PREEXISTING, CREATE, INCREMENT_VERSION, DESTROY]``,
  and ``category`` is one of the enums from
  ``torch.profiler._memory_profiler.Category``.

Output: Memory timeline written as gzipped JSON, JSON, or HTML.

.. deprecated::
    ``export_memory_timeline`` is deprecated and will be removed in a future version.
    Please use ``torch.cuda.memory._record_memory_history`` and
    ``torch.cuda.memory._export_memory_snapshot`` instead.
Nrj   z:0zcuda:0Úcpuz.htmlr®   úw+tr°   r±   zraw.json.gzÚwt)rr   rG   rj   ró   r   r  rq   rµ   Úexport_memory_timeline_htmlr¶   r·   Úexport_memory_timeline_rawr¹   Úexport_memory_timelinerº   r»   r¼   )r;   r¬   r  r½   r¿   rÀ   s         r(   r  Ú%_KinetoProfile.export_memory_timeline°  sC  € ðB ‰>Ø�� 4§?¡?°fÓ#<ØŸ™¨4Ñ/‘ä%*§Z¡Z×%<Ñ%<×%>Ñ%>™ÀE�ô ,¨D×,@Ñ,@Ó,BÓCˆŒð �=‰=˜×!Ñ!Ø�K‰K×3Ñ3°DÕAØ�]‰]˜5×!Ñ!Ü×,Ò,¨U¸7ÒCÀrØ—=‘= ×/Ñ/Ø—K‘K×:Ñ:¸2¿7¹7ÀFÕKà—K‘K×6Ñ6°r·w±wÀÔGÜ˜"Ÿ'™'”] c¬4¯9ª9°T¸4Ô+@ÀDØ—O‘O CÔ(÷ ,A—]÷ DÐCð �K‰K×.Ñ.¨tÕ<÷ ,AÕ+@ú—]•]ú÷ DÕCús=   ÃA9GÅG Å(F/Å:G ÆGÆ/
F=Æ9G Ç 
G	Ç
GÇ
G)re   r]   rf   rd   rc   rp   rq   rg   rx   r_   ro   r^   rr   ra   rb   r`   ©rh   N)Úself_cpu_time_total)Fr   FrN   )#r@   rA   rB   rC   rD   r   r   Úboolr   rK   r   rì   r8   ry   rP   rT   r|   r}   r€   r¸   rÄ   rÈ   r6   rÎ   rÒ   rÛ   rœ   rá   r�   r   r  r   ÚFutureWarningr  rE   r?   r*   r(   rZ   rZ   g   sü  † ñ)ð\ 9=Ø#Ø$Ø Ø Ø"Ø:>Ø;?Ø Ø=AØ26ò/2ð Ð-Ñ.°Ñ5ð/2ð ð	/2ð
 ð/2ð ð/2ð ð/2ð ð/2ð 1°4Ñ7ð/2ð #2°DÑ"8ð/2ð ð/2ð #+¨2¨s¨7Ñ"3°dÑ":ð/2ð $)¨4¡<ð/2ð 
õ/2ôbôô'ô8--ô^1ð;¨ô ;ñ$	9 #ð 	9¨sõ 	9ðDØðDØ(0Ð1AÑ(BðDà	ôDðF &+Ø !Ø',ñ	
à"ð
ð ð
ð !%õ	
ò*-ð> ð >¨Cð >°Dô >ð6 Sð 6°ð 6¸ô 6ð*¨ð *°Cð *¸Dô *òð(
; ô 
;ñ ð	yàññ
2=¨3ð 2=¸¸d¹
ð 2=Èdô 2=óó
2=r*   rZ   c                   ó(   • \ rS rSrSrSrSrSrSrSr	g)	r   iê  z?
Profiler actions that can be taken at the specified intervals
r   é   r!   é   r?   N)
r@   rA   rB   rC   rD   ÚNONEÚWARMUPÚRECORDÚRECORD_AND_SAVErE   r?   r*   r(   r   r   ê  s   † ñð €DØ€FØ€FØƒOr*   r   )ÚrepeatÚ
skip_firstÚskip_first_waitÚwaitÚwarmupÚactiver  r  r  rh   c                 óÖ   ^ ^^^^^• S[         S[        4UUUUU U4S jjnT S:  d  TS:  d  TS::  d  TS:  d  TS:  a  [        ST  ST ST ST S	T S
35      eTS:X  a
  [        SSS9  U$ )aÛ  
Returns a callable that can be used as profiler ``schedule`` argument. The profiler will skip
the first ``skip_first`` steps, then wait for ``wait`` steps, then do the warmup for the next ``warmup`` steps,
then do the active recording for the next ``active`` steps and then repeat the cycle starting with ``wait`` steps.
The optional number of cycles is specified with the ``repeat`` parameter, the zero value means that
the cycles will continue until the profiling is finished.

The ``skip_first_wait`` parameter controls whether the first ``wait`` stage should be skipped.
This can be useful if a user wants to wait longer than ``skip_first`` between cycles, but not
for the first profile. For example, if ``skip_first`` is 10 and ``wait`` is 20, the first cycle will
wait 10 + 20 = 30 steps before warmup if ``skip_first_wait`` is zero, but will wait only 10
steps if ``skip_first_wait`` is non-zero. All subsequent cycles will then wait 20 steps between the
last active and warmup.
Ústeprh   c                 ó|  >• U S:  a  [        SU  S35      eU T:  a  [        R                  $ U T-  n TS:w  a  U T-  n TT-   T-   nTS:”  a  X-  T:¼  a  [        R                  $ X-  nUT:  a  [        R                  $ UTT-   :  a  [        R                  $ X!S-
  :  a  [        R                  $ [        R
                  $ )Nr   zStep must be non-negative. Got rê   r  )rš   r   r  r  r  r  )	r!  Ú	num_stepsÚmod_stepr  r  r  r  r  r  s	      €€€€€€r(   Úschedule_fnÚschedule.<locals>.schedule_fn  sØ   ø€ Ø�!‹8Ü Ð#BÀ4À&ÈÐ!JÓKÐKØ�*ÓÜ!×&Ñ&Ð&à�JÑˆDà˜aÓØ�D‰LˆDØ˜6‘M FÑ*ˆ	Ø�A‹:˜$Ñ*¨fÓ4Ü!×&Ñ&Ð&ØÑ#ˆØ�d‹?Ü!×&Ñ&Ð&Ø˜˜v™Ó%Ü!×(Ñ(Ð(ð ¨!™mÓ+ô ×%Ñ%ðô $×3Ñ3ðr*   r   z.Invalid profiler schedule arguments. Got wait=z (need >= 0), warmup=z (need >= 0), active=z (need > 0), repeat=z (need >= 0), skip_first=z (need >= 0).z>Profiler won't be using warmup, this can skew profiler resultsr!   ©r$   )r6   r   rš   r   )r  r  r  r  r  r  r%  s   `````` r(   r   r   õ  sœ   ý€ ð0œ#ð ¤.÷ ô ð2 ˆaƒx�6˜A“: ¨1£°¸³
¸jÈ1»nÜØ<¸T¸FÐBWÐX^ÐW_ð `Ø�XÐ1°&°Ð9RÐS]ÐR^Ð^kðmó
ð 	
ð �ƒ{ÜØLØò	
ð Ðr*   Ú_c                 ó"   • [         R                  $ )zm
Default profiler behavior - immediately starts recording the events,
keeps doing it on every profiler step.
)r   r  )r(  s    r(   Ú_default_schedule_fnr*  3  s   € ô
 × Ñ Ð r*   Údir_nameÚworker_nameÚuse_gzipc                 ó8   ^ ^^^^• SSK mSSKmSU UUUU4S jjnU$ )zø
Outputs tracing files to directory of ``dir_name``, then that directory can be
directly delivered to tensorboard as logdir.
``worker_name`` should be unique for each worker in distributed scenario,
it will be set to '[hostname]_[pid]' by default.
r   Nc                 ó¾  >• [         R                  R                  T5      (       d   [         R                  " TSS9  T(       d(  TR                  5        S[         R                  " 5        3mT STR                  5        S3nT(       a  US-   nU R                  " [         R                  R                  TU5      5        g ! [         a  n[        ST-   5      UeS nAff = f)NT)Úexist_okzCan't create directory: r(  rê   z.pt.trace.jsonr®   )r¡   r¬   ÚisdirÚmakedirsÚ	ExceptionÚRuntimeErrorÚgethostnameÚgetpidÚtime_nsr¸   rû   )r‹   ÚeÚ	file_namer+  ÚsocketÚtimer-  r,  s      €€€€€r(   Ú
handler_fnÚ-tensorboard_trace_handler.<locals>.handler_fnG  s¹   ø€ ä�w‰w�}‰}˜X×&Ñ&ðQÜ—’˜H¨tÒ4ö Ø#×/Ñ/Ó1Ð2°!´B·I²I³K°=ÐAˆKà"�m 1 T§\¡\£^Ð$4°NÐCˆ	ÞØ! EÑ)ˆIØ× Ò ¤§¡§¡¨h¸	Ó!BÕCøô ó QÜ"Ð#=ÀÑ#HÓIÈqÐPûðQús   §B> Â>
CÃCÃCr  )r:  r;  )r+  r,  r-  r<  r:  r;  s   ``` @@r(   r   r   ;  s   ü€ ó Û÷Dó Dð Ðr*   c                   óZ  ^ • \ rS rSrSrSSSSSSSSSSSSSSS.S\\   S-  S\\/\	4   S-  S\S	\
4   S-  S
\S\S\S\S\S\S-  S\S-  S\S\S-  S\/ \4   S-  S\S-  SS4U 4S jjjrS rS rS"S jrS"S jrS"S jrS"S jrS rS"S jrS"S jrS\R6                  S-  4S  jrS!rU =r$ )#r   iY  aB  Profiler context manager.

Args:
    activities (iterable): list of activity groups (CPU, CUDA) to use in profiling, supported values:
        ``torch.profiler.ProfilerActivity.CPU``, ``torch.profiler.ProfilerActivity.CUDA``,
        ``torch.profiler.ProfilerActivity.XPU``.
        Default value: ProfilerActivity.CPU and (when available) ProfilerActivity.CUDA
        or (when available) ProfilerActivity.XPU.
    schedule (Callable): callable that takes step (int) as a single parameter and returns
        ``ProfilerAction`` value that specifies the profiler action to perform at each step.
    on_trace_ready (Callable): callable that is called at each step when ``schedule``
        returns ``ProfilerAction.RECORD_AND_SAVE`` during the profiling.
    record_shapes (bool): save information about operator's input shapes.
    profile_memory (bool): track tensor memory allocation/deallocation.
    with_stack (bool): record source information (file and line number) for the ops.
    with_flops (bool): use formula to estimate the FLOPs (floating point operations) of specific operators
        (matrix multiplication and 2D convolution).
    with_modules (bool): record module hierarchy (including function names)
        corresponding to the callstack of the op. e.g. If module A's forward call's
        module B's forward which contains an aten::add op,
        then aten::add's module hierarchy is A.B
        Note that this support exist, at the moment, only for TorchScript models
        and not eager mode models.
    experimental_config (_ExperimentalConfig) : A set of experimental options
        used for Kineto library features. Note, backward compatibility is not guaranteed.
    execution_trace_observer (ExecutionTraceObserver) : A PyTorch Execution Trace Observer object.
        `PyTorch Execution Traces <https://arxiv.org/pdf/2305.14516.pdf>`__ offer a graph based
        representation of AI/ML workloads and enable replay benchmarks, simulators, and emulators.
        When this argument is included the observer start() and stop() will be called for the
        same time window as PyTorch profiler. See the examples section below for a code sample.
    acc_events (bool): Enable the accumulation of FunctionEvents across multiple profiling cycles
    post_processing_timeout_s (float): Optional timeout in seconds for post-processing profiler
        results. If specified, event parsing will stop after this duration and return partial
        results. Useful for handling large traces that may take too long to process.
    use_cuda (bool):
        .. deprecated:: 1.8.1
            use ``activities`` instead.

.. note::
    Use :func:`~torch.profiler.schedule` to generate the callable schedule.
    Non-default schedules are useful when profiling long training jobs
    and allow the user to obtain multiple traces at the different iterations
    of the training process.
    The default schedule simply records all the events continuously for the
    duration of the context manager.

.. note::
    Use :func:`~torch.profiler.tensorboard_trace_handler` to generate result files for TensorBoard:

    ``on_trace_ready=torch.profiler.tensorboard_trace_handler(dir_name)``

    After profiling, result files can be found in the specified directory. Use the command:

    ``tensorboard --logdir dir_name``

    to see the results in TensorBoard.
    For more information, see
    `PyTorch Profiler TensorBoard Plugin <https://github.com/pytorch/kineto/tree/master/tb_plugin>`__

.. note::
    Enabling shape and stack tracing results in additional overhead.
    When record_shapes=True is specified, profiler will temporarily hold references to the tensors;
    that may further prevent certain optimizations that depend on the reference count and introduce
    extra tensor copies.


Examples:

.. code-block:: python

    with torch.profiler.profile(
        activities=[
            torch.profiler.ProfilerActivity.CPU,
            torch.profiler.ProfilerActivity.CUDA,
        ]
    ) as p:
        code_to_profile()
    print(p.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1))

Using the profiler's ``schedule``, ``on_trace_ready`` and ``step`` functions:

.. code-block:: python

    # Non-default profiler schedule allows user to turn profiler on and off
    # on different iterations of the training loop;
    # trace_handler is called every time a new trace becomes available
    def trace_handler(prof):
        print(
            prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1)
        )
        # prof.export_chrome_trace("/tmp/test_trace_" + str(prof.step_num) + ".json")


    with torch.profiler.profile(
        activities=[
            torch.profiler.ProfilerActivity.CPU,
            torch.profiler.ProfilerActivity.CUDA,
        ],
        # In this example with wait=1, warmup=1, active=2, repeat=1,
        # profiler will skip the first step/iteration,
        # start warming up on the second, record
        # the third and the forth iterations,
        # after which the trace will become available
        # and on_trace_ready (when set) is called;
        # the cycle repeats starting with the next step
        schedule=torch.profiler.schedule(wait=1, warmup=1, active=2, repeat=1),
        on_trace_ready=trace_handler,
        # on_trace_ready=torch.profiler.tensorboard_trace_handler('./log')
        # used when outputting for tensorboard
    ) as p:
        for iter in range(N):
            code_iteration_to_profile(iter)
            # send a signal to the profiler that the next iteration has started
            p.step()

The following sample shows how to setup up an Execution Trace Observer (`execution_trace_observer`)

.. code-block:: python

    with torch.profiler.profile(
        ...
        execution_trace_observer=(
            ExecutionTraceObserver().register_callback("./execution_trace.json")
        ),
    ) as p:
        for iter in range(N):
            code_iteration_to_profile(iter)
            p.step()

You can also refer to test_execution_trace_with_kineto() in tests/profiler/test_profiler.py.
Note: One can also pass any object satisfying the _ITraceObserver interface.
NF)r]   r   Úon_trace_readyr^   r_   r`   ra   rb   rc   rd   re   Úuse_cudarf   rg   r]   r   r?  .r^   r_   r`   ra   rb   rc   rd   re   r@  rf   rg   rh   c                ó8
  >• U(       a  [        U5      O	[        5       nUbi  [        S[        SS9  U(       a   UR	                  [
        R                  5        O3[
        R                  U;   a  UR                  [
        R                  5        [        U5      S:X  a  [        S5      e[        TU ]-  UUUUUUU	U
(       a  U
O[        R                  5       UUUS9  U(       a  X l        SU l        O[         U l        SU l        X0l        SU l        U R                  U R$                  5      U l        S U l        0 [*        R,                  [*        R,                  4/ _[*        R,                  [*        R.                  4U R0                  /_[*        R,                  [*        R2                  4U R0                  U R4                  /_[*        R,                  [*        R6                  4U R0                  U R4                  /_[*        R.                  [*        R,                  4[9        [        S	5      U R4                  U R:                  /_[*        R.                  [*        R.                  4/ _[*        R.                  [*        R2                  4U R4                  /_[*        R.                  [*        R6                  4U R4                  /_[*        R2                  [*        R,                  4[9        [        S
5      U R:                  /_[*        R2                  [*        R.                  4[9        [        S5      U R:                  /_[*        R2                  [*        R2                  4/ _[*        R2                  [*        R6                  4/ _[*        R6                  [*        R,                  4U R:                  U R<                  /_[*        R6                  [*        R.                  4U R:                  U R<                  U R0                  /_[*        R6                  [*        R2                  4U R:                  U R<                  U R0                  U R4                  /_[*        R6                  [*        R6                  4U R:                  U R<                  U R0                  U R4                  /_[*        R.                  S 4U R4                  U R:                  /_[*        R2                  S 4U R:                  U R<                  /[*        R6                  S 4U R:                  U R<                  /0EU l        [@        RB                  RE                  [F        5        g )Nz;`use_cuda` is deprecated, use `activities` argument insteadr!   r'  r   z"No valid profiler activities foundr\   TFz+Incorrect schedule: WARMUP followed by NONEz+Incorrect schedule: RECORD followed by NONEz-Incorrect schedule: RECORD followed by WARMUP)$rn   r   r   r  r&   r   rs   ÚremoveÚlenrš   Úsuperry   r   Ú"build_execution_trace_obs_from_envr   Úrecord_stepsr*  r?  Ústep_numÚcurrent_actionÚstep_rec_fnr   r  r  r|   r  r}   r  r   r€   Ú_trace_readyÚ
action_mapr‹   ÚKinetoStepTrackerÚinit_step_countÚPROFILER_STEP_NAME)r;   r]   r   r?  r^   r_   r`   ra   rb   rc   rd   re   r@  rf   rg   Úactivities_setÚ	__class__s                   €r(   ry   Úprofile.__init__ß  sˆ  ø€ ö& -7œ˜ZœÔ<PÓ<RˆØÑÜØMÜØòö
 Ø×"Ñ"Ô#3×#8Ñ#8Õ9Ü!×&Ñ&¨.Ó8Ø×%Ñ%Ô&6×&;Ñ&;Ô<Üˆ~Ó !Ó#Ü Ð!EÓFÐFä‰ÑØ!Ø'Ø)Ø!Ø!Ø%Ø 3æ'ñ &>ä'×JÑJÓLØ!Ø%=Ø&?ð 	ñ 	
ö  Ø$ŒMà $ˆDÕä0ˆDŒMØ %ˆDÔØ,ÔØˆŒØ"Ÿm™m¨D¯M©MÓ:ˆÔØ8<ˆÔð:
ä× Ñ ¤.×"5Ñ"5Ð6¸ð:
ô × Ñ ¤.×"7Ñ"7Ð8¸4×;MÑ;MÐ:Nð:
ô × Ñ ¤.×"7Ñ"7Ð8Ø×"Ñ"Ø× Ñ ð;ð	:
ô × Ñ ¤.×"@Ñ"@ÐAØ×"Ñ"Ø× Ñ ðDð:
ô ×"Ñ"¤N×$7Ñ$7Ð8ÜœÐKÓLØ× Ñ Ø—‘ð;ð:
ô" ×"Ñ"¤N×$9Ñ$9Ð:¸Bð#:
ô$ ×"Ñ"¤N×$9Ñ$9Ð:¸T×=MÑ=MÐ<Nð%:
ô& ×"Ñ"¤N×$BÑ$BÐCÀd×FVÑFVÐEWð':
ô( ×"Ñ"¤N×$7Ñ$7Ð8ÜœÐKÓLØ—‘ð;ð):
ô0 ×"Ñ"¤N×$9Ñ$9Ð:ÜœÐMÓNØ—‘ð=ð1:
ô8 ×"Ñ"¤N×$9Ñ$9Ð:¸Bð9:
ô: ×"Ñ"¤N×$BÑ$BÐCÀRð;:
ô< ×+Ñ+¬^×-@Ñ-@ÐAØ—‘Ø×!Ñ!ðDð=:
ôD ×+Ñ+¬^×-BÑ-BÐCØ—‘Ø×!Ñ!Ø×"Ñ"ðFðE:
ôN ×+Ñ+¬^×-BÑ-BÐCØ—‘Ø×!Ñ!Ø×"Ñ"Ø× Ñ ð	FðO:
ôZ ×+Ñ+¬^×-KÑ-KÐLØ—‘Ø×!Ñ!Ø×"Ñ"Ø× Ñ ð	Oð[:
ôh ×"Ñ" DÐ)¨D×,<Ñ,<¸d¿o¹oÐ+Nði:
ôj ×"Ñ" DÐ)¨D¯O©O¸T×=NÑ=NÐ+OÜ×+Ñ+¨TÐ2Ø—‘Ø×!Ñ!ð5ñm:
ð 	Œô~ 	×Ñ×.Ñ.Ô/AÕBr*   c                 ó&   • U R                  5         U $ rN   )rP   rO   s    r(   Ú	__enter__Úprofile.__enter__]  s   € Ø�
‰
ŒØˆr*   c                 óÂ   • U R                  5         [        R                  R                  [        5        U R
                  (       a  U R
                  R                  5         g g rN   )rT   r‹   rL  Úerase_step_countrN  rd   rW   )r;   Úexc_typeÚexc_valÚexc_tbs       r(   rª   Úprofile.__exit__a  s@   € Ø�	‰	ŒÜ×Ñ×/Ñ/Ô0BÔCØ×(×(Ø×)Ñ)×1Ñ1Õ3ð )r*   c                 ó  • U R                  [        R                  U R                  5        U R                  (       aL  [
        R                  " S[        U R                  5      -   5      U l	        U R                  R                  5         g g )NúProfilerStep#)Ú_transit_actionr   r  rH  rF  r‹   Úrecord_functionrì   rG  rI  rS  rO   s    r(   rP   Úprofile.startg  sd   € Ø×Ñœ^×0Ñ0°$×2EÑ2EÔFØ××Ü#×3Ò3Ø¤# d§m¡mÓ"4Ñ4ó ˆDÔð ×Ñ×&Ñ&Õ(ð	 r*   c                 óº   • U R                   (       a.  U R                  (       a  U R                  R                  S S S 5        U R                  U R                  S 5        g rN   )rF  rI  rª   r]  rH  rO   s    r(   rT   Úprofile.stopo  sA   € Ø×× ×!1×!1Ø×Ñ×%Ñ% d¨D°$Ô7Ø×Ñ˜T×0Ñ0°$Õ7r*   c                 óì  • U R                   (       a.  U R                  (       a  U R                  R                  SSS5        U R                  nU =R                  S-  sl        U R                  U R                  5      U l        U R                  XR                  5        [        R                  R                  SS5      (       d4  [        5       (       aH  [        R                  R                  SS5      (       a#  [        R                  R                  [        5        U R                   (       aL  [        R                  " S[!        U R                  5      -   5      U l        U R                  R#                  5         gg)z@
Signals the profiler that the next profiling step has started.
Nr  ÚKINETO_USE_DAEMONÚ ÚKINETO_FORCE_STEP_HOOKr\  )rF  rI  rª   rH  rG  r   r]  r¡   r¢   Úgetr   r‹   rL  Úincrement_steprN  r^  rì   rS  )r;   Úprev_actions     r(   r!  Úprofile.stept  sü   € ð ×× ×!1×!1Ø×Ñ×%Ñ% d¨D°$Ô7Ø×)Ñ)ˆØ�Š˜Ñ�Ø"Ÿm™m¨D¯M©MÓ:ˆÔà×Ñ˜[×*=Ñ*=Ô>Ü�:‰:�>‰>Ð-¨r×2Ñ2Ü�K‰KœBŸJ™JŸN™NÐ+CÀR×HÑHä×"Ñ"×1Ñ1Ô2DÔEà××Ü#×3Ò3Ø¤# d§m¡mÓ"4Ñ4ó ˆDÔð ×Ñ×&Ñ&Õ(ð	 r*   c                 ó   • Xl         g)z@
Sets a callback to be called when a new trace ID is generated.
N)rf   )r;   Úcallbacks     r(   Úset_custom_trace_id_callbackÚ$profile.set_custom_trace_id_callbackŠ  s
   € ð )1Õ%r*   c                 óJ   • U R                   c  gU R                   R                  $ )z
Returns the current trace ID.
N)ro   Útrace_idrO   s    r(   Úget_trace_idÚprofile.get_trace_id�  s!   € ð �=‰=Ñ ØØ�}‰}×%Ñ%Ð%r*   c                 óJ   • U R                   (       a  U R                  U 5        g g rN   )r?  rO   s    r(   rJ  Úprofile._trace_ready˜  s   € Ø××Ø×Ñ Õ%ð r*   c                 ól   • U R                   R                  X45      nU(       a  U H
  nU" 5         M     g g rN   )rK  rf  )r;   rh  rH  Úaction_listÚactions        r(   r]  Úprofile._transit_actionœ  s0   € Ø—o‘o×)Ñ)¨;Ð*GÓHˆÞÛ%�Ù–ò &ð r*   c                 óJ   • U R                   c  g U R                   R                  $ rN   )ro   Ú_statsrO   s    r(   ry  Úprofile._stats¢  s   € Ø�=‰=Ñ ØØ�}‰}×#Ñ#Ð#r*   )rK  rH  rf   r?  rF  r   rG  rI  r  )r@   rA   rB   rC   rD   r   r   r   r6   r   r	   r  r   rK   rì   r8   ry   rS  rª   rP   rT   r!  rl  rp  rJ  r]  r‹   Ú_ProfilerStatsry  rE   Ú__classcell__)rP  s   @r(   r   r   Y  sŒ  ø† ñCðP 9=Ø;?Ø48Ø#Ø$Ø Ø Ø"Ø:>Ø;?Ø à $Ø=AØ26ò#|Cð Ð-Ñ.°Ñ5ð|Cð ˜C˜5 .Ð0Ñ1°DÑ8ð	|Cð
 !  c Ñ*¨TÑ1ð|Cð ð|Cð ð|Cð ð|Cð ð|Cð ð|Cð 1°4Ñ7ð|Cð #2°DÑ"8ð|Cð ð|Cð ˜‘+ð|Cð  #+¨2¨s¨7Ñ"3°dÑ":ð!|Cð" $)¨4¡<ð#|Cð$ 
÷%|Cð |Cò|ò4ô)ô8ô
)ô,1ò&ô&ôð$˜×+Ñ+¨dÑ2÷ $ò $r*   r   c                   ó  • \ rS rSrSrSS jrSS jr\S\S    4S j5       r	SS jr
S	\S\4S
 jrSS\S-  4S jjr\ SS\S\S-  4S jj5       rSS jr\S 5       rS rSS jrSS jrSS jrS\S-  4S jrSS jrSrg)r   i¨  af  Execution Trace Observer

Each process can have a single ExecutionTraceObserver instance. The observer
can be added to record function callbacks via calling register_callback()
explicitly. Without calling unregister_callback(), repeated calls to
register_callback() will not add additional observers to record function
callbacks. Once an ExecutionTraceObserver is created, the start() and stop()
methods control when the event data is recorded.

Deleting or calling unregister_callback() will remove the observer from the
record function callbacks, finalize the output file, and will stop
incurring any overheads.
rh   Nc                 óX   • SU l         SU l        SU l        SU l        SU l        SU l        g)z!
Initializes the default states.
Frd  N)Ú_registeredÚ_execution_trace_runningÚextra_resources_collectionÚresources_dirÚoutput_file_pathÚoutput_file_path_observerrO   s    r(   ry   ÚExecutionTraceObserver.__init__·  s4   € ð !ˆÔØ(-ˆÔ%Ø*/ˆÔ'Ø"$ˆÔØ%'ˆÔØ.0ˆÕ&r*   c                 ó$   • U R                  5         g©z?
Calls unregister_callback() to make sure to finalize outputs.
N©Úunregister_callbackrO   s    r(   Ú__del__ÚExecutionTraceObserver.__del__Â  ó   € ð 	× Ñ Õ"r*   c                  óØ  • [         R                  R                  SS5      S:X  a‘   [        R                  " SSSS9 n U R
                  nSSS5        [        5       nUR                  W5        [         R                  R                  SS5      S:X  a  UR                  S5        U$ UR                  S5        U$ g! , (       d  f       Nt= f! [         a  n[        S	U 3S
S9   SnAgSnAff = f)aŽ  
Returns an ExecutionTraceObserver instance if the environment variable
ENABLE_PYTORCH_EXECUTION_TRACE is set to 1, otherwise returns None.

Configures the observer to also collect extra resources if the environment variable
``ENABLE_PYTORCH_EXECUTION_TRACE_EXTRAS=1``. These are resources such as generated kernels,
index tensor data etc. that are required to make the Execution Trace replayable.
ÚENABLE_PYTORCH_EXECUTION_TRACEr˜   r‘   r	  z.et.jsonF©r²   ÚdeleteNzTExecution trace will not be recorded. Exception on creating default temporary file: r!   r'  Ú%ENABLE_PYTORCH_EXECUTION_TRACE_EXTRAST)r¡   r¢   rf  r¶   r·   r¹   r3  r   r   Úregister_callbackÚset_extra_resource_collection)r½   Úfilenamer8  Úets       r(   rE  Ú9ExecutionTraceObserver.build_execution_trace_obs_from_envÈ  sÜ   € ô �:‰:�>‰>Ð:¸CÓ@ÀCÓGð
Ü×0Ò0Ø *°UòàØ!Ÿw™w�H÷ô (Ó)ˆBØ× Ñ  Ô*ä�z‰z�~‰~ÐEÀsÓKÈsÓRØ×0Ñ0°Ô6ð ˆIð ×0Ñ0°Ô7ØˆIØ÷%õ ûô ó ÜØjÐklÐjmÐnØ òô ûðús4   ¦C ¼B7Á	C Â7
CÃC ÃC Ã
C)ÃC$Ã$C)c                 óP   • Xl         U R                   (       a  U R                  SS9  g)a  
Collects extra resources such as generated kernels, index tensor data, and any other
metadata that is required to complete the Execution Trace content.

The caller should call this method with val=True after calling register_callback() if they want
to collect the extra resources.
T)Ú
can_createN)r�  Úget_resources_dir)r;   Úvals     r(   r“  Ú4ExecutionTraceObserver.set_extra_resource_collectionè  s'   € ð +.Ô'Ø×*×*Ø×"Ñ"¨dÐ"Ñ3Ør*   rƒ  c                 ó°   • S[         4S jnU R                  (       d9  Xl        UR                  S5      (       a  U" 5       nXl        [        U5      U l        U $ )z^
Adds ET observer to record function callbacks. The data will be
written to output_file_path.
rh   c                  ó|   • [         R                  " SSSS9 n U R                  sS S S 5        $ ! , (       d  f       g = f)Nr¯   r°   Fr�  )r¶   r·   r¹   )r½   s    r(   Úget_temp_uncompressed_fileÚLExecutionTraceObserver.register_callback.<locals>.get_temp_uncompressed_fileû  s+   € Ü×,Ò,¨U¸7È5ÒQÐUWØ—w‘w÷ R×Q×Qús   —-­
;r®   )rì   r  rƒ  rµ   r„  r   )r;   rƒ  rž  s      r(   r’  Ú(ExecutionTraceObserver.register_callbackõ  sR   € ð	¬Cô 	ð ××Ø$4Ô!Ø×(Ñ(¨×/Ñ/Ù#=Ó#?Ð Ø-=Ô*Ü<Ð=MÓNˆDÔØˆr*   c                 óÐ   • U R                   (       d  gU R                  (       a  U R                  $ [        R                  U R                  US9nU(       d  gX l        U R                  $ )a†  
Generates the resources directory for the generated kernels,
or index tensor data or any other metadata that is required
to complete the Execution Trace content.

The directory is created right where the ET file is being output.

Only works if the observer has called set_extra_resource_collection(val=True).

Returns None if the observer is not configured with extra resource collection.
N)Ú
create_dir)r�  r‚  r   Úget_resources_dir_for_et_pathrƒ  )r;   r˜  Úgenerated_paths      r(   r™  Ú(ExecutionTraceObserver.get_resources_dir  s`   € ð ×.×.ØØ××à×%Ñ%Ð%Ü/×MÑMØ×!Ñ!¨jð Nð 
ˆö àØ+ÔØ×!Ñ!Ð!r*   r¢  c                 ó’  • [         R                  R                  U 5      u  p#[         R                  R                  U[         R                  R	                  U5      S   S-   5      n[         R                  R                  U5      (       d!  U(       a   [         R                  " U5        U$ g U$ ! [         a    [        SU 3SS9   g f = f)Nr   Ú
_resourcesz(Execution trace exception when creating r!   r'  )	r¡   r¬   Úsplitrû   ÚsplitextÚexistsÚmkdirr3  r   )Ú
trace_pathr¢  Úwork_dirr9  Úresource_dirs        r(   r£  Ú4ExecutionTraceObserver.get_resources_dir_for_et_path!  s°   € ô !Ÿg™gŸm™m¨JÓ7ÑˆÜ—w‘w—|‘|Ø”b—g‘g×&Ñ& yÓ1°!Ñ4°|ÑCó
ˆô �w‰w�~‰~˜l×+Ñ+Þð Ü—H’H˜\Ô*ð Ðð ØÐøô !ó  ÜØBÀ<À.ÐQØ#$òñ  ð ús   ÂB, Â,CÃCc                 ót  ^ • SU 4S jjnS[         S[         SS4S jnT R                  (       ag  T R                  5          U" 5         [        5         T R                  R                  S
5      (       a  U" T R                  T R                  5        ST l        gg! [         a  n[	        SU 3SS	9   SnANlSnAff = f)z5
Removes ET observer from record function callbacks.
rh   Nc                  óÆ  >•  TR                  5       n U (       d  g SSKJn  UR
                   Vs/ s H  n[        USS 5      c  M  UR                  PM!     nnU H\  nUc  M  [        R                  R                  U5      n[        R                  R                  X5      n[        R                  " XW5        M^     g ! [         a  n[        SU 3SS9   S nAg S nAff = fs  snf )Nz>Execution trace exception when generating resource directory: r!   r'  r   )ÚPyCodeCacheÚ__file__)r™  r3  r   Útorch._inductor.codecacher²  Úmodulesr    r³  r¡   r¬   Úbasenamerû   ÚshutilÚcopyfile)	r®  r8  r²  r§   Úkernel_filesÚkernel_filer¹   Údstr;   s	           €r(   Ú_save_triton_kernelsÚHExecutionTraceObserver.unregister_callback.<locals>._save_triton_kernels<  sÖ   ø€ ðØ#×5Ñ5Ó7�ö  Øõ >ð %×,Ò,óâ,�AÜ˜1˜j¨$Ó/ó �—
”
Ù,ð ð ó  ,�ØÑ&ÙÜ—w‘w×'Ñ'¨Ó4�Ü—g‘g—l‘l <Ó6�Ü—’ Ö1ò  ,øô% ó ÜØTÐUVÐTWÐXØ òô ûðüòs"   ƒB: ¯CÁCÂ:
CÃCÃCÚuncompressed_fileÚoutput_filec                 ó"  • [        SU  SU 35        [        U S5       n[        R                  " US5       nUR                  U5        S S S 5        S S S 5        [        R
                  " U 5        g ! , (       d  f       N-= f! , (       d  f       N6= f)NzExecution Trace: compressing z to r³   r´   )Úprintrº   r»   r¼   r¡   rB  )r¾  r¿  r¿   rÀ   s       r(   Ú_save_gz_fileÚAExecutionTraceObserver.unregister_callback.<locals>._save_gz_fileX  sn   € ÜÐ1Ð2CÐ1DÀDÈÈÐVÔWÜÐ'¨Ô.°#Ü—Y’Y˜{¨DÔ1°TØ—O‘O CÔ(÷ 2÷ /ô �IŠIÐ'Õ(÷ 2Õ1ú÷ /Õ.ús"   žB ¶A/ÁB Á/
A=	Á9B Â 
Bz(Execution trace failed to save kernels: r!   r'  ÚgzFr  )	rì   r  rT   r3  r   r   rƒ  rµ   r„  )r;   r¼  rÂ  r8  s   `   r(   r‰  Ú*ExecutionTraceObserver.unregister_callback7  s«   ø€ ÷
	2ð8	)¬Sð 	)¼sð 	)Àtô 	)ð ××Ø�I‰IŒKðSÙ$Ô&ô -Ô.Ø×$Ñ$×-Ñ-¨d×3Ñ3Ù˜d×<Ñ<¸d×>SÑ>SÔTà$ˆDÕð øô
 ó SÜÐ?À¸sÐCÐPQ×RûðSús   ¿B Â
B7Â B2Â2B7c                 ó   • U R                   $ )zN
Returns True if the execution trace observer is registered, otherwise False.
)r  rO   s    r(   Úis_registeredÚ$ExecutionTraceObserver.is_registeredm  s   € ð
 ×ÑÐr*   c                 ó   • U R                   $ )z;
Returns True if the observer is running, otherwise False.
)r€  rO   s    r(   Ú
is_runningÚ!ExecutionTraceObserver.is_runningt  s   € ð ×,Ñ,Ð,r*   c                 óŽ   • U R                   (       a4  U R                  (       d"  [        5         SU l        U R                  5         ggg)z
Starts to capture.
TN)r  r€  r   Ú_record_pg_configrO   s    r(   rP   ÚExecutionTraceObserver.startz  s8   € ð ×× D×$A×$AÜ,Ô.Ø,0ˆDÔ)Ø×"Ñ"Õ$ð %BÐr*   c                 óJ   • U R                   (       a  [        5         SU l         gg)z
Stops to capture.
FN)r€  r   rO   s    r(   rT   ÚExecutionTraceObserver.stopƒ  s    € ð ×(×(Ü-Ô/Ø,1ˆDÕ)ð )r*   c                 ó$   • U R                  5         gr‡  rˆ  rO   s    r(   rW   ÚExecutionTraceObserver.cleanup‹  rŒ  r*   c                 ó>   • U R                   (       a  U R                   $ g)z'
Returns the output file name or None.
N)rƒ  rO   s    r(   Úget_output_file_pathÚ+ExecutionTraceObserver.get_output_file_path‘  s   € ð × × Ø×(Ñ(Ð(àr*   c                 ó‚  • U R                   (       a®  [        R                  R                  5       (       aŠ  [        R                  R	                  5       (       af  [        R                  R
                  R                  R                  n[        R                  R                  S[        R                  " U[        S95        g g g g )Nz## process_group:init ##r“   )rÇ  rG   rò   ró   rô   rù   Ú_worldÚpg_config_inforH   Ú _record_function_with_args_enterr1   rž   r,   )r;   rØ  s     r(   rÍ  Ú(ExecutionTraceObserver._record_pg_configš  s†   € ð ××Ü×!Ñ!×.Ñ.×0Ñ0Ü×!Ñ!×0Ñ0×2Ñ2ä"×.Ñ.×?Ñ?×FÑF×UÑUˆNÜ�N‰N×;Ñ;Ø*Ü—
’
˜>¬}Ñ=õð 3ð 1ð r*   )r€  r  r�  rƒ  r„  r‚  r  )F)r@   rA   rB   rC   rD   ry   rŠ  Ústaticmethodr
   rE  r“  rì   r   r’  r™  r  r£  r‰  ÚpropertyrÇ  rÊ  rP   rT   rW   rÔ  rÍ  rE   r?   r*   r(   r   r   ¨  sÈ   † ñô	1ô#ð ð°Ð9QÑ0Ró ó ðô>ð°#ð ¸$ô ñ$"°S¸4±Zõ "ð4 à',ñØ $ðà	ˆt‰ôó ðô*4%ðl ñ ó ð ò-ô%ô2ô#ð c¨D¡jô ÷r*   r   )NF)Br»   r1   r¡   r·  r¶   Úabcr   r   Úcollections.abcr   r   Úenumr   Ú	functoolsr   Útypingr	   r
   Útyping_extensionsr   r   Úwarningsr   rG   Útorch.autograd.profilerrH   ro   r‹   Útorch._Cr   Útorch._C._profilerr   r   r   r   r   Útorch._environmentr   Útorch._utils_internalr   Útorch.autogradr   r   Útorch.profiler._memory_profilerr   r   Ú__all__rN  rn   r%   ÚUserWarningr)   r2   r,   r   rK   rZ   r   r6   r   r*  rì   r  r   r   r   r?   r*   r(   Ú<module>rí     sX  ðã Û Û 	Û Û ß #ß .Ý Ý ß  ß .Ý ã ß &Ð &Ý 2÷õ õ )Ý Sß =ß Pò€ð $Ð á“%€ð )°Qô <ô7�D×$Ñ$ô 7ò,2ô�cô ÷"@=ñ @=ôF�Tô ð  ØØò;à
ð;ð ð;ð ð	;ð
 ð;ð ð;ð ð;ð õ;ð|!˜Cð ! Nô !ð EJñØðØ # d¡
ðØ=Aõô<L$ˆnô L$ô^
~˜_õ ~r*   