
    Pg                         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	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.                  j1                  dd      rJd dlZ ej4                  d	      sej7                  d
       n"ej7                  d        ej8                           ej:                         rdZnej>                  jA                  ej>                  jC                  e"            dk(  rNej>                  jC                  ej>                  jC                  ej>                  jC                  e"                  Zn4ej>                  jC                  ej>                  jC                  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 Z,d Z-d Z.d  Z/d=d!Z0d=d"Z1d#e#fd$Z2d% Z3de4fd&Z5d#e#d'e#d(e#d)e#fd*Z6de4fd+Z7d>de#d-e4de4fd.Z8de#de9fd/Z:de4fd0Z; e jx                  d      d1        Z=de
ee#e9f      fd2Z>d3Z?d4Z@d,ZAdZBdZCd5e#de
e#   fd6ZDd7ee#ef   d8e	e#   d9e#d:e9fd;ZEd7ee#ef   fd<ZFy)?    N)AnyCallableDictListOptionalTuple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    \/var/www/html/suriana-translation/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   3   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(   7   s9    	yyrww277#3#3D#9::r   c                      y r    r'   s    r   #prepare_multiprocessing_environmentr+   =       r   c                 @    t         j                  j                  |       S r   )r   r   realpathr'   s    r   resolve_library_pathr/   A   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_errorr7   E   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)r<   r=   r?   r:   r8   s      r   wrapper_functionzdcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_inner.<locals>.wrapper_functionY   sk    Jvf~/Ets$K!%v1990001FF*'+/5 r   )	functoolswrapsr   r<   r=   r   )r:   rE   r8   s   ` r   #compile_time_strobelight_meta_innerzJcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_innerV   sE     
	"		BGG 		ryy 		R 		 
#		  r   )r   r   r   )r8   rH   s   ` r   compile_time_strobelight_metarI   S   s2     2r6" 	"b&	 " /.r   categoryname
parametersc                 4    t         j                  d| ||       y )Nz	%s %s: %rloginfo)rJ   rK   rL   s      r   signpost_eventrQ   w   s    HH[(D*5r   c                 0    t         j                  d|        y )Nz%srN   )metricss    r   log_compilation_eventrT   {   s    HHT7r   c                      y r   r*   )graphs    r   upload_graphrW      r,   r   c                       y r   r*   r*   r   r   +set_pytorch_distributed_envs_from_justknobsrY      r,   r   c                       y r   r*   )r=   s    r   log_export_usager[      r,   r   c                       y r   r*   r<   r=   s     r   log_trace_structured_eventr^      r,   r   c                       y r   r*   r]   s     r   log_cache_bypassr`      r,   r   apic                     | }y r   r*   )ra   r=   _s      r   log_torchscript_usagerd      s
    A
r   c                       yNFr*   r*   r   r   check_if_torch_exportablerg          r   c                       y)NTr*   r*   r   r    export_training_ir_rollout_checkrj          r   type_of_exportexport_outcomeresultc                     | |||f\  }}}}y r   r*   )ra   rl   rm   rn   rc   s        r   !log_torch_jit_trace_exportabilityrp      s     nnf<JAq!Q
r   c                       yrf   r*   r*   r   r   ,capture_pre_autograd_graph_using_training_irrr      rh   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*   )rK   rs   s     r   justknobs_checkru      s	    . Nr   c                      y)z)
    Read warning on justknobs_check
    r   r*   )rK   s    r   justknobs_getval_intrw      s     r   c                       yrf   r*   r*   r   r   is_fb_unit_testry      rh   r   c                  "   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y)Nr   )nvsmizclocks.max.sm:r@   gfx94i  gfx90agfx908i  gfx11gfx103i  gfx101ix  iL  )
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      rk   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   )r   N)T)GrF   loggingr   r1   r$   typingr   r   r   r   r   r   r	   typing_extensionsr
   r   (torch._strobelight.compile_time_profilerr   r   r   	getLogger__name__rO   environgetshutilwhichrP   enable_running_with_deployr   r   r&   dirname__file__r   r   r   r(   r+   r/   r7   rI   rQ   rT   rW   rY   r[   r^   r`   rd   rg   boolrj   rp   rr   ru   rB   rw   ry   	lru_cacher   r   TEST_MASTER_ADDRTEST_MASTER_PORTUSE_GLOBAL_DEPSUSE_RTLD_GLOBAL_WITH_LIBTORCHREQUIRES_SET_PYTHON_MODULEr   r   r   r*   r   r   <module>r      sG     	 
  F F F '  S T]t_g!::>>-u56<<'\	
 	KL-&--/ 5 L	ww12h>wwrwwrwwx7P'QRwwrwwx'@A8C 8C 8*c *c *;C ;C ;	c 	d 	"s "s "

//xB (2r6"223/H6S 6 6c3h 6					s 
$ 	  	d #   4s s   T 48E#s(O#<      !& 
 # c hsm 
S>9  	S>r   