
    קg-                        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 d dl	Z	d dl
mZ  ej        e          Zej                            dd          rNd dlZ ej        d          se                    d           n$e                    d            ej                      e	j                    rd	Znej                            ej                            e                    d
k    rKej                            ej                            ej                            e                              Zn2ej                            ej                            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 Z"dededeeef         fdZ#d Z$d Z%d Z&d Z'd5dZ(d5dZ)defd Z*d! Z+ded"ed#ed$efd%Z,de-fd&Z. G d' d(          Z/	 d6dee         d*e-fd+Z0dede-fd,Z1dede2fd-Z3de-fd.Z4 e j5        d          d/             Z6d0Z7d1Z8d)Z9dZ:dZ;d2edee         fd3Z<d7d4Z=dS )8    N)AnyDictOptional)StrobelightCompileTimeProfiler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                  :    t          j        j        t          g| R  S N)ospathjointorch_parentr   s    Q/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/_utils_internal.pyget_file_pathr   +   s    7<77777    c                  (    t          j        j        |  S r   )r   r   r   r   s    r   get_file_path_2r   /   s    7<))r   r   c                     t          j        | t           j                  r| S t          j        t           j                            |                     S )N)suffix)r   accessW_OKtempfilemkdtempr   basenamer   s    r   get_writable_pathr!   3   sA    	yrw 27#3#3D#9#9::::r   c                     d S r    r    s    r   #prepare_multiprocessing_environmentr$   9       Dr   c                 @    t           j                            |           S r   )r   r   realpathr    s    r   resolve_library_pathr(   =   s    7D!!!r   c                 p    |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_errorr0   A   sh    !LLL
 
 	
 " > >GM> >4;> >
 
 	
r   c                       fd}|S )Nc                 J     t          j                    fd            }|S )Nc                  |    d|v r|d         dz   |d<   t           j        s | i |S t          j        g| R i |S )Nskip   )r   enabledprofile_compile_time)argskwargsfunction
phase_names     r   wrapper_functionzdcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_inner.<locals>.wrapper_functionQ   st    !'!!3v19 1x00001F*'+  /5  r   )	functoolswraps)r:   r<   r;   s   ` r   #compile_time_strobelight_meta_innerzJcompile_time_strobelight_meta.<locals>.compile_time_strobelight_meta_innerP   s?    		"	"		 		 		 		 		 
#	"		  r   r#   )r;   r?   s   ` r   compile_time_strobelight_metar@   O   s$              /.r   categoryname
parametersc                 @    t                               d| ||           d S )Nz	%s %s: %rloginfo)rA   rB   rC   s      r   signpost_eventrH   o   s     HH[(D*55555r   c                 <    t                               d|            d S )Nz%srE   )metricss    r   log_compilation_eventrK   s   s    HHT7r   c                     d S r   r#   )graphs    r   upload_graphrN   w   r%   r   c                      d S r   r#   r#   r   r   +set_pytorch_distributed_envs_from_justknobsrP   {   r%   r   c                      d S r   r#   )r9   s    r   log_export_usagerR      r%   r   c                      d S r   r#   r8   r9   s     r   log_trace_structured_eventrU      r%   r   c                      d S r   r#   rT   s     r   log_cache_bypassrW      r%   r   apic                 
    | }d S r   r#   )rX   r9   _s      r   log_torchscript_usager[      s    A
Fr   c                      dS NFr#   r#   r   r   check_if_torch_exportabler^          5r   type_of_exportexport_outcomeresultc                     | |||f\  }}}}d S r   r#   )rX   r`   ra   rb   rZ   s        r   !log_torch_jit_trace_exportabilityrd      s     nnf<JAq!Q
Fr   c                      dS r]   r#   r#   r   r   ,capture_pre_autograd_graph_using_training_irrf      r_   r   c                   V    e Zd ZdZdddddee         defdZdefd	Zd
 Z	d Z
d ZdS )JustKnobsConfiga  Represents a lazily loaded config

    This is designed to be used to specify a value in a config.

    i.e. foo.bar = JustknobsConfig(name="//foo:bar", env_name="FORCE_FOO_BAR")

    Call .get() in order to access the value
    i.e. if foo.bar.get():

    Note that the value is fetched once, and then not allowed to change. This
    means less suprises, at the downside that you may have to restart a job
    to pick up an update.

    It can also be set explicitly via set - i.e.
    foo.bar = JustknobsConfig(name="//foo:bar")
    foo.bar.set(True)

    Note that this does allow for no JK name (so that you can use this to replace old configurations).
    NT)rB   env_namedefaultrB   rj   c                L    || _         || _        || _        d | _        d | _        d S r   )rB   ri   rj   valueexecuted_value)selfrB   ri   rj   s       r   __init__zJustKnobsConfig.__init__   s.     	 %)
"r   rl   c                     || _         d S r   )rl   )rn   rl   s     r   setzJustKnobsConfig.set   s    


r   c                 v    | j         ,t          | j        | j        | j        | j                  | _         | j         S )N)config_valueri   rj   )rm   justknobs_featurerB   rl   ri   rj   rn   s    r   getzJustKnobsConfig.get   sA    &"3	!Z	# # #D ""r   c           	      \    t          |           }d| j         d| j         d| j         d| d	S )NzJustknobsConfig(name=z, env_name=z
, default=z - evals_to=))boolrB   ri   rj   )rn   vs     r   __str__zJustKnobsConfig.__str__   s?    JJttyttT]ttVZVbttpqttttr   c                 *    |                                  S r   )rv   ru   s    r   __bool__zJustKnobsConfig.__bool__   s    xxzzr   )__name__
__module____qualname____doc__r   strry   ro   rq   rv   r{   r}   r#   r   r   rh   rh      s         * (,dD# # #}#EI# # # #    # # #u u u    r   rh   Trj   c                    ||S |Ut          j        |          x}?|                                }|dv rdS |dv rdS t                              d|||            dS | dS |st          |            S t          |           S )a5  Returns whether or not a specific justknob feature is enabled.

    This is a slightly higher level API then justknobs_check, designed to make it "easy" to do the right thing.
    The primary thing it does, is allow configuration to override JK by default, while retaining some features to force this
    the other way during sevs.

    The preference order (i.e. who wins first) in OSS (and FB) is
    - Config if specified
    - Environment Variable if specified
    - JK (FB), or default (OSS)


    Quickstart
    Have a config variable
    Make a JK which is set to your "enabled" value (generally true).
    Use this feature to check it (if you set the JK to be false, change the default).
    If you have an env variable, also use the function to check it.

    Arguments:
        name - This should correspond 1:1 to a JK name internally to FB.
        env_name - If this is set, we'll try and read the value from environment variables
        config_value - If this is set to anything other than None, we'll use this value by
            default. Note that within FB, there is some functionality to force override these
            configs
        default - This is the value to return in OSS. This avoids having to write weird double
            negatives within justknobs and the config code, if you just want to have the
            killswitch work by having feature return True to turn off features

    Requirements:
        WARNING - Don't use this at import time - Simply pass in the existing config.
        If you want to use this at config time, use JustKnobsConfig
    N)1TRUET)0FALSEFzjDifficulty parsing env variable %s=%s for feature %s - Assuming env variable means true and returning True)r   getenvupperrF   errorjustknobs_check)rB   rs   ri   rj   envs        r   rt   rt      s    F 8)<)<"<#!Iiikk-4.  5		x		
 	
 	
 t|t )"4((((4   r   c                     d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.
    Tr#   rB   s    r   r   r     s	    . 4r   c                     dS )z)
    Read warning on justknobs_check
    r   r#   r   s    r   justknobs_getval_intr   )  s	     1r   c                      dS r]   r#   r#   r   r   is_fb_unit_testr   0  r_   r   c                  6   t           j        j        sddlm}   | dg          d         S t          t           j                            d          j        	                    dd          d                   }d|v rdS d|v rdS d	|v rd
S d|v rdS d|v rdS d|v rdS dS )Nr   )nvsmizclocks.max.sm:r5   gfx94i  gfx90agfx908i  gfx11gfx103i  gfx101ix  iL  )
torchversionhiptriton.testingr   r   cudaget_device_propertiesgcnArchNamesplit)r   gcn_archs     r   max_clock_rater   4  s    = ((((((uo&''**
 uz77::FLLSRSTTUVWXXh4!!4!!4  4!!4!!44r   z	127.0.0.1i<s  profile_pathc                 $    t          d           d S )Nz1Uploading profile stats (fb-only otherwise no-op))print)r   s    r   #maybe_upload_prof_stats_to_manifoldr   ^  s    	
=>>>4r   c                     d S r   r#   )eventstacklogger_uuidstart_timestamps       r   log_chromium_event_internalr   c  s    4r   )r   N)NNTr   )>r=   loggingr   r*   r   typingr   r   r   r   (torch._strobelight.compile_time_profilerr   	getLoggerr~   rF   environrv   shutilwhichrG   enable_running_with_deployr   r   r   dirname__file__r   r   r   r!   r$   r(   r0   r@   rH   rK   rN   rP   rR   rU   rW   r[   r^   rd   ry   rf   rh   rt   r   intr   r   	lru_cacher   TEST_MASTER_ADDRTEST_MASTER_PORTUSE_GLOBAL_DEPSUSE_RTLD_GLOBAL_WITH_LIBTORCHREQUIRES_SET_PYTHON_MODULEr   r   r#   r   r   <module>r      s        				 



  & & & & & & & & & &  S S S S S S g!!:>>-u55 	0MMM6<'' 0\	
 	
 	
 	
 	KLLL-&-/// 5 	B LL	w1122h>>wrwrwx7P7P'Q'QRRwrwx'@'@AA8C 8C 8 8 8 8*c *c * * * *;C ;C ; ; ; ;	c 	d 	 	 	 	"s "s " " " "

 

 

/ / /@6S 6 6c3h 6 6 6 6  	 	 		 	 		 	 		 	 	 		 	 	 	s    
  	  	   d    0 0 0 0 0 0 0 0h LP7! 7!
3-7!DH7! 7! 7! 7!t# $    4s s         T  4     !& 
 # c hsm    
     r   