
    iP,                     &   d dl Z 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mZm	Z	m
Z
 d dlmZ d dlZd dlmZ  e
d      Z ed      Z ej"                  e      Zej(                  j+                  dd      rJd dlZ ej.                  d	      sej1                  d
       n"ej1                  d        ej2                          ej4                  j7                  ej4                  j9                  e            dk(  rNej4                  j9                  ej4                  j9                  ej4                  j9                  e                  Zn4ej4                  j9                  ej4                  j9                  e            ZdedefdZ dedefdZ!dedefdZ"deddfdZ#dedefdZ$d Z%dedeeeef   geeef   f   fdZ&dedede'eef   fdZ(dededefdZ)d Z*d  Z+d! Z,d" Z-d# Z.dFd$Z/dFd%Z0d&efd'Z1d( Z2de3fd)Z4de3fd*Z5d&ed+ed,ed-efd.Z6dGded0e3de3fd1Z7dede8fd2Z9de3fd3Z:e jv                  d4        Z<de	e=ee8f      fd5Z>d6Z?d7Z@d/ZAdZBdZCd8ede	e   fd9ZDd:e'eef   d;eEe   d<ed=e8fd>ZFd:e'eef   fd?ZGd@ ZHdA ZIdB ZJdCe	e   fdDZKde	e   fdEZLy)H    N)AnyCallableOptionalTypeVar)	ParamSpec)StrobelightCompileTimeProfiler_T_PTORCH_COMPILE_STROBELIGHTFstrobeclientzNTORCH_COMPILE_STROBELIGHT is true, but seems like you are not on a FB machine.z8Strobelight profiler is enabled via environment variablesharedpath_componentsreturnc                  J    t        j                  j                  t        g|  S N)ospathjointorch_parentr   s    O/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_utils_internal.pyget_file_pathr   *   s    77<<777    c                  :    t        j                  j                  |  S r   )r   r   r   r   s    r   get_file_path_2r   .   s    77<<))r   r   c                     t        j                  | t         j                        r| S t        j                  t         j
                  j                  |             S )N)suffix)r   accessW_OKtempfilemkdtempr   basenamer   s    r   get_writable_pathr$   2   s9    	yyrww277#3#3D#9::r   c                      y r    r#   s    r   #prepare_multiprocessing_environmentr'   8       r   c                 @    t         j                  j                  |       S r   )r   r   realpathr#   s    r   resolve_library_pathr+   <   s    77D!!r   c                 h    |t         j                  v rt        |  d      t        |  d| d|       )Nz5: We could not find the fake impl for this operator. zm: We could not find the fake impl for this operator. The operator specified that you may need to import the 'z'' Python module to load the fake impl. )sysmodulesNotImplementedError)opnamemodulecontexts      r   &throw_abstract_impl_not_imported_errorr3   @   sU    !hKL
 	
 "h GGMh O44;9>
 	
r   
phase_namec                 `     dt         t        t        f   dt         t        t        f   f fd}|S )Nfunctionr   c                      t        j                         dt        j                  dt        j                  dt
        f fd       }|S )Nargskwargsr   c                      d|v rt        |d   x}t              r|dz   |d<   t        j                  s | i |S t        j                  g| i |S )Nskip   )
isinstanceintr   enabledprofile_compile_time)r8   r9   r;   r6   r4   s      r   wrapper_functionzdcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_inner.<locals>.wrapper_functionT   sm    Jvf~/Ets$K!%v 2990001FF*'+/5 r   )	functoolswrapsr
   r8   r9   r	   )r6   rA   r4   s   ` r   #compile_time_strobelight_meta_innerzJcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_innerQ   sE     
	"	BGG 	ryy 	R 	 
#	  r   r   r
   r	   )r4   rD   s   ` r   compile_time_strobelight_metarF   N   s2     2r6" 	"b&	 & /.r   categoryname
parametersc                 4    t         j                  d| ||       y )Nz	%s %s: %rloginfo)rG   rH   rI   s      r   signpost_eventrN   t   s    HH[(D*5r   insightinsight_descriptionc                      y r   r&   )rG   rO   rP   s      r   add_mlhub_insightrR   x   r(   r   c                 0    t         j                  d|        y )Nz%srK   )metricss    r   log_compilation_eventrU   |   s    HHT7r   c                      y r   r&   )graphs    r   upload_graphrX      r(   r   c                       y r   r&   r&   r   r   +set_pytorch_distributed_envs_from_justknobsrZ      r(   r   c                       y r   r&   r9   s    r   log_export_usager]      r(   r   c                       y r   r&   r\   s    r   log_draft_export_usager_      r(   r   c                       y r   r&   r8   r9   s     r   log_trace_structured_eventrb      r(   r   c                       y r   r&   ra   s     r   log_cache_bypassrd      r(   r   apic                     | }y r   r&   )re   r9   _s      r   log_torchscript_usagerh      s
    A
r   c                       yNFr&   r&   r   r   check_if_torch_exportablerk          r   c                       yNTr&   r&   r   r    export_training_ir_rollout_checkro          r   c                       yrn   r&   r&   r   r   full_aoti_runtime_assertrr      rp   r   type_of_exportexport_outcomeresultc                     | |||f\  }}}}y r   r&   )re   rs   rt   ru   rg   s        r   !log_torch_jit_trace_exportabilityrw      s     nnf<JAq!Q
r   Tdefaultc                     |S )ay  
    This function can be used to killswitch functionality in FB prod,
    where you can toggle this value to False in JK without having to
    do a code push.  In OSS, we always have everything turned on all
    the time, because downstream users can simply choose to not update
    PyTorch.  (If more fine-grained enable/disable is needed, we could
    potentially have a map we lookup name in to toggle behavior.  But
    the point is that it's all tied to source code in OSS, since there's
    no live server to query.)

    This is the bare minimum functionality I needed to do some killswitches.
    We have a more detailed plan at
    https://docs.google.com/document/d/1Ukerh9_42SeGh89J-tGtecpHBPwGlkQ043pddkKb3PU/edit
    In particular, in some circumstances it may be necessary to read in
    a knob once at process start, and then use it consistently for the
    rest of the process.  Future functionality will codify these patterns
    into a better high level API.

    WARNING: Do NOT call this function at module import time, JK is not
    fork safe and you will break anyone who forks the process and then
    hits JK again.
    r&   )rH   rx   s     r   justknobs_checkrz      s	    . Nr   c                      y)z)
    Read warning on justknobs_check
    r   r&   )rH   s    r   justknobs_getval_intr|      s     r   c                       yrj   r&   r&   r   r   is_fb_unit_testr~      rl   r   c                  6   t         j                  j                  sddlm}   | dg      d   S t        t         j                  j                  d      j                  j                  dd      d         }d|v ryd|v ryd	|v ry
d|v ryd|v ryd|v ryd|v ryd|v ryy)z
    unit: MHz
    r   )nvsmizclocks.max.sm:r<   gfx94i  gfx90agfx908i  gfx12gfx11gfx103i  gfx101ix  gfx95iL  )
torchversionhiptriton.testingr   strcudaget_device_propertiesgcnArchNamesplit)r   gcn_archs     r   max_clock_rater      s    
 ==(o&'**
 uzz77:FFLLSRSTUVWXh!!  !! r   c                       y r   r&   r&   r   r   get_mast_job_name_versionr      rp   r   z	127.0.0.1i<s  profile_pathc                     t        d       y )Nz1Uploading profile stats (fb-only otherwise no-op))print)r   s    r   #maybe_upload_prof_stats_to_manifoldr     s    	
=>r   eventstacklogger_uuidstart_time_nsc                      y r   r&   )r   r   r   r   s       r   log_chromium_event_internalr     s     r   c                      y r   r&   )r   s    r   record_chromium_event_internalr     s     r   c                       yrn   r&   r&   r   r   1profiler_allow_cudagraph_cupti_lazy_reinit_cuda12r   !  rp   r   c                  Z    dt         t        t        f   dt         t        t        f   fd} | S )a  
    When we deprecate a function that might still be in use, we make it internal
    by adding a leading underscore. This decorator is used with a private function,
    and creates a public alias without the leading underscore, but has a deprecation
    warning. This tells users "THIS FUNCTION IS DEPRECATED, please use something else"
    without breaking them, however, if they still really really want to use the
    deprecated function without the warning, they can do so by using the internal
    function name.
    funcr   c                 
   | j                   j                  d      st        d      | j                   dd  }t        j                  | j
                     }t        ||      rt        d| d|j                    d      | j                   dd   d} t        j                  |t        d      |       }||_         d	| j                  v r+| j                  j                  d	d      d
   d	z   |z   |_        n||_        t        |||       | S )Nrg   z@deprecate must decorate a function whose name starts with a single leading underscore (e.g. '_foo') as the api should be considered internal for deprecation.r<   zCannot create alias 'z' -> symbol already exists in zP.                  Please rename it or consult a pytorch developer on what to doz= is DEPRECATED, please consider using an alternative API(s). )rG   
stacklevel.r   )__name__
startswith
ValueErrorr-   r.   
__module__hasattrRuntimeErrortyping_extensions
deprecatedUserWarning__qualname__rsplitsetattr)r   public_namer1   warning_msgaliass        r   	decoratorzdeprecated.<locals>.decorator0  s"   ((-B 
 mmAB'T__- 6;''}4RSYSbSbRc dO P 
 qr*++hi
!,,+!

 % $###!%!2!2!9!9#q!A!!Ds!J[!XE!,EU+r   rE   )r   s    r   r   r   %  s0    #R( #Xb"f-= #J r   c                       y)a  
    When using elastic agent, if no numa options are provided, we will use these
    as the default.

    For external use cases, we return None, i.e. no numa binding. If you would like
    to use torch's automatic numa binding capabilities, you should provide
    NumaOptions to your launch config directly or use the numa binding option
    available in torchrun.

    Must return None or NumaOptions, but not specifying to avoid circular import.
    Nr&   r&   r   r   get_default_numa_optionsr   X  s     r   failc                      y r   r&   )r   s    r   log_triton_buildsr   g  r(   r   c                       y)z<
    Allows overriding the binary used for subprocesses
    Nr&   r&   r   r   find_compile_subproc_binaryr   k  s     r   )r   N)T)MrB   loggingr   r-   r    r   typingr   r   r   r   r   r   (torch._strobelight.compile_time_profilerr   r	   r
   	getLoggerr   rL   environgetshutilwhichrM   enabler   r"   dirname__file__r   r   r   r   r$   r'   r+   r3   rF   dictrN   rR   rU   rX   rZ   r]   r_   rb   rd   rh   rk   boolro   rr   rw   rz   r>   r|   r~   cacher   tupler   TEST_MASTER_ADDRTEST_MASTER_PORTUSE_GLOBAL_DEPSUSE_RTLD_GLOBAL_WITH_LIBTORCHREQUIRES_SET_PYTHON_MODULEr   listr   r   r   r   r   r   r   r&   r   r   <module>r      sy     	 
   3 3 '  S T]t_g!::>>-u56<<'\	
 	KL-&--/ 77BGGOOH-.(:77??277??277??83L#MNL77??277??8#<=L8C 8C 8*c *c *;C ;C ;	c 	d 	"s "s "

//xB (2r6"223/L6S 6 6c3h 6	 	c 	 							s 
$ $ 	  	#   4s s    B8E#s(O#<      !& 
 # c hsm 
S>9  	S>0f	HSM 	Xc] r   