
    ΅ix                     N   S SK r S SKrS SKrS SKrS SKr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  S SKJr  S SKJrJr  S SKJr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  \\\\ " S5      \!\"\#\$\%4	r&\" S	\\-  \-  \!-  \"-  \#-  \$-  \%-  S-  S
9r'\(" 5       r)\" SS9 " S S\\'   5      5       r*\(       a:  \)SSSSS4S\'\(-  S\!S-  S\!\"\!   -  S-  S\!\"\!   -  S-  S\ S-  S\!S-  S\'4S jjr+O<\)SSSSS4S\'\(-  S\!S-  S\!\"\!   -  S-  S\!\"\!   -  S-  S\ S-  S\!S-  S\*\'   4S jjr+S\!S\\!-  S-  4S jr,S\SS4S jr-Sr.S\S\#\!   4S jr/\ " S S5      5       r0 " S  S!\5      r1 " S" S#\ Rd                  5      r2 " S$ S%5      r3S&\(S\!S'\(S\(4S( jr4S*S\!S\S\S-  4S) jjr5g)+    N)Callable)	dataclass)FunctionType
ModuleType)AnyGenericNoReturnOptionalTYPE_CHECKINGTypeVar)
deprecated)mock)justknobs_checkT)boundT)kw_onlyc                       \ rS rSr% Sr\\-  \S'   Sr\	S-  \S'   Sr
\\	   S-  \S'   Sr\\	   S-  \S'   Sr\S-  \S'   Sr\	S-  \S	'   SS jr\S\	\\	   -  S-  S
\\	   S-  4S j5       rSrg)_Config    a  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                 :   [         R                  U R                  5      U l        [         R                  U R                  5      U l        U R                  bF  U R
                  [        Ld'  U R                  c  U R                  c  U R                  b  [        S5      eg g )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/home/james-whalen/.local/lib/python3.13/site-packages/torch/utils/_config_module.py__post_init___Config.__post_init__O   s     ' H H!!!
 &FF
 ::!O3==,((4&&2$I  3 "    valc                     U c  g [        U [        5      (       a  U /$ [        U [        5      (       d  [        S[	        U 5       35      eU $ )Nzval is not a list, got )
isinstancestrlistr    type)r'   s    r#   r   (_Config.string_or_list_of_string_to_listc   sI     ;c35L#t$$ #:49+!FGG
r&   )r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   object__annotations__r   r*   r   r+   r   r   r,   r   r$   staticmethodr   __static_attributes__ 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                     g Nr8   r   r   r   r   r   r   s         r#   Configr<   v   s     r&   c           	          [        U UUUUUS9$ )Nr;   )r   r;   s         r#   r<   r<      s#     -)!
 	
r&   namec                 `    [         R                  R                  U 5      nUS:X  a  gUS:X  a  gU$ N1T0Fosenvironget)r>   values     r#   _read_env_variablerH      s-    JJNN4 E||Lr&   modulec                    ^ ^^  " S S[         5      nS[        [        -  S[        [        -  S[        SS4UU U4S jjm0 m[        T 5      nT" T T S	5        TT l        UT l        UT l        S
T l	        ST l
        g)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                   (    \ rS rSr\" 1 Sk5      rSrg)3install_config_module.<locals>.ConfigModuleInstance   >   	_is_dirty_hash_digestr5   r8   N)r/   r0   r1   r2   set_bypass_keysr7   r8   r&   r#   ConfigModuleInstancerL      s    KLr&   rR   sourcedestprefixr   Nc                 b  > [         R                  " U 5      n[        U R                  R	                  5       5       GH  u  pEUR                  S5      (       d  [        U[        [        45      (       dk  [        US5      (       a0  UR                  S:X  dJ  UR                  R                  S5      (       d*  [        U[        5      (       a  [        U[        5      (       a  M  U U 3nUR                  US5      n[        U[        5      (       a*  [!        [        XWS95      T	U'   UT
L a  [#        T
U5        M  M  [        U[        5      (       a;  Ub  UR$                  c  Xul        [!        U5      T	U'   UT
L a  [#        T
U5        GMH  GMK  [        U[        5      (       au  UR                  T
R&                  :w  a  [)        SU ST
R&                   35      e[+        T
U S	35      nT" XXU S	35        UT
L a  [-        XU5        GM  XR                  U'   GM  [)        S
U SU S[        U5       S35      e   g)z?Walk the module structure and move everything to module._config__r0   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   hasattrr0   r,   
issubclassr   rF   CONFIG_TYPES_ConfigEntrydelattrr   r/   r    SubConfigProxysetattr)rS   rT   rU   
type_hintskeyrG   r>   annotated_typeproxyconfigrI   visits            r#   rm   $install_config_module.<locals>.visit   s    ,,V4
v4467JCt$$ej,%?@@E<00((H4 ++667HII ud++
5'0J0JXcU#D'^^C6N%..+EE t 6>FC( "E7++!-%2B2B2J'5$+E2t6>FC( "E4((##v6(*5'1LV__L]^  'v$qz:etfAJ/6>Du-).MM#&$'8QugRU}TU%VWW[ 8r&    T)ConfigModuler   r,   rf   r*   -get_assignments_with_compile_ignored_comments_config_compile_ignored_keys	__class__rN   rO   )rI   rR   compile_ignored_keysrl   rm   s   `  @@r#   install_config_modulerv      s    M| M4XT!4X>)4X 4X 
	4X 4Xl ')FHP	&&"FN#7F +FFFr&   z@compile_ignoredc                 >   [         R                  " U 5      n[        5       n[        R                  " [        R
                  " UR                  S5      5      R                  5      nSnSnU GH  nUR                  [        R                  :X  aR  SnUR                  R                  5       n[        U;   a*  US:w  a  [        S[         35      eXvR                  S   4nMr  Mt  UR                  [        R                  :X  a  U(       d  UR                  nM  M  UR                  [        R                   :X  d  M  UR                  S:X  d  M  [        US   ;   a,  US   UR                  S   S-
  :X  a  UR#                  U5        SnSnGM     US:w  a  [        S[         35      eU$ )Nutf-8)ro   ro   zunconsumed r   rZ      )r\   	getsourcerP   tokenizeioBytesIOencodereadliner,   COMMENTstringstripCOMPILE_IGNORED_MARKERr    startNAMEOPadd)rI   source_codeassignmentstokenscurrent_comment	prev_nametokenmaybe_currents           r#   rq   rq      s^   ##F+K%K rzz+*<*<W*EFOOPFOI::)))I!LL..0M%6"h.(;7M6N)OPP"/Q"? 7 ZZ8==( !LL	 ZZ8;;&5<<3+> '/!*<<#A&%++a.1*<<	*"(I- . ("{+A*BCDDr&   c                       \ rS rSr% \\S'   \\S'   \r\\S'   Sr	\
S-  \S'   \r\\S'   \r\\S'   S	r\\S
'   Sr\
S-  \S'   S\SS4S jrSrg)rd   i  r   r   user_overrideNr   env_value_forceenv_value_defaultFhider   rl   r   c                 4   UR                   U l         UR                  b  UR                  O[        U R                   5      U l        UR                  U l        UR                  U l        UR
                  b)  UR
                   H  n[        U5      =nc  M  X0l          O   UR                  b)  UR                   H  n[        U5      =nc  M  X0l	          O   U R                  bE  U R                   b8  [        U R                   [        5      (       d  [        SU R                    S35      eU R                  bg  UR
                  c  UR                  bL  U R                  [        [        [        [           [        [           4;  a  [        SU R                   S35      eg g g )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   rH   r   r   r   r)   boolr    r*   r
   )r"   rl   r'   	env_values       r#   __init___ConfigEntry.__init__.  sw   ~~!'!2!2!>FDDV 	 \\
""...!3C!88IE-6* /   ,,,!3C!88IE+4( - ==$)AdllD11$7~EVW  ??&##/63H3H3T	'  %RSWSbSbRccno  4U 'r&   )r   r   r   r   r   r   )r/   r0   r1   r2   r   r5   r,   r   r   r   r*   r   r   r   r   r   r   r   r7   r8   r&   r#   rd   rd     sk     L )M3(HcDj*OS*,s, D$E3:#w #4 #r&   rd   c                     ^  \ rS rSr% \\\4   \S'   \\   \S'   \\   \S'   \	\S'   \
S-  \S'   S3S	 jrS
\S\SS4U 4S jjrS
\S\4S jrS
\SS4S jrS\S\\\4   S-  4S jrS\S\4S jrS\S\SS4S jrS
\S\	4S jr   S4S\\   S-  S\\   S-  S\	S\\\4   4S jjrS\S\4S jrS\
4S jrSS.S\	S\\\4   4S jjrS\4S  jrS\
4S! jr\" S"\ S#9S\\\4   4S$ j5       r!\" S%\ S#9S\\\4   4S& j5       r"S'\
\\\4   -  SS4S( jr#S\\\4   4S) jr$S\\\4   4S* jr%  S5S+\\\\4   -  S-  S,\S-\\\4   SS.4S/ jjr&S0\\\4   S\4S1 jr'S2r(U =r)$ )6rp   iT  rr   rQ   rs   rN   NrO   r   c                 (    [        S[         S35      e)Nzuse z-.install_config_module(sys.modules[__name__]))NotImplementedErrorr/   r!   s    r#   r   ConfigModule.__init__`  s    !8*IJ
 	
r&   r>   rG   c                 h  > XR                   ;   a  [        TU ]	  X5        g XR                  ;  a  [	        U R
                   SU S35      eU R                  U   R                  b   U R                  U R                  U   U5        g X R                  U   l        SU l	        SU R                  U   l
        g )NrY    does not existTF)rQ   super__setattr__rr   AttributeErrorr/   r   _set_alias_valr   rN   r   )r"   r>   rG   rt   s      r#   r   ConfigModule.__setattr__e  s    $$$G,% DMM?!D6!IJJ\\$%%1T 2E:/4LL,!DN&+DLL#r&   c                     U R                   U   nUR                  (       a  [        U R                   SU S35      eU R	                  U5      nU[
        La  U$ UR                  [
        La  UR                  $ UR                  [
        La  UR                  $ UR                  [
        La  UR                  $ UR                  b  [        UR                  UR                  S9$ [        UR                  [        [        [        45      (       a1  [         R"                  " UR                  5      Ul        UR                  $ UR                  $ ! [$         a!  n[        U R                   SU S35      UeS nAff = f)NrY   r   )r>   r   )rr   r   r   r/   _get_alias_valr   r   r   r   r   r   r   r)   r+   rP   dictcopydeepcopyKeyError)r"   r>   rl   	alias_vales        r#   __getattr__ConfigModule.__getattr__q  s:   !	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E E 8E E 6*E !AE <E 
E3E..E3c                 j    SU l         [        U R                  U   l        SU R                  U   l        g NT)rN   r   rr   r   r   r"   r>   s     r#   __delattr__ConfigModule.__delattr__  s-     ,;T("&Tr&   entryc                     UR                   nUc  g UR                  SS5      u  p4 [        R                  " U5      nXT4$ ! [         a  n[        SU S35      UeS nAff = f)NrY   rz   zconfig alias r   )r   rsplit	importlibimport_moduleImportErrorr   )r"   r   r   module_nameconstant_namerI   r   s          r#   _get_alias_module_and_name'ConfigModule._get_alias_module_and_name  ss     =%*\\#q%9"	P,,[9F $$  	P =!GHaO	Ps   ? 
A	AAc                 X    U R                  U5      nUc  [        $ Uu  p4[        X45      nU$ r:   )r   r   getattr)r"   r   datarI   r   constant_values         r#   r   ConfigModule._get_alias_val  s5    ..u5<"" $ 7r&   r'   c                 b    U R                  U5      nUc  [        S5      eUu  pE[        XEU5        g )Nz6alias data should not be None when setting alias value)r   r    rg   )r"   r   r'   r   rI   r   s         r#   r   ConfigModule._set_alias_val  s;    ..u5< H  !%s+r&   c                    U R                   U   nUR                  [        L =(       d    UR                  UR                  :H  nUR                  [        L =(       d    UR                  UR                  :H  nUR
                  [        L n[        UR                  [        [        [        45      (       a"  U=(       d    UR
                  UR                  :H  nU=(       a    U=(       a    U$ )zo
Returns true if the config is at its default value.
configs overridden by the env are not considered default.
)
rr   r   r   r   r   r   r)   r+   rP   r   )r"   r>   
config_valnot_set_env_defaultnot_set_env_forceunsets         r#   _is_default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                 R  ^ 0 nU R                    H  mU(       a  TU;   a  M  U(       a  [        U4S jU 5       5      (       a  M5  U(       a  U R                  T5      (       a  MT  U R                   T   R                  b  Mp  [        R
                  " [        U T5      5      UT'   M     U$ )ag  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   F   >#    U  H  nTR                  U5      v   M     g 7fr:   )r`   ).0rU   ri   s     r#   	<genexpr>)ConfigModule._get_dict.<locals>.<genexpr>  s     M<L&s~~f--<Ls   !)rr   anyr   r   r   r   r   )r"   r   r   r   rl   ri   s        @r#   	_get_dictConfigModule._get_dict  s    , "$<<C| 3M<LMMM 0 0 5 5||C &&2--c(:;F3K   r&   config_namec                 4    U R                   U   R                  $ r:   )rr   r   )r"   r   s     r#   get_typeConfigModule.get_type  s    ||K(333r&   c                 `    [        U S/ 5      n[        R                  " U R                  US9SS9$ )z Convert config to a pickled blob_save_config_ignorer      )protocol)r   pickledumpsr   )r"   r   s     r#   save_configConfigModule.save_config  s3    t%:B?||NNN5
 	
r&   T)ignore_private_configsr   c                    / nU(       a  UR                  S5        UR                  [        U S/ 5      5        U R                  US9$ )z!Convert config to portable format__cache_config_ignore_prefix)r   )appendextendr   r   )r"   r   prefixess      r#   save_config_portable!ConfigModule.save_config_portable  s?     !OOC &CRHI~~x~88r&   c                   ^^^	^
^ [        5       m
S[        S[        S[        4S jmS[        SS4UU
4S jjmS[        [         -  S[        [           4U4S jjmS[
        S[        4S	 jm	S[        4UUU	U4S
 jjn/ nU R                  nU R                  [        U S/ 5      SS9R                  5        H  u  pEUR                  U" X4U5      5        M     T
 H  nUR                  SSU 35        M     SR                  U5      $ )zConvert config to Python statements that replicate current config.
This does NOT include config settings that are at default values.
funcadd_dotr   c                 R    U R                   nUS:X  a  SnU(       a  US:w  a  US-  nU$ )Nbuiltinsro   rY   )r0   )r   r   r   s      r#   get_module_name4ConfigModule.codegen_config.<locals>.get_module_name  s2    //Kj( ;",s"r&   Nc                 J   > T" U S5      nU(       a  TR                  U5        g g )NF)r   )r   r   r   importss     r#   
add_import/ConfigModule.codegen_config.<locals>.add_import  s#    )$6KK( r&   vc                 ^   > U  Vs/ s H  nT" US5       UR                    3PM     sn$ s  snf r   )r/   )r   itemr   s     r#   list_of_callables_to_string@ConfigModule.codegen_config.<locals>.list_of_callables_to_string!  s2    PQRPQtT23DMM?CPQRRRs   !*c                 d    [        U 5      =(       a    [        U S5      =(       a    [        U S5      $ )Nr0   r/   )callablera   )r   s    r#   importable_callable8ConfigModule.codegen_config.<locals>.importable_callable$  s$    A;V71l#;V:@VVr&   c                   > T" U5      (       a%  T" U5        U  SU ST" US5       UR                    3$ [        U[        [        45      (       al  [	        U4S jU 5       5      (       aR  U H  nT" U5        M     T" U5      n[        U[        5      (       a
  U  SU SU 3$ U  SU SSR                  U5       S3$ U  SU SU< 3$ )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 }
rY   z = Tc              3   4   >#    U  H  nT" U5      v   M     g 7fr:   r8   )r   r   r   s     r#   r   GConfigModule.codegen_config.<locals>.get_config_line.<locals>.<genexpr>6  s      467d#D))as   z = { z, z })r/   r)   r+   rP   alljoin)	modkr   r   v_listr   r   r   r   s	        r#   get_config_line4ConfigModule.codegen_config.<locals>.get_config_line(  s     #1%%1as#oa&>%?

|LLAc{++ 4674 1 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 
)rP   r   r   r*   r+   r   r/   r   r   r_   r   insertr  )r"   r	  linesr  r  r   import_namer   r   r   r   r   s          @@@@@r#   codegen_configConfigModule.codegen_config  s    %	( 	T 	c 		)X 	)$ 	) 	)
	S4#: 	S$s) 	S	W3 	W4 	W	,# 	, 	,6 mmNN '<bAPT # 

%'DA LL34 #KLLgk]34 #yyr&   c                 Z   U R                   (       d  U R                  c  U R                  [        U R                  5      S9n[        [        UR                  5       5      5      n[        R                  " UR                  S5      SS9R                  5       U l        SU l         U R                  $ )z/Hashes the configs that are not compile_ignoredr   rx   F)usedforsecurity)rN   rO   r   r+   rs   reprsortedr_   hashlibmd5r   digest)r"   dict_to_hashstring_to_hashs      r#   get_hash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                 "    U R                  5       $ r:   get_config_copyr!   s    r#   to_dict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                 "    U R                  5       $ r:   r  r!   s    r#   shallow_copy_dictConfigModule.shallow_copy_dicta  r"  r&   maybe_pickled_configc                     [        U[        5      (       d  [        R                  " U5      nOUnUR	                  5        H7  u  p4X0R
                  ;   a  [        XU5        M"  SSKJn  U" SU SU S35        M9     g)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   loadsr_   rr   rg   torch._dynamo.utilsr(  )r"   r&  rl   r  r   r(  s         r#   load_configConfigModule.load_configj  se    .55\\"67F)FLLNDALL #9D<s2STU #r&   c                 "    U R                  5       $ r:   )r   r!   s    r#   r  ConfigModule.get_config_copyx  s    ~~r&   c                 6    U R                  [        U S/ 5      S9$ )Nr   r   )r   r   r!   s    r#   get_serializable_config_copy)ConfigModule.get_serializable_config_copy{  s    ~~749NPR+S~TTr&   arg1arg2kwargsContextDecoratorc                 |  ^^^ Ub\  Ub$  [        U[        5      (       d  [        S5      eX0mO"[        U[        5      (       d  [        S5      eUmU(       a  [        S5      eOUmUb  [        S5      e[        T[        5      (       d  [        S[	        T5       35      e0 mU m " UUU4S jS[
        5      nU" 5       $ )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                   F   > \ rS rSrSU 4S jjrSUU4S jjrUU4S jrSrg)'ConfigModule.patch.<locals>.ConfigPatchi  Nc                    > TU l         g r:   changes)r"   r;  s    r#   r   0ConfigModule.patch.<locals>.ConfigPatch.__init__  s
    &r&   c                    > T(       a  [        S5      eU R                   H  nTR                  U5      TU'   M     U R                  R                  5        H  u  p#TR	                  X#5        M     g )Nz/prior should be empty when entering ConfigPatch)r    r;  r   r_   r   )r"   ri   r  r   rl   priors       r#   	__enter__1ConfigModule.patch.<locals>.ConfigPatch.__enter__  sc    (I   <<C!'!3!3C!8E#J ( !LL..0DA&&q, 1r&   c                 z   > TR                  5        H  u  pETR                  XE5        M     TR                  5         g r:   )r_   r   clear)r"   exc_typeexc_valexc_tbr  r   rl   r>  s         r#   __exit__0ConfigModule.patch.<locals>.ConfigPatch.__exit__  s,    !KKMDA&&q, *r&   r:  r.   )r/   r0   r1   r2   r   r?  rF  r7   )r;  rl   r>  s   r#   ConfigPatchr8    s    '	- 	- r&   rH  )r)   r*   r    r   r,   r5  )r"   r2  r3  r4  rH  r;  rl   r>  s        @@@r#   patchConfigModule.patch~  s    . !$,,(a   ,!$--(e  $P   G$b  '4(( #7W!GHH "	 	* 	( }r&   r;  c                 N   ^ ^^ T R                   mS[        / S4   4UUU 4S jjnU$ )z
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                     >^ T V s0 s H  o TU    R                   _M     sn mTR                  5        H  u  pUTR                  U    l         M     SUU4S jjnU$ s  sn f )Nc                  `   > TR                  5        H  u  pUTR                  U    l        M     g r:   )r_   rr   r   )r  r   r>  r"   s     r#   revertBConfigModule._make_closure_patcher.<locals>.change.<locals>.revert  s%    !KKMDA45DLLO1 *r&   r.   )r   r_   rr   )r  r   rN  r>  r;  rl   r"   s      @r#   change2ConfigModule._make_closure_patcher.<locals>.change  s]    9@AAq	///AE01Q- (6 6 M Bs   A)rr   r   )r"   r;  rP  rl   s   `` @r#   _make_closure_patcher"ConfigModule._make_closure_patcher  s/    $ 		T* 		 		 r&   )rO   rN   r.   )NNF)NN)*r/   r0   r1   r2   r   r*   rd   r5   rP   r   bytesr   r4   r   r   r   r   tupler   r   r   r   r   r+   r   r,   r   r   r   r  r  r   FutureWarningr   r$  r+  r  r0  rI  rR  r7   __classcell__rt   s   @r#   rp   rp   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&   rp   c                   \   ^  \ rS rSrSrS	S jrS\4S jrS\\	/\	4   S\	4U 4S jjr
SrU =r$ )
r5  i  zO
Same as contextlib.ContextDecorator, but with support for
`unittest.TestCase`
r   c                     [        S5      eNNYIr   r!   s    r#   r?  ContextDecorator.__enter__      !%((r&   c                     [        S5      er[  r]  )r"   rC  rD  rE  s       r#   rF  ContextDecorator.__exit__  r_  r&   r   c                   >^  [        U[        5      (       ab  [        U[        R                  5      (       aC   " U 4S jSU5      nUR
                  Ul        UR                  Ul        UR                  Ul        U$ [        TT ]%  U5      $ )Nc                   V   >^  \ rS rSr\SU U4S jj5       r\SU U4S jj5       rSrU =r$ ),ContextDecorator.__call__.<locals>._TestCasei  c                    > TR                  5          [        TU ]	  5         g ! [         a    TR	                  S S S 5        e f = fr:   )r?  r   
setUpClass	ExceptionrF  clsrt   r"   s    r#   rf  7ContextDecorator.__call__.<locals>._TestCase.setUpClass  s?    NN$*,$ dD$7s	   " Ac                 z   >  [         TU ]  5         TR                  S S S 5        g ! TR                  S S S 5        f = fr:   )r   tearDownClassrF  rh  s    r#   rl  :ContextDecorator.__call__.<locals>._TestCase.tearDownClass  s4    8-/dD$7dD$7s   % :r8   r.   )	r/   r0   r1   r2   classmethodrf  rl  r7   rW  )rt   r"   s   @r#   	_TestCaserd    s)      8 8r&   ro  )
r)   r,   rb   unittestTestCaser/   r1   r0   r   __call__)r"   r   ro  rt   s   `  r#   rr  ContextDecorator.__call__  sl    dD!!jx7H7H&I&I8D 8" "&I%)%6%6I"#'??I w%%r&   r8   r.   )r/   r0   r1   r2   r3   r?  r	   rF  r   r   rr  r7   rW  rX  s   @r#   r5  r5    s<    
))X )&XseSj1 &c & &r&   r5  c                   v   ^  \ rS rSrSrS\S\SS4U 4S jjrS\S	\SS4S
 jrS\S\	4S jr
S\SS4S jrSrU =r$ )rf   i  zb
Shim to redirect to main config.
`config.triton.cudagraphs` maps to _config["triton.cudagraphs"]
rl   rU   r   Nc                 F   > [         TU ]  SU5        [         TU ]  SU5        g )Nrr   _prefix)r   r   )r"   rl   rU   rt   s      r#   r   SubConfigProxy.__init__  s!    Iv.Iv.r&   r>   rG   c                 T    U R                   R                  U R                  U-   U5      $ r:   )rr   r   rv  )r"   r>   rG   s      r#   r   SubConfigProxy.__setattr__   s"    ||''t(;UCCr&   c                 R    U R                   R                  U R                  U-   5      $ r:   )rr   r   rv  r   s     r#   r   SubConfigProxy.__getattr__#       ||''t(;<<r&   c                 R    U R                   R                  U R                  U-   5      $ r:   )rr   r   rv  r   s     r#   r   SubConfigProxy.__delattr__&  r|  r&   r8   )r/   r0   r1   r2   r3   r4   r*   r   r   r   r   r   r7   rW  rX  s   @r#   rf   rf     sk    
/v /s /t /
D DF Dt D= = == = = =r&   rf   objrG   c                     [        U [        5      (       a  U R                  X5      $ [        R                  R	                  XU5      $ )z8
Workaround `mock.patch.object` issue with ConfigModule
)r)   rp   rI  r   r4   )r  r>   rG   s      r#   patch_objectr  *  s7     #|$$yy%%::S..r&   c                 `    [         R                  R                  U 5      nUS:X  a  gUS:X  a  gU$ r@   rC   )r>   r   rG   s      r#   get_tristate_envr  3  s-    JJNN4 E||Nr&   r:   )6
contextlibr   r  r   r\   r}   rD   r   r|   rp  collections.abcr   dataclassesr   typesr   r   rX   r   r   r	   r
   r   r   typing_extensionsr   r   torch._utils_internalr   intfloatr   r,   r*   r+   rP   rU  r   rc   r   r4   r   r   r<   rH   rv   r   rq   rd   rp   r5  rf   r  r  r8   r&   r#   <module>r     s        	 	    $ ! * K K (  1 UD$t*c4eTJ CsU{T)C/$6<uDt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&   