
    ix                     <   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Zd dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZmZ d dlmZmZmZmZmZmZ d dlmZ d dl	mZ d dlmZ eee e d      e!e"e#e$e%f	Z& ed	eez  ez  dz  e!z  e"z  e#z  e$z  e%z  
      Z' e(       Z) ed       G d dee'                Z*er8e)dddddfde'e(z  de!dz  de!e"e!   z  dz  de!e"e!   z  dz  de dz  de!dz  de'fdZ+n:e)dddddfde'e(z  de!dz  de!e"e!   z  dz  de!e"e!   z  dz  de dz  de!dz  de*e'   fdZ+de!dee!z  dz  fdZ,deddfdZ-dZ.dede#e!   fdZ/e G d d             Z0 G d  d!e      Z1 G d" d#e jd                        Z2 G d$ d%      Z3d&e(de!d'e(de(fd(Z4d*de!dededz  fd)Z5y)+    N)Callable)	dataclass)FunctionType
ModuleType)AnyGenericNoReturnOptionalTYPE_CHECKINGTypeVar)
deprecated)mock)justknobs_checkT)boundT)kw_onlyc                       e Zd ZU dZeez  ed<   dZedz  ed<   dZ	e
e   dz  ed<   dZe
e   dz  ed<   dZedz  ed<   dZedz  ed<   dd
Zedee
e   z  dz  d	e
e   dz  fd       Zy)_Configa	  Represents a config with richer behaviour than just a default value.
    ::
        i.e.
        foo = Config(justknob="//foo:bar", default=False)
        install_config_module(...)

    This configs must be installed with install_config_module to be used

    Precedence Order:
        alias: If set, the directly use the value of the alias.
        env_name_force: If set, this environment variable has precedence over
            everything after this.
            If multiple env variables are given, the precedence order is from
            left to right.
        user_override: If a user sets a value (i.e. foo.bar=True), that
            has precedence over everything after this.
        env_name_default: If set, this environment variable will override everything
            after this.
            If multiple env variables are given, the precedence order is from
            left to right.
        justknob: If this pytorch installation supports justknobs, that will
            override defaults, but will not override the user_override precedence.
        default: This value is the lowest precedence, and will be used if nothing is
            set.

    Environment Variables:
        These are interpreted to be either "0" or "1" to represent true and false.

    Arguments:
        justknob: the name of the feature / JK. In OSS this is unused.
        default: is the value to default this knob to in OSS.
        alias: The alias config to read instead.
        env_name_force: The environment variable, or list of, to read that is a FORCE
            environment variable. I.e. it overrides everything except for alias.
        env_name_default: The environment variable, or list of, to read that changes the
            default behaviour. I.e. user overrides take preference.
    defaultNjustknobenv_name_defaultenv_name_force
value_typealiasreturnc                 0   t         j                  | j                        | _        t         j                  | j                        | _        | j                  B| j
                  t        us$| j                  | j                  | j                  t        d      y y )Nztif alias is set, none of {default, justknob,                         env_name_default and env_name_force} can be set)	r    string_or_list_of_string_to_listr   r   r   r   _UNSET_SENTINELr   AssertionErrorselfs    T/var/www/html/engine/venv/lib/python3.12/site-packages/torch/utils/_config_module.py__post_init__z_Config.__post_init__O   s     ' H H!!!
 &FF
 ::!O3==,((4&&2$I  3 "    valc                     | y t        | t              r| gS t        | t              st        dt	        |              | S )Nzval is not a list, got )
isinstancestrlistr   type)r%   s    r"   r   z(_Config.string_or_list_of_string_to_listc   sC     ;c35L#t$ #:49+!FGG
r$   r   N)__name__
__module____qualname____doc__r   object__annotations__r   r(   r   r)   r   r   r*   r   r#   staticmethodr    r$   r"   r   r       s    $L ZHcDj)-d3i$&-'+NDI$+"Jt"E3:( 	49_t#		cT		 	r$   r   r   r   r   r   r   r   r   c                      y Nr3   r   r   r   r   r   r   s         r"   Configr7   v   s     r$   c                 $    t        | |||||      S )Nr6   )r   r6   s         r"   r7   r7      s#     -)!
 	
r$   namec                 \    t         j                  j                  |       }|dk(  ry|dk(  ry|S N1T0Fosenvironget)r9   values     r"   _read_env_variablerC      s-    JJNN4 E||Lr$   modulec                       G d dt               }dt        t        z  dt        t        z  dt        ddf fdi t               }   d	        _        | _        | _        d
 _	        d _
        y)z
    Converts a module-level config into a `ConfigModule()`.

    See _config_typing.pyi for instructions on how to get the converted module to typecheck.
    c                        e Zd Z eh d      Zy)3install_config_module.<locals>.ConfigModuleInstance>   	_is_dirty_hash_digestr1   N)r,   r-   r.   set_bypass_keysr3   r$   r"   ConfigModuleInstancerG      s    KLr$   rL   sourcedestprefixr   Nc                    t        j                  |       }t        | j                  j	                               D ]  \  }}|j                  d      slt        |t        t        f      sVt        |d      r*|j                  dk(  s;|j                  j                  d      s t        |t              rt        |t              r| | }|j                  |d      }t        |t              r+t!        t        ||            	|<   |
u st#        
|       t        |t              r7||j$                  ||_        t!        |      	|<   |
u st#        
|       t        |t              rt|j                  
j&                  k7  rt)        d| d
j&                         t+        
| d	      } ||| d	       |
u rt-        |||       ||j                  |<   t)        d
| d| dt        |       d       y)z?Walk the module structure and move everything to module._config__r-   typingzcollections.abcN)r   r   zsubconfig class z must be defined in module .zUnhandled config =z ())inspectget_annotationsr)   __dict__items
startswithr'   r   r   hasattrr-   r*   
issubclassr   rA   CONFIG_TYPES_ConfigEntrydelattrr   r,   r   SubConfigProxysetattr)rM   rN   rO   
type_hintskeyrB   r9   annotated_typeproxyconfigrD   visits            r"   rg   z$install_config_module.<locals>.visit   s    ,,V4
v4467 -	XJCt$ej,%?@E<0((H4 ++667HI ud+
5'0JXcU#D'^^C6N%.+EnE t 6>FC(E7+!-%2B2B2J'5E$+E2t6>FC(E4(##v6(*5'1LV__L]^  'v$qz:eUtfAJ/6>D#u-).DMM#&$'8QugRU}TU%VWW[-	Xr$    T)ConfigModuler   r*   r`   r(   -get_assignments_with_compile_ignored_comments_config_compile_ignored_keys	__class__rH   rI   )rD   rL   compile_ignored_keysrf   rg   s   `  @@r"   install_config_modulero      s    M| M4XT!4X>)4X 4X 
	4Xl ')FHP	&&"FN#7F +FFFr$   z@compile_ignoredc                 
   t        j                  |       }t               }t        j                  t	        j
                  |j                  d            j                        }d}d}|D ]  }|j                  t        j                  k(  rNd}|j                  j                         }t        |v sF|dk7  rt        dt               ||j                  d   f}o|j                  t        j                  k(  r|r|j                  }|j                  t        j                   k(  s|j                  dk(  st        |d   v r+|d   |j                  d   dz
  k(  r|j#                  |       d}d} |dk7  rt        dt               |S )Nutf-8)rh   rh   zunconsumed r   rT      )rV   	getsourcerJ   tokenizeioBytesIOencodereadliner*   COMMENTstringstripCOMPILE_IGNORED_MARKERr   startNAMEOPadd)rD   source_codeassignmentstokenscurrent_comment	prev_nametokenmaybe_currents           r"   rj   rj      sY   ##F+K%K rzz+*<*<W*EFOOPFOI ::)))I!LL..0M%6"h.(;7M6N)OPP"/Q"?ZZ8==( !LL	ZZ8;;&5<<3+> '/!*<<#A&%++a.1*<<	*"(I-. ("{+A*BCDDr$   c                       e Zd ZU eed<   eed<   eZeed<   dZe	dz  ed<   eZ
eed<   eZeed<   dZeed	<   dZe	dz  ed
<   deddfdZy)r^   r   r   user_overrideNr   env_value_forceenv_value_defaultFhider   rf   r   c                    |j                   | _         |j                  |j                  nt        | j                         | _        |j                  | _        |j                  | _        |j
                  '|j
                  D ]  }t        |      x}|| _         n |j                  '|j                  D ]  }t        |      x}|| _	         n | j                  ?| j                   3t        | j                   t              st        d| j                    d      | j                  c|j
                  |j                  J| j                  t        t        t        t           t        t           fvrt        d| j                   d      y y y )Nz!justknobs only support booleans, z is not a booleanz<envvar configs only support (optional) booleans or strings, z is neither)r   r   r*   r   r   r   rC   r   r   r   r'   boolr   r(   r
   )r!   rf   r%   	env_values       r"   __init__z_ConfigEntry.__init__.  s   ~~!'!2!2!>FDDV 	 \\
""... !3C!88IE-6D*   ,,, !3C!88IE+4D( ==$)AdllD1$7~EVW  ??&##/63H3H3T	'  %RSWSbSbRccno  4U 'r$   )r,   r-   r.   r   r1   r*   r   r   r   r(   r   r   r   r   r   r   r   r3   r$   r"   r^   r^     sk     L )M3(HcDj*OS*,s, D$E3:#w #4 #r$   r^   c                       e Zd ZU eeef   ed<   ee   ed<   ee   ed<   eed<   e	dz  ed<   d1dZ
d	ed
eddf fdZd	edefdZd	eddfdZdedeeef   dz  fdZdedefdZdededdfdZd	edefdZ	 	 	 d2dee   dz  dee   dz  dedeeef   fdZdedefdZde	fdZdddedeeef   fdZdefdZde	fd Z ed!e"      deeef   fd#       Z  ed$e"      deeef   fd%       Z!d&e	eeef   z  ddfd'Z"deeef   fd(Z#deeef   fd)Z$	 	 d3d*eeeef   z  dz  d+ed,eeef   dd-fd.Z%d/eeef   defd0Z& xZ'S )4ri   rk   rK   rl   rH   NrI   r   c                 (    t        dt         d      )Nzuse z-.install_config_module(sys.modules[__name__]))NotImplementedErrorr,   r    s    r"   r   zConfigModule.__init__`  s    !8*IJ
 	
r$   r9   rB   c                 f   || j                   v rt        | 	  ||       y || j                  vrt	        | j
                   d| d      | j                  |   j                   | j                  | j                  |   |       y || j                  |   _        d| _	        d| j                  |   _
        y )NrS    does not existTF)rK   super__setattr__rk   AttributeErrorr,   r   _set_alias_valr   rH   r   )r!   r9   rB   rm   s      r"   r   zConfigModule.__setattr__e  s    4$$$Ge,% DMM?!D6!IJJ\\$%%1T 2E:/4DLL,!DN&+DLL#r$   c                    	 | j                   |   }|j                  rt        | j                   d| d      | j	                  |      }|t
        ur|S |j                  t
        ur|j                  S |j                  t
        ur|j                  S |j                  t
        ur|j                  S |j                  !t        |j                  |j                        S t        |j                  t        t        t        f      r0t!        j"                  |j                        |_        |j                  S |j                  S # t$        $ r!}t        | j                   d| d      |d }~ww xY w)NrS   r   )r9   r   )rk   r   r   r,   _get_alias_valr   r   r   r   r   r   r   r'   r)   rJ   dictcopydeepcopyKeyError)r!   r9   rf   	alias_vales        r"   __getattr__zConfigModule.__getattr__q  s7   !	R\\$'F{{$av_%MNN++F3I/  %%_<---##?:+++''>///*&FOOV^^TT
 &..4d*;<'+}}V^^'D$+++>>! 	R DMM?!D6!IJPQQ	Rs=   AD; D; 1D; D; -,D; AD; /D; ;	E%E  E%c                 j    d| _         t        | j                  |   _        d| j                  |   _        y NT)rH   r   rk   r   r   r!   r9   s     r"   __delattr__zConfigModule.__delattr__  s-     ,;T("&Tr$   entryc                     |j                   }|y |j                  dd      \  }}	 t        j                  |      }||fS # t        $ r}t        d| d      |d }~ww xY w)NrS   rs   zconfig alias r   )r   rsplit	importlibimport_moduleImportErrorr   )r!   r   r   module_nameconstant_namerD   r   s          r"   _get_alias_module_and_namez'ConfigModule._get_alias_module_and_name  sw     =%*\\#q%9"]	P,,[9F }$$  	P =!GHaO	Ps   ? 	AAAc                 Z    | j                  |      }|t        S |\  }}t        ||      }|S r5   )r   r   getattr)r!   r   datarD   r   constant_values         r"   r   zConfigModule._get_alias_val  s9    ..u5<"" $ 7r$   r%   c                 d    | j                  |      }|t        d      |\  }}t        |||       y )Nz6alias data should not be None when setting alias value)r   r   ra   )r!   r   r%   r   rD   r   s         r"   r   zConfigModule._set_alias_val  s?    ..u5< H  !%s+r$   c                    | j                   |   }|j                  t        u xs |j                  |j                  k(  }|j                  t        u xs |j                  |j                  k(  }|j
                  t        u }t        |j                  t        t        t        f      r|xs |j
                  |j                  k(  }|xr |xr |S )z
        Returns true if the config is at its default value.
        configs overridden by the env are not considered default.
        )
rk   r   r   r   r   r   r'   r)   rJ   r   )r!   r9   
config_valnot_set_env_defaultnot_set_env_forceunsets         r"   _is_defaultzConfigModule._is_default  s    
 \\$'

 ((O; B++z/A/AA 	
 &&/9 @))Z-?-?? 	
 ((O;j((4d*;<KZ559K9KKEB,B1BBr$   ignored_keysignored_prefixesskip_defaultc                 
   i }| j                   D ]p  |r|v r
|rt        fd|D              r!|r| j                        r5| j                      j                  Ot	        j
                  t        |             |<   r |S )a  Export a dictionary of current configuration keys and values.

        This function is design to provide a single point which handles
        accessing config options and exporting them into a dictionary.
        This is used by a number of different user facing export methods
        which all have slightly different semantics re: how and what to
        skip.
        If a config is aliased, it skips this config.

        Arguments:
            ignored_keys are keys that should not be exported.
            ignored_prefixes are prefixes that if a key matches should
                not be exported
            skip_default does two things. One if a key has not been modified
                it skips it.
        c              3   @   K   | ]  }j                  |        y wr5   )rZ   ).0rO   rc   s     r"   	<genexpr>z)ConfigModule._get_dict.<locals>.<genexpr>  s     M&s~~f-Ms   )rk   anyr   r   r   r   r   )r!   r   r   r   rf   rc   s        @r"   	_get_dictzConfigModule._get_dict  s    , "$<< 
	<C| 3M<LMM 0 0 5||C &&2--c(:;F3K
	< r$   config_namec                 4    | j                   |   j                  S r5   )rk   r   )r!   r   s     r"   get_typezConfigModule.get_type  s    ||K(333r$   c                 j    t        | dg       }t        j                  | j                  |      d      S )z Convert config to a pickled blob_save_config_ignorer      )protocol)r   pickledumpsr   )r!   r   s     r"   save_configzConfigModule.save_config  s3    t%:B?||NNN5
 	
r$   T)ignore_private_configsr   c                    g }|r|j                  d       |j                  t        | dg              | j                  |      S )z!Convert config to portable format__cache_config_ignore_prefix)r   )appendextendr   r   )r!   r   prefixess      r"   save_config_portablez!ConfigModule.save_config_portable  s?     !OOC &CRHI~~x~88r$   c                   	
 t               
dt        dt        dt        fddt        ddf
fddt        t         z  dt        t           ffddt
        dt        fd		dt        f	fd
}g }| j                  }| j                  t        | dg       d      j                         D ]  \  }}|j                   ||||               
D ]  }|j                  dd|         dj                  |      S )zConvert config to Python statements that replicate current config.
        This does NOT include config settings that are at default values.
        funcadd_dotr   c                 D    | j                   }|dk(  rd}|r
|dk7  r|dz  }|S )Nbuiltinsrh   rS   )r-   )r   r   r   s      r"   get_module_namez4ConfigModule.codegen_config.<locals>.get_module_name  s2    //Kj( ;",s"r$   Nc                 @     | d      }|rj                  |       y y )NF)r   )r   r   r   importss     r"   
add_importz/ConfigModule.codegen_config.<locals>.add_import  s#    )$6KK( r$   vc                 X    | D cg c]  } |d       |j                     c}S c c}w r   )r,   )r   itemr   s     r"   list_of_callables_to_stringz@ConfigModule.codegen_config.<locals>.list_of_callables_to_string!  s,    PQRtT23DMM?CRRRs   'c                 P    t        |       xr t        | d      xr t        | d      S )Nr-   r,   )callabler[   )r   s    r"   importable_callablez8ConfigModule.codegen_config.<locals>.importable_callable$  s$    A;V71l#;V:@VVr$   c                 \    |      r% |       |  d| d |d       |j                    S t        |t        t        f      r_t	        fd|D              rK|D ]
  } |         |      }t        |t              r
|  d| d| S |  d| ddj                  |       dS |  d| d|S )a  
            Return a string version of the config line.
            Handle v when v is a callable, or a list/dict of callables. Add import statements for callables if necessary.
            We assume that the value of a single config won't be a mix of callables and non-callables.

            Example output:
                import logging
                import _warnings
                torch._dynamo.config.reorderable_logging_functions = { _warnings.warn, logging.warn, print }
            rS   z = Tc              3   .   K   | ]  } |        y wr5   r3   )r   r   r   s     r"   r   zGConfigModule.codegen_config.<locals>.get_config_line.<locals>.<genexpr>6  s      4.2#D)4s   z = { z, z })r,   r'   r)   rJ   alljoin)	modkr   r   v_listr   r   r   r   s	        r"   get_config_linez4ConfigModule.codegen_config.<locals>.get_config_line(  s     #1%1as#oa&>%?

|LLAc{+ 4674 1  %Dt$%4Q7a&!U!A3c&22!U!A3fTYYv->,?sCCas#aU++r$   r   T)r   r   r   zimport 
)rJ   r   r   r(   r)   r   r,   r   r   rY   r   insertr   )r!   r   linesr   r   r   import_namer   r   r   r   r   s          @@@@@r"   codegen_configzConfigModule.codegen_config  s    %	( 	T 	c 		)X 	)$ 	)
	S4#: 	S$s) 	S	W3 	W4 	W	,# 	, 	,6 mmNN '<bAPT # 

%'	5DAq LLa34	5 # 	5KLLgk]34	5yyr$   c                 X   | j                   s| j                  | j                  t        | j                              }t        t        |j                                     }t        j                  |j                  d      d      j                         | _        d| _         | j                  S )z/Hashes the configs that are not compile_ignoredr   rq   F)usedforsecurity)rH   rI   r   r)   rl   reprsortedrY   hashlibmd5rx   digest)r!   dict_to_hashstring_to_hashs      r"   get_hashzConfigModule.get_hashM  s    >>T..6>>tD<V<V7W>XL!&););)=">?N '%%g.!fh  #DN   r$   z`config.to_dict()` has been deprecated. It no longer changes the underlying config. use `config.get_config_copy()` instead if you just want a copy of the config, or config.load_config if you need mutable access)categoryc                 "    | j                         S r5   get_config_copyr    s    r"   to_dictzConfigModule.to_dictX       ##%%r$   z`config.shallow_copy_dict()` has been deprecated. It no longer changes the underlying config. use `config.get_config_copy()` instead if you just want a copy of the config, or config.load_config if you need mutable accessc                 "    | j                         S r5   r  r    s    r"   shallow_copy_dictzConfigModule.shallow_copy_dicta  r  r$   maybe_pickled_configc                     t        |t              st        j                  |      }n|}|j	                         D ]6  \  }}|| j
                  v rt        | ||       "ddlm}  |d| d| d       8 y)zARestore from a prior call to save_config() or shallow_copy_dict()r   )	warn_oncezkey z with value z! is not understood by this configN)	r'   r   r   loadsrY   rk   ra   torch._dynamo.utilsr	  )r!   r  rf   r   r   r	  s         r"   load_configzConfigModule.load_configj  so    .5\\"67F)FLLN 	VDAqDLL a#9D<s2STU	Vr$   c                 "    | j                         S r5   )r   r    s    r"   r  zConfigModule.get_config_copyx  s    ~~r$   c                 <    | j                  t        | dg             S )Nr   r   )r   r   r    s    r"   get_serializable_config_copyz)ConfigModule.get_serializable_config_copy{  s    ~~749NPR+S~TTr$   arg1arg2kwargsContextDecoratorc                 L   |L| t        |t              st        d      ||int        |t              st        d      ||rt        d      ||t        d      t        t              st        dt	                     i |  G fddt
              } |       S )a  
        Decorator and/or context manager to make temporary changes to a config.

        As a decorator:

            @config.patch("name", val)
            @config.patch(name1=val1, name2=val2)
            @config.patch({"name1": val1, "name2", val2})
            def foo(...):
                ...

        As a context manager:

            with config.patch("name", val):
                ...
        zGfirst argument must be a string when passing 2 positional args to patchzKfirst argument must be a dict when passing a single positional arg to patchz:cannot pass both positional and keyword arguments to patchzLsecond positional argument is only valid when first argument is a key stringzexpected `dict` got c                   4    e Zd Zd fdZdfdZfdZy)'ConfigModule.patch.<locals>.ConfigPatchNc                     | _         y r5   )changes)r!   r  s    r"   r   z0ConfigModule.patch.<locals>.ConfigPatch.__init__  s
    &r$   c                     rt        d      | j                  D ]  }j                  |      |<    | j                  j                         D ]  \  }}j	                  ||        y )Nz/prior should be empty when entering ConfigPatch)r   r  r   rY   r   )r!   rc   r   r   rf   priors       r"   	__enter__z1ConfigModule.patch.<locals>.ConfigPatch.__enter__  sq    (I   << 9C!'!3!3C!8E#J9 !LL..0 -DAq&&q!,-r$   c                 z    j                         D ]  \  }}j                  ||        j                          y r5   )rY   r   clear)r!   exc_typeexc_valexc_tbr   r   rf   r  s         r"   __exit__z0ConfigModule.patch.<locals>.ConfigPatch.__exit__  s5    !KKM -DAq&&q!,-r$   r+   )r,   r-   r.   r   r  r!  )r  rf   r  s   r"   ConfigPatchr    s    '	-r$   r"  )r'   r(   r   r   r*   r  )r!   r  r  r  r"  r  rf   r  s        @@@r"   patchzConfigModule.patch~  s    . !$,(a   ,!$-(e  $P 
 G$b  '4( #7W!GHH "	 	* 	( }r$   r  c                 J      j                   dt        g df   f fd}|S )aV  
        A lower-overhead version of patch() for things on the critical path.

        Usage:

            # do this off the critical path
            change_fn = config.make_closure_patcher(foo=True)

            ...

            revert = change_fn()
            try:
              ...
            finally:
                revert()

        r   Nc                      D  ci c]  } | |    j                    c} j                         D ]  \  } }|j                  |    _          dfd}|S c c} w )Nc                  ^    j                         D ]  \  } }|j                  |    _         y r5   )rY   rk   r   )r   r   r  r!   s     r"   revertzBConfigModule._make_closure_patcher.<locals>.change.<locals>.revert  s,    !KKM 6DAq45DLLO16r$   r+   )r   rY   rk   )r   r   r'  r  r  rf   r!   s      @r"   changez2ConfigModule._make_closure_patcher.<locals>.change  s]    9@AAQq	///AE 2101Q-26 M Bs   A)rk   r   )r!   r  r(  rf   s   `` @r"   _make_closure_patcherz"ConfigModule._make_closure_patcher  s*    $ 		T* 		 r$   r+   )NNF)NN)(r,   r-   r.   r   r(   r^   r1   rJ   r   bytesr   r0   r   r   r   r   tupler   r   r   r   r   r)   r   r*   r   r   r   r   r   r   FutureWarningr  r  r  r  r  r#  r)  __classcell__rm   s   @r"   ri   ri   T  s    #|#$$c(s8#O$,


, 
,F 
,t 
,"R "R "RH' ' '%!%	z3	$	&%L S ,L ,s ,t ,C C C4 *.-1"	#3i$&# s)d*# 	#
 
c3h#J4C 4D 4
U 
 159)-9	c3h9?  ? B	!% 	! 	8 	&c3h && 	8 	&4S> &&VS#X0F V4 V c3h  Ud38n U
 -1JDcN"T)J J sCx.	J
 
JXtCH~ # r$   ri   c                   L     e Zd ZdZddZdefdZdeegef   def fdZ	 xZ
S )r  z[
    Same as contextlib.ContextDecorator, but with support for
    `unittest.TestCase`
    r   c                     t        d      NNYIr   r    s    r"   r  zContextDecorator.__enter__      !%((r$   c                     t        d      r1  r3  )r!   r  r  r   s       r"   r!  zContextDecorator.__exit__  r4  r$   r   c                      t        |t              r\t        |t        j                        rB G  fdd|      }|j
                  |_        |j                  |_        |j                  |_        |S t         %  |      S )Nc                   F     e Zd Zed fd       Zed fd       Z xZS ),ContextDecorator.__call__.<locals>._TestCasec                     j                          	 t        | 	          y # t        $ r j	                  d d d         w xY wr5   )r  r   
setUpClass	Exceptionr!  clsrm   r!   s    r"   r:  z7ContextDecorator.__call__.<locals>._TestCase.setUpClass  s?    NN$*,$ dD$7s	   " A c                 z    	 t         |           j                  d d d        y # j                  d d d        w xY wr5   )r   tearDownClassr!  r<  s    r"   r?  z:ContextDecorator.__call__.<locals>._TestCase.tearDownClass  s4    8-/dD$7dD$7s   % :r+   )r,   r-   r.   classmethodr:  r?  r-  )rm   r!   s   @r"   	_TestCaser8    s)      8 8r$   rA  )
r'   r*   r\   unittestTestCaser,   r.   r-   r   __call__)r!   r   rA  rm   s   `  r"   rD  zContextDecorator.__call__  sf    dD!jx7H7H&I8D 8" "&I%)%6%6I"#'??I w%%r$   r+   )r,   r-   r.   r/   r  r	   r!  r   r   rD  r-  r.  s   @r"   r  r    s<    
))X )&XseSj1 &c & &r$   r  c                   d     e Zd ZdZdededdf fdZdededdfd	Zdedefd
Z	deddfdZ
 xZS )r`   zn
    Shim to redirect to main config.
    `config.triton.cudagraphs` maps to _config["triton.cudagraphs"]
    rf   rO   r   Nc                 F    t         |   d|       t         |   d|       y )Nrk   _prefix)r   r   )r!   rf   rO   rm   s      r"   r   zSubConfigProxy.__init__  s!    Iv.Iv.r$   r9   rB   c                 T    | j                   j                  | j                  |z   |      S r5   )rk   r   rG  )r!   r9   rB   s      r"   r   zSubConfigProxy.__setattr__   s"    ||''t(;UCCr$   c                 R    | j                   j                  | j                  |z         S r5   )rk   r   rG  r   s     r"   r   zSubConfigProxy.__getattr__#       ||''t(;<<r$   c                 R    | j                   j                  | j                  |z         S r5   )rk   r   rG  r   s     r"   r   zSubConfigProxy.__delattr__&  rJ  r$   )r,   r-   r.   r/   r0   r(   r   r   r   r   r   r-  r.  s   @r"   r`   r`     sf    
/v /s /t /
D DF Dt D= = == = =r$   r`   objrB   c                     t        | t              r| j                  ||      S t        j                  j	                  | ||      S )z@
    Workaround `mock.patch.object` issue with ConfigModule
    )r'   ri   r#  r   r0   )rL  r9   rB   s      r"   patch_objectrN  *  s8     #|$yyu%%::S$..r$   c                 \    t         j                  j                  |       }|dk(  ry|dk(  ry|S r;   r>   )r9   r   rB   s      r"   get_tristate_envrP  3  s-    JJNN4 E||Nr$   r5   )6
contextlibr   r   r   rV   rv   r?   r   ru   rB  collections.abcr   dataclassesr   typesr   r   rR   r   r   r	   r
   r   r   typing_extensionsr   r   torch._utils_internalr   intfloatr   r*   r(   r)   rJ   r+  r   r]   r   r0   r   r   r7   rC   ro   r}   rj   r^   ri   r  r`   rN  rP  r3   r$   r"   <module>rY     s        	 	    $ ! * K K (  1 UD$t*c4eTJ CsU{T)D036=CeKdRS ( 4Lgaj L Lf  .#3715"& V* S	/D0 d3i$.	
 4K Tz 
 .#3715"& 
V
*
 S	/D0
 d3i$.	

 4K
 Tz
 

$S TCZ$%6 J* J JZ , "* "S "J > > >BU: Up&&z22 &&R= =*/f /C / /6 /3  t r$   