
    N jZ                        % 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J	r	  S SK
Jr  S SKJrJrJrJrJrJr  S SKJrJr  S SKrS SKJs  Jr  S SKJr  S SKJrJr  S SK J!r!J"r"  S S	K#J$r$   S S
KJ%r%  \(       a  S SK)J*r*  \" S\S9r+\" SSS9r,\-" \S5      =(       a	    \-" \S5      r.\R^                  S 5       r0 " S S5      r1S\1S\4S jr20 r3\4\5S4   \6S'   \Rn                  \Rp                  \Rr                  \Rt                  \Rv                  \Rx                  \Rz                  /r> " S S\1\ R~                  5      r@S rAS rBS rCS rD " S S 5      rE\E" 5       qFSCS! jrGS" rHS# rIS$ rJS% rKS& rLS' rM\N" 5       qO\NS(   \6S)'   S* rPS+ rQS, rR " S- S(\1\\,\+4   5      rS " S. S/\S\,\+4   5      rTS0\U4S1 jrVS0\U4S2 jrWS3\R                  S0\U4S4 jrY " S5 S6\\,\+4   5      rZS\Z\,\+4   S7\,R                  S8\,R                  S0\+4S9 jr] " S: S;\R                  5      r_S< r`S= ra " S> S?\R                  5      rb " S@ SA\R                  5      rc\c" 5       rd\c\6SB'   g! \& a    \'" \(5      r% GNf = f)D    N)CallableIterator)cached_property)AnyClassVarConcatenatefinalGenericTYPE_CHECKING)	ParamSpecTypeVar)_utils_internal)_dispatch_is_included_in_aliasDispatchKey)dispatch_functorchTransformType)TorchDispatchMode)NotImplementedType)BaseFunctionalizeAPI_T)default_P.getdlopenflagssetdlopenflagsc               #     #    [         (       d  Sv   g[        R                  " 5       n [        R                  " U [        R
                  -  5         Sv   [        R                  " U 5        g! [        R                  " U 5        f = f7f)zu
Context manager to set the RTLD_GLOBAL dynamic linker flag while we open a
shared library to load custom operators.
N)_SET_GLOBAL_FLAGSsysr   r   ctypesRTLD_GLOBAL)	old_flagss    [/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/_ops.pydl_open_guardr"   (   s^      ""$Iy6#5#556&9%9%s   ABA+ B+BBc                       \ rS rSrSrS rS rS rS rS\	\
   \	\R                     -  \-  \-  S\\\\4   /\\\4   4   4S	 jrS
\\S\4   \4   S\\S\4   \4   4S jrS rSrg)OperatorBase9   z
Base class for OpOverload (which represents C++ ATen operators) and HigherOrderOperator
(which represents Python-only operators that are unrepresentable in TorchScript).
c                 <    0 U l         0 U l        0 U l        0 U l        g N)_dispatch_cache
py_kernelspython_key_tablefunctorch_tableselfs    r!   __init__OperatorBase.__init__?   s0      UW BD  	  "    c                     [         er'   NotImplementedErrorr-   argskwargss      r!   __call__OperatorBase.__call__i       !!r0   c                     XR                   ;   $ r'   )r)   )r-   ks     r!   has_kernel_for_dispatch_key(OperatorBase.has_kernel_for_dispatch_keyl   s    OO##r0   c                     U R                    HA  n[        R                  R                  U5      (       a  M)  UR	                  U5      (       d  MA    g   g)NTF)r)   torch_C_dispatch_is_alias_keyhas)r-   ksr;   s      r!   has_kernel_for_any_dispatch_key,OperatorBase.has_kernel_for_any_dispatch_keyo   s9    A8822155"&&)) ! r0   r;   returnc                 h   ^ ^ S[         [        [        4   S[         [        [        4   4UU 4S jjnU$ )NfnrF   c                   > [         R                  " T5      (       a}  [        T[        5      (       d  [        T[        R
                  5      (       aI  TTR                  ;   a  [        T S35      eU TR                  T'   TR                  R                  5         U $ [        T[        5      (       a/  TTR                  ;   a  [        T S35      eU TR                  T'   U $ [        T[        5      (       d  [        S[        T5       35      eT[        R                  :X  a  [        S5      eTTR                   ;   a  [#        ST STR%                  5        35      eU TR                   T'   TR                  R                  5         U $ )Nz' already registered in python_key_tablez& already registered in functorch_tablezexpected DispatchKey, got z>Please register a mode for the DispatchKey.Python key instead.z%Trying to override a python impl for z on operator )inspectisclass
issubclassr   r?   Tensorr*   AssertionErrorr(   clear
isinstancer   r+   r   typePythonr)   RuntimeErrorname)rH   r;   r-   s    r!   inner#OperatorBase.py_impl.<locals>.innery   sU   q!!1/00Jq%,,4O4O---(A3.U)VWW+-%%a($$**,	!]++,,,(A3.T)UVV*,$$Q'	a--$'A$q'%KLLK&&&$T  DOO#";A3mDIIK=Y  "$DOOA  &&(Ir0   )r   r   r   )r-   r;   rU   s   `` r!   py_implOperatorBase.py_implu   s5    	hr2v& 	8BF+; 	 	@ r0   rH   r   c           	        ^^^^ SSK JmJnJmJm  S[
        R                  S[
        R                  S[        4UU4S jjnSUS -  S[
        R                  S[
        R                  S[        [        -  4UU4S jjnS[
        R                  S[
        R                  S[        4UU4S	 jjnU R                  [        R                  5      " U5        U R                  U5      " U5        U R                  [        R                  5      " U5        T$ )
Nr   )CppFunctionalizeAPIFunctionalTensorModeFunctorchFunctionalizeAPIPythonFunctionalizeAPIr5   r6   rF   c                  &   > T" T" 5       /U Q70 UD6$ r'    )r5   r6   rZ   rH   s     r!   functionalize_dk_fn?OperatorBase.py_functionalize_impl.<locals>.functionalize_dk_fn   s    )+=d=f==r0   modec                 t   > SSK Jn  SSKJn  SSKJn  U" X4XE4S9(       a  [        $ T" T" U 5      /UQ70 UD6$ )Nr   )has_user_subclass)
FakeTensor)FunctionalTensor)allowed_subclasses)torch._higher_order_ops.utilsrd   torch._subclassesre   #torch._subclasses.functional_tensorrf   NotImplemented)rb   r5   r6   rd   re   rf   r]   rH   s         r!   functionalize_dispatch_mode_fnJOperatorBase.py_functionalize_impl.<locals>.functionalize_dispatch_mode_fn   sE     H4L $.#A &%,T2DTDVDDr0   c                 (   > T" T" U 5      /UQ70 UD6$ r'   r_   )interpreterr5   r6   r\   rH   s      r!   functionalize_functorch_fnFOperatorBase.py_functionalize_impl.<locals>.functionalize_functorch_fn   s      /<NtNvNNr0   )rj   rZ   r[   r\   r]   r   r5   r6   r   r   rW   r   Functionalizer   )	r-   rH   r[   r`   rl   rp   rZ   r\   r]   s	    `    @@@r!   py_functionalize_impl"OperatorBase.py_functionalize_impl   s    	
 	
	>rww 	>")) 	> 	> 	>	E&-	E68gg	EIK	E$$	E 	E	O "	O3599	O	O 	O
 	[../0CD)*+IJ]0012LM	r0   c                     [         er'   r2   r,   s    r!   rT   OperatorBase.name   r9   r0   )r(   r+   r)   r*   N)__name__
__module____qualname____firstlineno____doc__r.   r7   r<   rD   rQ   r   r?   rM   r   r   r   r   r   rW   r   rs   rT   __static_attributes__r_   r0   r!   r$   r$   9   s    
("T"$$!"T%,,%77-G+U$ 
8BF#$hr2v&66	7$b&;'=r'ABBFG&	+4b892=	>&P"r0   r$   opr;   c                 >   U R                  U5      (       a  U$ [        R                  nU[        R                  :X  d  [	        X5      (       a  U R                  U5      (       a  U$ [        R
                  nU[        R                  :X  d  [	        X5      (       a  U R                  U5      (       a  U$ U R                  [        R                  R                  U5      5      =(       d    U R                  [        R
                  5      n[        R                  nU[        R                  :w  a/  [	        X5      (       a  U R                  U5      (       a	  U(       d  U$ [        R                  nU[        R                  :X  d  [	        X5      (       al  U R                  U5      (       aV  U[        R                  :X  a9  U R                  [        R                  R                  5      (       a  [        S5      eU(       d  U$ [        R                  n[	        X5      (       a  U R                  U5      (       a  U$ [        R                   n[	        X5      (       a  U R                  U5      (       a  U$ [        R                  R#                  U5      (       a  U$ [%        SU  SU 35      e)Nzambiguous autogradother kernelzcould not find kernel for  at dispatch key )r<   r   &CompositeExplicitAutogradNonFunctional	Undefinedis_included_in_aliasCompositeExplicitAutogradrD   r?   r@   *_dispatch_get_backend_keyset_from_autograd%CompositeImplicitAutogradNestedTensorCompositeImplicitAutogradAutogradOther _dispatch_autogradother_backendsrS   AutogradFuncTorchBatchedDecomposition_dispatch_has_backend_fallbackr3   )r}   r;   candhas_backend_kernels       r!   resolve_keyr      s   	%%a((==D	["""&:1&C&C

(
(
.
.00D	["""&:1&C&C

(
(
.
.;;;;A> O		'	'(M(M	N  <<D	
k##	#(<Q(E(E**400"00D	["""&:1&C&C

(
(
.
.)))b.P.PHH55/
 /
 ?@@#KDA$$)G)G)M)M44DA$$)G)G)M)Mxx..q11 
 :2$>OPQsS
TTr0   HigherOrderOperator_higher_order_opsc                   4  ^  \ rS rSrSS.U 4S jjrS\\   \\R                     -  \	-  \
-  S\\\\4   /\\\4   4   4U 4S jjrS\\\4   S\\\4   4S	 jr\S
 5       r\S\4S j5       rS rS r\R0                  S 5       rS rS rS rSS jrSrU =r$ )r   i  F)	cacheablec                0  > [         TU ]  5         [        U 5      [        L a  [	        S5      eXl        Xl        U [        U'   SU l        SU l	        X l
        [        R                  R                  5       U l        [         H  nU R!                  U5        M     g )NzODirect instantiation of HigherOrderOperator is not allowed. Please subclass it.higher_ordertorch.ops.higher_order)superr.   rQ   r   rS   _namerw   r   _nsrx   
_cacheabler?   r@   _dispatch_keyset_fullnon_fallthrough_keys2_HIGHER_ORDER_OP_DEFAULT_FALLTHROUGH_DISPATCH_KEYSfallthrough)r-   rT   r   dispatch_key	__class__s       r!   r.   HigherOrderOperator.__init__  s    :,,a  
 "&$!2#$)HH$B$B$D!NL\* Or0   r;   rF   c                    > [        U[        5      (       a@  U R                  R                  U5      (       d   U R                  R	                  U5      U l        [
        TU ]  U5      $ r'   )rP   r   r   rB   addr   rW   r-   r;   r   s     r!   rW   HigherOrderOperator.py_impl7  sP     a%%d.G.G.K.KA.N.N(,(A(A(E(Ea(HD%wq!!r0   rH   c                    ^ ^ S[         R                  S[         R                  S[        4UU 4S jjnT R	                  [
        R                  5      " U5        T$ )Nr5   r6   rF   c                    > [         R                  " 5       (       a1  [        R                  " [         R                  S / U QUP75      (       a0  [         R
                  R                  5          T" U 0 UD6sS S S 5        $ SSKJn  U" T5      (       aP  TR                  " U 0 UD6n[        S UR                   5       5      (       a  [        STR                  5        S35      eT" U 0 UD6$ ! , (       d  f       Ny= f)Nc                 $    U R                   (       + $ r'   )requires_grad)ts    r!   <lambda>RHigherOrderOperator.py_autograd_impl.<locals>.maybe_run_autograd.<locals>.<lambda>F  s    aoo-r0   r   )_has_gen_schemac              3   8   #    U  H  oR                   v   M     g 7fr'   )is_write.0args     r!   	<genexpr>SHigherOrderOperator.py_autograd_impl.<locals>.maybe_run_autograd.<locals>.<genexpr>P  s     @/?||/?   zThe z HigherOrderOperator does not currently support training with in-place input or buffer mutations If you require this feature, please submit an issue to PyTorch. Alternatively, consider creating your own custom autograd.Function. )r?   is_grad_enabledpytreetree_all_onlyrM   r@   _AutoDispatchBelowAutogradrh   r   
gen_schemaany	argumentsrS   rT   )r5   r6   r   schemarH   r-   s       r!   maybe_run_autograd@HigherOrderOperator.py_autograd_impl.<locals>.maybe_run_autogradC  s    ((**f.B.B-$/ /
 XX88:00 ;: Ft$$$9&9@v/?/?@@@&tyy{m ,_ _  t&v&& ;:s   +C((
C6)r   r5   r6   r   rW   r   r   )r-   rH   r   s   `` r!   py_autograd_impl$HigherOrderOperator.py_autograd_impl?  sI    	'bgg 	' 	'r 	' 	'. 	[))*+=>	r0   c                     U R                   $ r'   )r   r,   s    r!   	namespaceHigherOrderOperator.namespace^      xxr0   c                 .   SSK Jn  U R                  =(       d}    U R                   SU R                   3[
        R                  R                  R                  ;   =(       d6    [        X5      =(       a$    [
        R                  R                  R                  $ )Nr   )AutogradFunctionApply.)"torch._functorch.autograd_functionr   r   rx   rw   r?   	_inductorconfig!unsafe_marked_cacheable_functionsrP   
_functorch.autograd_cache_allow_custom_autograd_functions)r-   r   s     r!   r   HigherOrderOperator.cacheableb  sr    L OO //"!DMM?3%%GGH 47 [$$++ZZ	
r0   c                 D    U R                   R                  U5      U l         g r'   )r   remove)r-   r   s     r!   r   HigherOrderOperator.fallthroughp  s    $($=$=$D$D\$R!r0   c                	  ^^ SSK Jn  XR                  ;   a:  U R                  U   n[        U[        5      (       a  [        SU 35      eU" U0 UD6$ U[        R                  :X  a  [        XU5      $ U[        R                  :X  Ga  / mS mUU4S jn/ UQUR                  5       Q7 H9  nU" U5        [        U[        [        45      (       d  M(  U H  nU" U5        M     M;     [        T5      n	SSK Jn
  U" 5       nUb  [        U5      U R                  ;   a5  U R                  [        U5         nU
" 5        nU" U/UQ70 UD6nS S S 5        OgUR                  (       a$  U
" 5        nUR!                  U / X#5      sS S S 5        $ [#        SU R$                   SU S	U S
U SU R$                   SU S35      eW[&        La  U$ U	 H  n[        U5      nUR                   [(        R*                  R,                  L a  M7  U[(        R.                  R0                  R2                  L aM  [(        R.                  R0                  R4                  nU R                  U   nU" UR6                  /UQ70 UD6nUs  $ XR                  ;   a  U R                  U   nU" U0 UD6nO[#        SU R$                   SU S35      eU[&        Ld  M  Us  $    [9        SU R$                   SU SU	 Vs/ s H  n[        U5      R:                  PM     sn SU R$                   SU S35      e[(        R*                  R=                  U5      nU[        R>                  :X  a  SSK Jn
  [A        5       S:  a  [(        R*                  RC                  [        R                  5      (       dv  [E        5       nUc  [        S5      e[        U5      U R                  ;  a  [        SU S35      eU R                  [        U5         nU
" U5       nU" U/UQ70 UD6sS S S 5        $ [G        X5      nUU RH                  ;  a  [#        SU R$                   SU SU S35      eU[        R>                  :w  a  U RH                  U   U R                  U'   U RH                  U   n[        U[        5      (       a  [        SU 35      eU" U0 UD6$ ! , (       d  f       GN= f! , (       d  f       GN= fs  snf ! , (       d  f       N= f)Nr   _get_current_dispatch_modez!unexpected DispatchKey in cache: c                 ^    [         R                  R                  U 5      R                  S5      $ )NrR   )r?   r@   _dispatch_keysrB   )tensors    r!   has_python_key4HigherOrderOperator.dispatch.<locals>.has_python_key  s"    xx..v6::8DDr0   c                    > [        U [        R                  5      (       a   T" U 5      (       a  TR                  U 5        g g g r'   )rP   r?   rM   append)r   r   overloaded_args_lists    r!   check_overloaded6HigherOrderOperator.dispatch.<locals>.check_overloaded  s5    c5<<00^C5H5H(//4 6I0r0   )_pop_mode_temporarilyz5There was no rule registered for HigherOrderOperator z
 and mode z.Hint: set zc's supports_higher_order_operators to True. This causes all higher order operators to pass through zk's __torch_dispatch__, so handle them accordingly by adding support for HigerOrderOperators (in this case, z) in zC.__torch_dispatch__ or returning NotImplemented when not supported.z%There was no rule registered for HOP z and subclass z. We recommend filing an issue.zHigherOrderOperator 'z' is not supported for the given input types. This typically happens when using custom tensor types or dispatch modes that don't have implementations for this operation.

Current mode: z
Input types: z$

To fix this, can add support for 'z' in z's __torch_dispatch__
zIIllegal invocation of dispatch on DispatchKey.PreDispatch without a mode.zCurrent active mode z not registeredz.could not find kernel for HigherOrderOperator r   z (resolved from )z&unexpected DispatchKey in py_kernels: )%torch.utils._python_dispatchr   r(   rP   r   rN   FuncTorchDynamicLayerFrontModer   rR   valueslisttupler   rQ   r*   supports_higher_order_operators__torch_dispatch__r3   r   rk   r?   r@   _disabled_torch_dispatch_impl_subclassesfake_tensorre   FakeTensorMode	fake_mode	TypeErrorrw   _to_functionality_keyPreDispatch&_len_torch_dispatch_stack_pre_dispatch&_dispatch_tls_is_dispatch_key_excluded'_get_current_dispatch_mode_pre_dispatchr   r)   )r-   r   r5   r6   r   kernelr   r   aoverloaded_argsr   	curr_modehandlerrb   resultsubclass_typefunctionality_key	final_keyr   r   s                     @@r!   dispatchHigherOrderOperator.dispatchu  s    K///)),7F&+..$'H%QRR4*6**;EEE%d&99;--- $& E5 100 %cD%=11 (+ ! 1 $$89O K24I$	?d&;&;;"33DODG.0D ")!?!?!? 10
 !@@24#,#?#?b$#W 54 2STXT^T^S__ijsit u))2 4WW`Va bVVZV`V`Ua b  ){ +LM  /!M ' $S	!44xx==>  !E$5$5$A$A$L$LL$)$5$5$A$A$P$PM"33MBG$S]]DTDVDF!M $9$99"33MBG %d5f5F-?

|>ZgYh i8 9  /!M= 'B '

| 4! "+ , ;J K?aa!1!1? KL M559ZZLi[Pgi  "HH::<H 7 77J
 781<hhEE""  DE	$(c  	?$*?*??(.ykI  //Y@*+<="49$9&9 >=  3	 DOO+%@ M##,+-=l^1N  ;222151KD  .+ fk** #I&!RSSt&v&&[ 10 54l !L2 >=s*   8R'&R9S-S'
R69
S
Sc                   [        X5      n[        R                  R                  U5      (       a$  [        R                  R                  " X/UQ70 UD6$ [        XU R                  5      nU R                  " UR                  5       /UQ70 UD6$ r'   )	_to_flat_tupler?   	overrideshas_torch_functionhandle_torch_function_compute_keysetr   r   highestPriorityTypeId)r-   r5   r6   	flat_argsdispatch_key_sets        r!   r7   HigherOrderOperator.__call__  s    "40	??--i88??88"&*0  +49R9RS}}-CCEWWPVWWr0   c                 4    [        SU R                   S35      e)NzHigherOrderOperator z does not implement a gen_schema. This is OK as long as the hop is functional. e.g. it should not mutate its inputs and there are no input, output aliasing via views or direct referencing.)r3   r   r4   s      r!   r   HigherOrderOperator.gen_schema#  s$    !"4::, // 0
 	
r0   c                 $    U R                  5        $ r'   )rT   r,   s    r!   __str__HigherOrderOperator.__str__+  s    ))+r0   c                     U R                   $ r'   r   r,   s    r!   rT   HigherOrderOperator.name.      zzr0   c                     U $ r'   r_   r-   memos     r!   __deepcopy__ HigherOrderOperator.__deepcopy__2      r0   )rx   rw   r   r   r   r   r'   ) rw   rx   ry   rz   r.   rQ   r   r?   rM   r   r   r   r   r   rW   r   propertyr   r	   boolr   r   r   abcabstractmethodr7   r   r  rT   r  r|   __classcell__r   s   @r!   r   r     s     +0 + +8"!"T%,,%77-G+U" 
8BF#$hr2v&66	7"RV 
"b&	>   
4 
 
S
U'n 	X X,
  r0   c                 .    [         R                  " U 0 UD6$ r'   )r   arg_tree_leavesr5   r6   s     r!   r   r   6  s    !!42622r0   c                 .    [        X5      n[        X25      $ r'   )_get_tensorskey_extractor)r5   r6   r   tensorss       r!   r  r  :  s    4(G77r0   c                     [        X5      nU Vs/ s H&  n[        U[        R                  5      (       d  M$  UPM(     nn[	        U5      $ s  snf r'   )r   rP   r?   rM   r   )r5   r6   flat_allr   tensor_argss        r!   r!  r!  ?  s>    d+H&Fh*Q*E1hKF Gs
   #A
A
c                     [         R                  R                  5       nU  H%  nU[         R                  R                  U5      -  nM'     U[         R                  R	                  5       -
  nX!-  nU$ r'   )r?   r@   _dispatch_tls_local_include_setr   _dispatch_tls_local_exclude_set)r#  key_maskkey_setr   s       r!   r"  r"  G  s[    hh668GEHH33F;; @@BBG GNr0   c                   ,    \ rS rSrS rS rS rS rSrg)_ModeStackStateForPreDispatchi]  c                 $    S S /U l         S U l        g r'   )*_ModeStackStateForPreDispatch__infra_modes_schema_check_moder,   s    r!   r.   &_ModeStackStateForPreDispatch.__init__^  s    "D\"&r0   c                     U[        U R                  5      :  a$  [        SU S[        U R                  5       35      eX R                  U'   g Nzindex z& out of bounds for infra_modes length lenr/  rN   )r-   indexrb   s      r!   set!_ModeStackStateForPreDispatch.setb  sO    C**++ Ec$J\J\F]E^_  %)5!r0   c                     U[        U R                  5      :  a$  [        SU S[        U R                  5       35      eU R                  U   $ r3  r4  )r-   r6  s     r!   get!_ModeStackStateForPreDispatch.geti  sR    C**++ Ec$J\J\F]E^_  !!%((r0   c                     [        U R                   Vs/ s H	  oc  M  UPM     sn5      [        U R                  S L5      -   $ s  snf r'   )r5  r/  intr0  )r-   is     r!   count#_ModeStackStateForPreDispatch.countp  sD    t11C1!A1CDs##4/H
 
 	
Cs
   AA)__infra_modesr0  N)	rw   rx   ry   rz   r.   r7  r:  r?  r|   r_   r0   r!   r-  r-  ]  s    '))
r0   r-  c                   ^ ^ [        5       m[        R                  R                  R                  [        R                  R                  R
                  4nT b  T U;  a  [        SU ST  35      eU(       a  T b  [        S5      eUU 4S jnU" 5       n[        5       nUS:X  a.  [        R                  R                  [        R                  S5        U$ )Nz mode_key must be None or one of z, got z/mode_key must be None when schema_check is Truec                    > T[         R                  R                  R                  L a-  TR	                  S5      n [        5       R                  SS 5        U $ T[         R                  R                  R                  L a-  TR	                  S5      n [        5       R                  SS 5        U $ [        5       R                  n S [        5       l        U $ )Nr      )	r?   r@   _TorchDispatchModeKeyPROXYr:  !mode_stack_state_for_pre_dispatchr7  
FUNCTIONALr0  )current_modecurrent_mode_stack_pre_dispatchmode_keys    r!   _unset_mode,unset_mode_pre_dispatch.<locals>._unset_mode  s     uxx55;;;:>>qAL-/33At<77BBB:>>qAL-/33At<<>QQLEI-/Br0   r   F)rG  r?   r@   rE  rF  rH  rN   r   '_dispatch_tls_set_dispatch_key_includedr   r   )rK  schema_check
valid_keysrL  rI  new_pre_dispatch_lenrJ  s   `     @r!   unset_mode_pre_dispatchrR  y  s    &G&I#&&,,&&11J 
 :.zl&
K
 	
  !RSS   =LAC
 q 889P9PRWXr0   c                    SSK Jn  SSKJn  SSKJn  [        U UUU45      (       d  [        S[        U 5       35      e[        5       n[        X5      (       a5  [        5       R                  nUS:  a  [        S5      eU [        5       l        O[        X5      (       aE  [        5       R                  S5      nUb  [        SU 35      e[        5       R                  SU 5        OD[        5       R                  S5      nUb  [        S	U 35      e[        5       R                  SU 5        US:X  a/  [        R                  R!                  ["        R$                  S
5        g g )Nr   )r[   )SchemaCheckMode)ProxyTorchDispatchModezSmode must be FunctionalTensorMode, ProxyTorchDispatchMode, or SchemaCheckMode, got zYSchemaCheckMode for pre-dispatch must be used exclusively, found other modes on the stackrD  z.FunctionalTensorMode slot already occupied by z0ProxyTorchDispatchMode slot already occupied by T)rj   r[   #torch._subclasses.schema_check_moderT  "torch.fx.experimental.proxy_tensorrU  rP   rN   rQ   r   rG  r0  r:  r7  r?   r@   rN  r   r   )rb   r[   rT  rU  previous_mode_stack_lenrI  s         r!   _set_mode_pre_dispatchrY    sV   HCI "	
  abfgkblamn
 	
 EF$((8:MM"Q& k  BF)+>	D	/	/8:>>qA# @O  	*+//488:>>qA# B<.Q  	*+//48 !#889P9PRVW $r0   c                  x   [        5       n [        5       nUS:X  a  [        S5      eU R                  b
  [	        S SS9$ U R                  S5      b-  [	        [        R                  R                  R                  5      $ U R                  S5      b-  [	        [        R                  R                  R                  5      $ g )Nr   zTrying to pop empty mode stackT)rO  rD  )rG  r   rN   r0  rR  r:  r?   r@   rE  rH  rF  )
mode_stackpre_dispatch_lens     r!   _pop_mode_from_pre_dispatchr]    s    24J=?1=>>$$0&t$??~~a$&uxx'E'E'P'PQQ~~a$&uxx'E'E'K'KLL %r0   c                  2    [        5       R                  5       $ r'   )rG  r?  r_   r0   r!   r   r     s    ,.4466r0   c                    U [         R                  R                  R                  L a  [	        5       R                  S5      $ U [         R                  R                  R                  La  [        SU  35      e[	        5       R                  S5      $ )Nr   z*mode_key must be PROXY or FUNCTIONAL, got rD  )r?   r@   rE  rF  rG  r:  rH  rN   )rK  s    r!   _get_dispatch_mode_pre_dispatchr`    ss    588117770266q9958899DDD <XJG  1266q99r0   c                  h   [        5       R                  b  [        5       R                  $ [        5       R                  5       n U S:X  a  [        5       R                  S5      $ U S:X  aL  [        5       R                  S5      b  [        5       R                  S5      $ [        5       R                  S5      $ g )N   rD  r   )rG  r0  r?  r:  )	stack_lens    r!   r   r     s    (*==I02EEE57==?	>46::1==> 56::1=I 2377: 78<<Q?
 r0   c                      [         $ r'   )"_mode_stack_state_for_pre_dispatchr_   r0   r!   rG  rG    s    --r0   
OpOverload
cached_opsc                 .    [         R                  U 5        g r'   )rg  r   )op_overloads    r!   add_cached_oprj    s    NN;r0   c                  ,    [         R                  5         g r'   )rg  rO   r_   r0   r!   reset_cached_opsrl    s    r0   c                      [         $ r'   )rg  r_   r0   r!   get_cached_opsrn    s    r0   c                     ^  \ rS rSrSSS\\\4   S\\\\4   \4   S\	R                  R                  S\\   SS	4U 4S
 jjr\S\4S j5       r\S\4S j5       r\S\	R                  R&                  4S j5       rS&S jrS rS\R.                  S\R0                  S\4S jrS\	R                  R4                  S\R.                  S\R0                  S\4S jrS rS rS\S\4U 4S jjrS\	R                  R4                  S\4U 4S jjr \!S\4S j5       r"S\4S jr#S\R.                  S\R0                  S\4S jr$S\SS	4S jr%S\S\\\\4   -  4S  jr&S! r'\!S" 5       r(\!S# 5       r)\!S$ 5       r*S%r+U =r,$ )'rf  i  overloadpacketOpOverloadPacketr}   op_dkr   tagsrF   Nc                   > [         TU ]  5         X l        X0l        X@l        Xl        XPl        UR                  S:X  a  SOUR                  U l        U(       a"  [        R                  R                  U;   U l        U R                  R                  U l        UR                  (       a"  U =R                  SUR                  -   -  sl        U R                  R                  R                  S5      S    SU R                   3U l        UR"                  U l        UR"                  Ul        U R                  U l        0 U l        U R$                  [        R(                  R*                  ;   U l        S nU R                  R.                   HL  nUR0                  c  M  Uc  UR0                  R2                  nM-  UR0                  R2                  =(       d    UnMN     US L=(       a    U(       + U l        g )N r   r   ::rD  )r   r.   _op_op_dk_schema_overloadpacket_tagsoverload_name_overloadnamer?   Tagnondeterministic_seeded_nondeterministic_seededrT   r   splitrw   rx   ry   __annotations__library_defs_defined_in_pythonr   
alias_infor   is_view)	r-   rp  r}   rr  r   rs  r   r   r   s	           r!   r.   OpOverload.__init__  s    	-
--3I9M9M 	 ,1II,M,MQU,UD)\\&&
JJ# 4 444J<<,,2248;<Ad>P>P=QR(33&11 JJ! #'"3"3u}}7J7J"J ''A||#<<00 <<00<H (  t+<Hr0   c                 P    U R                   R                  R                  SSS9S   $ )Nrv  rD  maxsplitr   ry  rT   r  r,   s    r!   
_namespaceOpOverload._namespaceI  '    ||  &&ta&8;;r0   c                 P    U R                   R                  R                  SSS9S   $ )Nrv  rD  r  r  r,   s    r!   _opnameOpOverload._opnameM  r  r0   c                     [         R                  R                  U R                  R                  U R                  R
                  5      $ r'   )r?   r@   _dispatch_find_schema_or_throwry  rT   r|  r,   s    r!   _handleOpOverload._handleQ  s2    xx66LLt||99
 	
r0   c                     U $ r'   r_   r  s     r!   r  OpOverload.__deepcopy__X  r  r0   c                 V    SU R                    SU R                   SU R                   S3$ )Nz<OpOverload(op='r   z', overload='z')>)r  r  r}  r,   s    r!   __repr__OpOverload.__repr__[  s.    !$//!2!DLL>tOaOaNbbeffr0   r5   r6   c                &    U R                   " U0 UD6$ r'   rw  r4   s      r!   r7   OpOverload.__call__`  s    xx(((r0   keysetc                B    U R                   R                  " U/UQ70 UD6$ r'   )r  redispatch_boxed)r-   r  r5   r6   s       r!   
redispatchOpOverload.redispatche  s#     ||,,VEdEfEEr0   c                 ,    [        U R                  5      $ r'   hashrw  r,   s    r!   __hash__OpOverload.__hash__j      DHH~r0   c                     SR                   " / U R                  R                  R                  S5      QU R                  P76 $ )Nz{}.{}.{}rv  )formatry  rT   r  r}  r,   s    r!   r  OpOverload.__str__n  s6      T$,,"3"3"9"9$"?TASASTTr0   r;   c                    > [         TU ]  U5      =(       d.    [        R                  R	                  U R                  5       U5      $ r'   )r   r<   r?   r@   %_dispatch_has_kernel_for_dispatch_keyrT   r   s     r!   r<   &OpOverload.has_kernel_for_dispatch_keyq  s9    w2
 LXX;;DIIKK	Lr0   rC   c                    > [         R                  R                  U R                  5       U5      =(       d    [        TU ]  U5      $ r'   )r?   r@   )_dispatch_has_kernel_for_any_dispatch_keyrT   r   rD   )r-   rC   r   s     r!   rD   *OpOverload.has_kernel_for_any_dispatch_keyv  s7    xxAAIIK
 9W4R8	9r0   c                     U R                   $ r'   )r  r,   s    r!   r   OpOverload.namespace{  s    r0   c                     [         R                  nXR                  ;   =(       d.    [        R                  R                  U R                  5       U5      $ r'   )r   r   r)   r?   r@   r  rT   )r-   dks     r!   _can_decomposeOpOverload._can_decompose  s=    22__$ 
(V(VIIK)
 	
r0   c                    [         R                  nX0R                  ;   a  U R                  U   " U0 UD6$ [        R                  R                  U R                  5       U5      (       a  U R                  " U/UQ70 UD6$ [        $ r'   )	r   r   r)   r?   r@   r  rT   rx  rk   )r-   r5   r6   r  s       r!   	decomposeOpOverload.decompose  sn    22 
 ??2&777XX;;DIIKLL;;r3D3F33!!r0   keyc                 <    U R                   R                  US 5        g r'   )r(   pop)r-   r  s     r!   _uncache_dispatchOpOverload._uncache_dispatch  s      d+r0   c                 T  ^ ^ TT R                   ;   a  [        T  ST S35      eT[        R                  :X  a  [	        T [
        5      (       d-  T R                  (       d  TT R                   T'   [        T 5        T$ S[        R                  S[        R                  S[        4UU 4S jjnUT R                   T'   [        T 5        U$ [        R                  R                  T5      nU[        R                  :X  ar  [!        5       nUS:  ab  [        R                  R#                  [        R                  5      (       d0  S[        R                  S[        R                  S[        4U 4S jjnU$ [%        T T5      nT[        R                  :g  nT[        R&                  :X  aO  SS KJs  Jn  UR.                  (       a5  UR1                  T U5      nU(       a  UT R                   T'   [        T 5        U$ T R2                  R5                  XU5      nU(       a  UT R                   T'   [        T 5        U$ )	N z already in dispatch cacher5   r6   rF   c                  ^  > SSK Jn  [        U" 5       5      nUc  [        S5      eUTR                  ;  a  [        T[        5      (       aa  [        R                  R                  R                  5        n[        R                  R                  R                  " UT/U Q70 UD6sS S S 5        $ TR                  " T/U Q70 UD6$ [        R                  R                  R                  5        nTR                  U   " U/U Q70 UD6sS S S 5        $ ! , (       d  f       NY= f! , (       d  f       g = f)Nr   r   zDIllegal invocation of dispatch on DispatchKey.Python without a mode.)r   r   rQ   rN   r*   rP   TorchBindOpOverloadr?   utils_python_dispatchr   _libraryhandle_dispatch_moderx  )r5   r6   r   r   rb   r  r-   s        r!   r   )OpOverload._get_dispatch.<locals>.handler  s   S !!;!=>	$(^  D$9$99!$(;<<!KK88NNPTX#(>>#7#7#L#L $d$-1$5;$ QP  ${{3@@@@[[11GGIT00;DR4R6R JI QP JIs   3/D*D
D
D,r   c                     > [         R                  S 5       nU" 5        n[        R                  R                  R
                  " UT/U Q70 UD6sS S S 5        $ ! , (       d  f       g = f)Nc               3   `   #    [        5       n  U v   [        U 5        g ! [        U 5        f = f7fr'   )r]  rY  )top_modes    r!   (_temporarily_pop_modes_from_pre_dispatch[OpOverload._get_dispatch.<locals>.handler.<locals>._temporarily_pop_modes_from_pre_dispatch  s(     #>#@="*N28<28<s   . .+.)
contextlibcontextmanagerr?   r  r  r  )r5   r6   r  r   r-   s       r!   r   r    s`    ..= /= BCy$~~33HH%t .2 6<  DCCs   /A
A&)r(   rN   r   rR   rP   r  r*   rj  r   r5   r6   r   r?   r@   r   r   r   r   r   rr   torch._dispatch.python	_dispatchpythonCROSSREF_FUNCTIONALIZEmake_crossref_functionalizer)   r:  )	r-   r  r   r   curr_stack_lenr   cache_result
pydispatchrs	   ``       r!   _get_dispatchOpOverload._get_dispatch  s   $&&& D63%/I!JKK+$$$d$788AVAV,/$$S)d#
Srww S")) S S S2 )0D  %$N!HH::3? 7 77CEN "GG&& 
277 bii B & c*	 k555
 ++++7700$@@yQ07D((-!$'OO	5()D  %$r0   c                     U R                   $ r'   r  r,   s    r!   rT   OpOverload.name  r  r0   c                     U R                   $ r'   )rz  r,   s    r!   rp  OpOverload.overloadpacket  s    ###r0   c                     U R                   $ r'   r  r,   s    r!   r}   OpOverload.op  r   r0   c                     U R                   $ r'   )r{  r,   s    r!   rs  OpOverload.tags
  s    zzr0   )r  rx   rw   ry   r  r   r  rw  rx  r}  rz  ry  r{  r  r'   )-rw   rx   ry   rz   r   r   r   r   r   r?   r@   FunctionSchemar   r   r.   r   strr  r  _DispatchOperatorHandler  r  r  r5   r6   r7   DispatchKeySetr  r  r  r  r<   rD   r  r   r  r  r  r  rT   rp  r}   rs  r|   r  r  s   @r!   rf  rf    s1   *=**= RV*= KO4b89	*=
 ''*= 3i*= 
*=X <C < < < < < 
99 
 
g
) )BII )" )
F00F9;FLNIIF	F
UL[ LT L
9%((2I2I 9d 9
 3  
 
"rww "")) " "*,[ ,T ,_ _xB?O1O _B $ $    r0   c                       \ rS rSrS\\   4S jrS\R                  S\R                  S\
4S jrS\\   S\R                  S\R                  S\
4S jrS	rg
)r  i  rF   c                 b  ^  [         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  [         R                  [         R                  /nS[         4U 4S jjnU Vs/ s H  nU" U5      (       d  M  UPM     sn$ s  snf )Nr  c                 D  > [         R                  R                  TR                  5       U 5      (       a.  [         R                  R	                  TR                  5       U 5      $ U TR
                  ;  =(       d)    TR
                  U    [         R                  R                  L $ r'   )r?   r@   r  rT   0_dispatch_kernel_for_dispatch_key_is_fallthroughr)   r  fallthrough_kernel)r  r-   s    r!   (_may_use_fallthrough_instead_of_fallbackWTorchBindOpOverload._fallthrough_keys.<locals>._may_use_fallthrough_instead_of_fallback$  sv    xx==diik3OOxxPPIIK 
 4??* L??3'5==+K+KKr0   )	r   r   AutogradCPUAutogradCUDAADInplaceOrViewBackendSelectPythonTLSSnapshotPythonDispatcherrr   )r-   _DEFAULT_FALLTHROUGH_KEYSr  r  s   `   r!   _fallthrough_keys%TorchBindOpOverload._fallthrough_keys  s       ##$$''%%))((%%	%
!		+ 		 1
07< 0
 	
 
s   B,#B,r5   r6   c                    [        X5      (       a$  U R                  " U R                  5       /UQ70 UD6$ U R                  " U0 UD6$ r'   )_must_dispatch_in_python_dispatch_in_pythonr  rw  r4   s      r!   r7   TorchBindOpOverload.__call__7  sG    #D11 ++D,B,B,DVtVvVVxx(((r0   fallthrough_keysc           	      \   [         R                  R                  5       nU H  nUR                  U5      nM     [	        X#U5      nUR                  5       nXpR                  ;  a  U R                  U5      OU R                  U   n[        U[        5      (       aa  [         R                  R                  U R                  5       U5      (       a  U R                  " X/-   /UQ70 UD6$ [        SU  SU SU S35      e[        U[        5      (       d  [        S[!        U5       35      eU" U0 UD6$ )NzTorchbind op z4 received a FakeScriptObject input when dispatching z. but no python implementation is found. Please file an issue on this when you encounter this error. This error can happen when you export or compile the model. It can still happen even if a C++ implementation for zz.  has been registered. That's because FakeScriptObject purely lives in python and cannot work  with a C++ implementation.zhandler must be callable, got )r?   r@   r   r   r  r  r(   r  rP   r   r  rT   r  rS   r   rN   rQ   )	r-   r  r5   r6   r   r  r  r   r   s	            r!   r  'TorchBindOpOverload._dispatch_in_python?  sS     %xx==?#C#7#>#>s#C  $ +49MN'==? #7#77 |,%%l3 	 g{++ xxHH		\  //$~5   v%YZaYb cI JV W.	/  '8,, #A$w-!QRR'''r0   r_   N)rw   rx   ry   rz   r   r   r  r   r5   r6   r   r7   r  r|   r_   r0   r!   r  r    sh    
4#4 
B) )BII )" )(( $[ 1((:<''((MOYY((	((r0   r  rF   c                 0   [        U [        R                  R                  R                  5      (       a  g[        U [
        [        45      (       a  [        S U  5       5      $ [        U [        5      (       a   [        S U R                  5        5       5      $ g)zCheck if obj is or contains a FakeScriptObject.
This is load-bearing for TorchBindOpOverloads so we avoid pytree
since it's much slower.
Tc              3   8   #    U  H  n[        U5      v   M     g 7fr'   _contains_fake_script_object)r   items     r!   r   /_contains_fake_script_object.<locals>.<genexpr>r  s     F#$/55#r   c              3   8   #    U  H  n[        U5      v   M     g 7fr'   r  r   vs     r!   r   r  t  s     ILq/22Lr   F)
rP   r?   r  fake_class_registryFakeScriptObjectr   r   r   dictr   )objs    r!   r  r  j  sm    
 #u~~99JJKK	C$	'	'F#FFF	C		ICJJLIIIr0   c                     [        S U  5       5      =(       d2    [        U5      =(       a     [        S UR                  5        5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr'   r  r   s     r!   r   +_must_dispatch_in_python.<locals>.<genexpr>y  s     ADS+C00Dr   c              3   8   #    U  H  n[        U5      v   M     g 7fr'   r  r  s     r!   r   r  z  s     Vo9!<<or   )r   r  r   r  s     r!   r  r  x  s7    ADAA VVVfmmoVVr0   r   c                 :    [        S U R                   5       5      $ )Nc              3   j   #    U  H)  n[        UR                  [        R                  5      v   M+     g 7fr'   )rP   rQ   r?   	ClassTyper   s     r!   r   )_has_script_object_arg.<locals>.<genexpr>  s$     Q@Pz#((EOO44@Ps   13)r   r   )r   s    r!   _has_script_object_argr  ~  s    Q@P@PQQQr0   c            
          \ rS rSr% Sr\\   \S'   S\S\S\\	\
4   S\\   SS	4
S
 jrSS jrS rS rS r\S 5       r\S 5       rS\S\\	\
4   4S jrS\\   4S jrS\	R0                  S\	R2                  S\
4S jrS rSrg	)rq  i  	torch.ops__file__qualified_op_nameop_namer}   overload_namesrF   Nc                     Xl         X l        X0l        X@l        / U l        [        S U R                  R                  5        5       5      U l        g )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr'   )r  )r   r   s     r!   r   ,OpOverloadPacket.__init__.<locals>.<genexpr>  s      .
9Ov"6**9Or   )	_qualified_op_namerw   rw  _overload_names_dirr   _schemasr   _has_torchbind_op_overload)r-   r  r  r}   r  s        r!   r.   OpOverloadPacket.__init__  sH     #4-!	*- .
9=9M9M9O.
 +
'r0   c                     U $ r'   r_   r  s     r!   r  OpOverloadPacket.__deepcopy__  r  r0   c                 R    SR                   " U R                  R                  S5      6 $ )Nz<OpOverloadPacket(op='{}.{}')>rv  r  r  r  r,   s    r!   r  OpOverloadPacket.__repr__  s)    /66$$**40
 	
r0   c                 ,    [        U R                  5      $ r'   r  r,   s    r!   r  OpOverloadPacket.__hash__  r  r0   c                 R    SR                   " U R                  R                  S5      6 $ )Nz{}.{}rv  r'  r,   s    r!   r  OpOverloadPacket.__str__  s"    ~~t66<<TBCCr0   c                     U R                   $ r'   r  r,   s    r!   r}   OpOverloadPacket.op  r   r0   c                     U R                    Vs0 s H.  nU[        R                  R                  U R                  U5      _M0     sn$ s  snf r'   )r  r?   r@   _get_schemar  )r-   r|  s     r!   r!  OpOverloadPacket._schemas  sK     "&!5!5
!5 588//0G0GWW!5
 	
 
s   5Ar  c           
          UR                  S5      (       a  [        U R                  U5      $   US:X  a  SOUn[
        R                  R                  U R                  U5      nUc  [        S[	        U 5       S	U S35      eUu  pEn[
        R                  R                  U R                  U5      n[        U5      (       d  [        XXWU5      O[        XXWU5      n[        XU5        U R                  R                  U5        U$ ! [         a3    [        S[	        U 5       S[	        U R                  5       SU S35      S ef = f! [          a    [        S[	        U 5       S	U S35      S ef = f)
N__'zH' can't have an overload name beginning with '__' and the underlying op z has no attribute z either.r   ru  zThe underlying op of 'z' has no overload name ')
startswithgetattrrw  AttributeErrorr  r?   r@   _get_operation_overloadr  r0  r  rf  r  setattrr   r   rS   )	r-   r  use_key
op_dk_tagsop_op_dk_rs  r   overloads	            r!   __getattr__OpOverloadPacket.__getattr__  s   	~~d##txx-- $	9,b#G99''J !$,SYK7OPSuTUV  !+CXX))$*A*A7KF .f55 4fd;(FDI  Dx(IIS!OA  	
 !CI; !!$TXX/A#hP 	B  	 (T3KC5PQR	s   +D CE =E'E+c                 ,    [        U R                  5      $ r'   iterr   r,   s    r!   __iter__OpOverloadPacket.__iter__      DIIr0   r5   r6   c                    U R                   (       a  [        X5      (       a  [        U /UQ70 UD6$ U R                  " U0 UD6$ r'   )r"  r  !_call_overload_packet_from_pythonrw  r4   s      r!   r7   OpOverloadPacket.__call__  sA     **/G/U/U4TKDKFKKxx(((r0   c                 V    U R                    Vs/ s H  o(       a  UOSPM     sn$ s  snf )Nr   )r  )r-   ns     r!   	overloadsOpOverloadPacket.overloads  s)    /3/C/CD/C!QI%/CDDDs   &)rw   r   r"  rw  r  r  r'   )rw   rx   ry   rz   r  r   r  r  r   r   r   r   r.   r  r  r  r  r  r}   r!  rf  r?  r   rD  r5   r6   r7   rL  r|   r_   r0   r!   rq  rq    s    )Hhsm)

 
 RV	

 S	
 

&

D   
 
/s /z"b&'9 /b(3- 
) )BII )" )Er0   rq  r5   r6   c                    [         R                  R                  " U /UQ70 UD6u  p4U(       a  U$ 0 nS nU R                  5        H?  n[	        X5      n [         R                  R
                  " UR                  /UQ70 UD6n	Un  O   U(       a  U" U0 UD6$ SU  S3nUR                  5        H  u  pUSU SU S3-  nM     [        U5      e! [         a  n
XU'    S n
A
M  S n
A
ff = f)Nz'Fail to match any TorchBindOverload of z with following exceptions:
zOverload name z:
 
)	r?   r@   (_maybe_call_torch_function_for_op_packetrL  r6  &_check_schema_allow_fake_script_objectry  rS   items)r}   r5   r6   torch_function_calledret
exceptionsfound_opr|  ri  _eerr_msgr  msgs                 r!   rH  rH    s    "'!R!R
""" 
 JHb0	*??##&*.4A #H ( ((( 2"5RS  $$&^C5SE44 '
w
  	*()}%	*s   0C
C%C  C%c                   b   ^  \ rS rSrSrSrS\SS4U 4S jjrS\\   4S jr	S	\S\
4S
 jrSrU =r$ )_OpNamespacei5  a  
An op namespace to dynamically bind Operators into Python.

Say a user has created a custom Operator called "my_namespace::my_op". To
call this op, the user will write torch.ops.my_namespace.my_op(...).
At startup, this operation will not yet be bound into Python. Instead, the
following sequence of magic tricks will occur:
1. `torch.ops.my_namespace` will invoke the `__getattr__` magic method
   on the `torch.ops` object, which will create a new `_OpNamespace`
   object called `my_namespace` and set it as an attribute on the `ops`
   object.
2. `torch.ops.my_namespace.my_op` will then invoke `__getattr__` on
   the `my_namespace` object, which will retrieve the operation via
   `torch.get_operation`, a function bound from C++, and then in a similar
   fashion bind this new object onto the `my_namespace` object.
3. `torch.ops.my_namespace.my_op(...)` then calls this new operation
    and subsequent accesses will incur no further lookup (the namespace and
    operation will already exist).
r  rT   rF   Nc                 D   > [         TU ]  SU-   5        Xl        / U l        g )Nz
torch.ops.)r   r.   rT   r   )r-   rT   r   s     r!   r.   _OpNamespace.__init__L  s!    ,-	!	r0   c                 ,    [        U R                  5      $ r'   rB  r,   s    r!   rD  _OpNamespace.__iter__Q  rF  r0   r  c                    US;   a  [        SU SU R                   S35      eU R                  nU SU 3nU R                  S-   U-   n [        X45      u  pVUc  [        SU R                   SU S35      e XEl        [        X1XV5      nU R                  S-   U-   Ul        [        XU5        U R                  R                  U5        U$ ! [         a"  n[        SU R                   SU S35      UeS nAff = f)	N)
__origin____self__zInvalid attribute 'z' for '_OpNamespace' 'r4  rv  r   z'_OpNamespace' 'z' object has no attribute ')	r7  rT   rx   _get_packetrS   rq  r9  r   r   )	r-   r  namespace_namer  module_namer}   r  rX  opoverloadpackets	            r!   r?  _OpNamespace.__getattr__T  s2   00 %gY.DTYYKqQ  -.b	:oo+n<	!,->!LBz$&tyyk1LWIUVW   $+
 '+oo&;n&L# 	/0		!!  	 !"499+-H	QRS	s   	,C 
C4C//C4)r   rT   )rw   rx   ry   rz   r{   r  r  r.   r   rD  rq  r?  r|   r  r  s   @r!   r\  r\  5  sK    ( H"S "T "
(3- " 3 " +; "  " r0   r\  c                     [         R                  R                  U 5      u  p#Ub/  [         R                  R                  R                  X 5        Xl        X#4$ r'   )r?   r@   _jit_get_operationjit	_builtins_register_builtinrx   )qualname	op_moduler}   r  s       r!   rd  rd  y  sF    44X>B	~ 			--b;!r0   c                     [        U R                  U R                  R                  5      u  pUc  [	        SU R                   35      eXl        X l        g )Nzfailed to get packet for )rd  r  rw  rx   rN   r  )packetr}   r  s      r!   _refresh_packetrr    sK    $V%>%>

@U@UVB	z89R9R8STUUJ+r0   c                   V   ^  \ rS rSrSrS	U 4S jjrS\\   4S jrS\S\	4S jr
SrU =r$ )
_HigherOrderNamespacei  r  rF   c                 2   > [         TU ]  S5        / U l        g )Nr   )r   r.   r   r-   r   s    r!   r.   _HigherOrderNamespace.__init__  s    12!	r0   c                 ,    [        U R                  5      $ r'   rB  r,   s    r!   rD  _HigherOrderNamespace.__iter__  rF  r0   rT   c                     [         R                  U5      nUc  [        SU S35      e[        XU5        U R                  R                  U5        U$ )NzJ'_HigherOrderNamespace' 'torch.ops.higher_order' object has no attribute 'r4  )r   r:  r7  r9  r   r   )r-   rT   r}   s      r!   r?  !_HigherOrderNamespace.__getattr__  sV    ""4(: \]a\bbcd  	B			r0   )r   )rF   N)rw   rx   ry   rz   r  r.   r   r  rD  r   r?  r|   r  r  s   @r!   rt  rt    s6    H"(3- 	 	(; 	 	r0   rt  c                   ^   ^  \ rS rSrSrU 4S jrS\S\4S jrS\	\   4S jr
S rS	 rS
rU =r$ )_Opsi  z_ops.pyc                 n   > [         TU ]  S5        [        5       U l        [	        5       U l        / U l        g )Nr  )r   r.   r7  loaded_librariesrt  r   r   rv  s    r!   r.   _Ops.__init__  s,    % #13	r0   rT   rF   c                 j    [        U5      n[        XU5        U R                  R                  U5        U$ r'   )r\  r9  r   r   )r-   rT   r   s      r!   r?  _Ops.__getattr__  s.     &	I&		r0   c                 ,    [        U R                  5      $ r'   rB  r,   s    r!   rD  _Ops.__iter__  rF  r0   c                 0    [         R                  " U5        g)a#  
Imports a Python module that has torch.library registrations.

Generally, to extend PyTorch with custom operators, a user will
create a Python module whose import triggers registration of
the custom operators via a torch.ops.load_library call or a call
to one or more torch.library.* APIs.

It is unexpected for Python modules to have side effects, so some
linters and formatters will complain. Use this API to import Python
modules that contain these torch.library side effects.

Args:
    module (str): The name of the Python module to import

N)	importlibimport_module)r-   modules     r!   r  _Ops.import_module  s    " 	'r0   c                     [         R                  " U5      n[        5           [        R                  " U5         SSS5        U R                  R                  U5        g! [
         a  n[        SU 35      UeSnAff = f! , (       d  f       NK= f)a  
Loads a shared library from the given path into the current process.

The library being loaded may run global initialization code to register
custom operators with the PyTorch JIT runtime. This allows dynamically
loading custom operators. For this, you should compile your operator
and the static registration code into a shared library object, and then
call ``torch.ops.load_library('path/to/libcustom.so')`` to load the
shared object.

After the library is loaded, it is added to the
``torch.ops.loaded_libraries`` attribute, a set that may be inspected
for the paths of all libraries loaded using this function.

Args:
    path (str): A path to a shared library to load.
zCould not load this library: N)	r   resolve_library_pathr"   r   CDLL	ExceptionOSErrorr  r   )r-   pathrX  s      r!   load_library_Ops.load_library  sw    $ 33D9_MD!  	!!$'  M =dVDE1LM _s(   A?A
A<(A77A<<A??
B)r   r   r  )rw   rx   ry   rz   r  r.   r  r\  r?  r   rD  r  r  r|   r  r  s   @r!   r}  r}    s?    H  (3- (&( (r0   r}  ops)F)er  r  r   r  rJ   r   typescollections.abcr   r   	functoolsr   typingr   r   r   r	   r
   r   typing_extensionsr   r   r?   torch.utils._pytreer  _pytreer   r   torch._Cr   r   r   torch._functorch.pyfunctorchr   r   r   r   r   ImportErrorrQ   rk   rj   r   r   r   hasattrr   r  r"   r$   r   r   r
  r  r  r  r  r  r  AutocastCPUAutocastCUDAAutocastXPUr   ABCr   r   r  r!  r"  r-  re  rR  rY  r]  r   r`  r   rG  r7  rg  rj  rl  rn  rf  r  r  r  r  r  r  rq  r5   r6   rH  
ModuleTyper\  rd  rr  rt  r}  r  r_   r0   r!   <module>r     s   
     
  . % L L 0  $ $ ! X J :.(
 H T3tS! C!12UwsDT7U  & & V" V"t2UL 2U[ 2Uj 79 4223 8   !!6 2^, ^B	38
,
 
2 &C%D "(V-X`M7	: .
 !$
C % 

pwr2v prR(*RV, R(j d R5#7#7 RD RuEwr2v uEt% R % )+% <>II% % nA 5## A H,E,, ,A(5 A(J FT ].  .n-.s   .I I&%I&