
    ȅi                        % 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$  \(       a  S S
K%J&r&  \" S\S9r'\" SSS9r(\)" \S5      =(       a	    \)" \S5      r*\RV                  S 5       r, " S S5      r-S\-S\4S jr.0 r/\0\1S4   \2S'   \Rf                  \Rh                  \Rj                  \Rl                  \Rn                  \Rp                  \Rr                  /r: " S S\-\ Rv                  5      r<S r=S r>S r?S r@ " S S5      rA\A" 5       qBSAS  jrCS! rDS" rES# rFS$ rGS% rHS& rI\J" 5       qK\JS'   \2S('   S) rLS* rMS+ rN " S, S'\-\\(\'4   5      rO " S- S.\O\(\'4   5      rPS/ rQS0\R                  S1\S4S2 jrT " S3 S4\\(\'4   5      rUS\U\(\'4   S5\(R                  S6\(R                  S1\'4S7 jrX " S8 S9\R                  5      rZS: r[S; r\ " S< S=\R                  5      r] " S> S?\R                  5      r^\^" 5       r_\^\2S@'   g)B    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)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    D/home/james-whalen/.local/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)OperatorBase3   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__9   s0      UW BD  	  "    c                     [         er&   NotImplementedErrorr,   argskwargss      r    __call__OperatorBase.__call__c       !!r/   c                     XR                   ;   $ r&   )r(   )r,   ks     r    has_kernel_for_dispatch_key(OperatorBase.has_kernel_for_dispatch_keyf   s    OO##r/   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_keyi   s9    A8822155"&&)) ! r/   r:   returnc                 h   ^ ^ S[         [        [        4   S[         [        [        4   4UU 4S jjnU$ )NfnrE   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)rG   r:   r,   s    r    inner#OperatorBase.py_impl.<locals>.inners   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  &&(Ir/   )r   r   r   )r,   r:   rT   s   `` r    py_implOperatorBase.py_implo   s5    	hr2v& 	8BF+; 	 	@ r/   rG   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PythonFunctionalizeAPIr4   r5   rE   c                  &   > T" T" 5       /U Q70 UD6$ r&    )r4   r5   rY   rG   s     r    functionalize_dk_fn?OperatorBase.py_functionalize_impl.<locals>.functionalize_dk_fn   s    )+=d=f==r/   modec                 (   > T" T" U 5      /UQ70 UD6$ r&   r^   )ra   r4   r5   r\   rG   s      r    functionalize_dispatch_mode_fnJOperatorBase.py_functionalize_impl.<locals>.functionalize_dispatch_mode_fn   s      ,T2DTDVDDr/   c                 (   > T" T" U 5      /UQ70 UD6$ r&   r^   )interpreterr4   r5   r[   rG   s      r    functionalize_functorch_fnFOperatorBase.py_functionalize_impl.<locals>.functionalize_functorch_fn   s      /<NtNvNNr/   )#torch._subclasses.functional_tensorrY   rZ   r[   r\   r   r4   r5   r   rV   r   Functionalizer   )	r,   rG   rZ   r_   rc   rg   rY   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	r/   c                     [         er&   r1   r+   s    r    rS   OperatorBase.name   r8   r/   )r'   r*   r(   r)   N)__name__
__module____qualname____firstlineno____doc__r-   r6   r;   rC   rP   r   r>   rL   r   r   r   r   r   rV   r   rk   rS   __static_attributes__r^   r/   r    r#   r#   3   s    
("T"$$!"T%,,%77-G+U$ 
8BF#$hr2v&66	7$b;'=r'ABBFG	+4b892=	>>"r/   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CompositeExplicitAutogradrC   r>   r?   *_dispatch_get_backend_keyset_from_autograd%CompositeImplicitAutogradNestedTensorCompositeImplicitAutogradAutogradOther _dispatch_autogradother_backendsrR   AutogradFuncTorchBatchedDecomposition_dispatch_has_backend_fallbackr2   )ru   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Tr/   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-   rP   r   rR   _namero   r   _nsrp   
_cacheabler>   r?   _dispatch_keyset_fullnon_fallthrough_keys2_HIGHER_ORDER_OP_DEFAULT_FALLTHROUGH_DISPATCH_KEYSfallthrough)r,   rS   r   dispatch_key	__class__s       r    r-   HigherOrderOperator.__init__  s    :,,a  
 "&$!2#$)HH$B$B$D!NL\* Or/   r:   rE   c                    > [        U[        5      (       a@  U R                  R                  U5      (       d   U R                  R	                  U5      U l        [
        TU ]  U5      $ r&   )rO   r   r   rA   addr   rV   r,   r:   r   s     r    rV   HigherOrderOperator.py_impl(  sP     a%%d.G.G.K.KA.N.N(,(A(A(E(Ea(HD%wq!!r/   rG   c                    ^ ^ S[         R                  S[         R                  S[        4UU 4S jjnT R	                  [
        R                  5      " U5        T$ )Nr4   r5   rE   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>7  s    aoo-r/   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>A  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_onlyrL   r?   _AutoDispatchBelowAutogradtorch._higher_order_ops.utilsr   
gen_schemaany	argumentsrR   rS   )r4   r5   r   schemarG   r,   s       r    maybe_run_autograd@HigherOrderOperator.py_autograd_impl.<locals>.maybe_run_autograd4  s    ((**f.B.B-$/ /
 XX88:00 ;: Ft$$$9&9@v/?/?@@@&tyy{m ,_ _  t&v&& ;:s   +C((
C6)r   r4   r5   r   rV   r   r   )r,   rG   r   s   `` r    py_autograd_impl$HigherOrderOperator.py_autograd_impl0  sI    	'bgg 	' 	'r 	' 	'. 	[))*+=>	r/   c                     U R                   $ r&   )r   r+   s    r    	namespaceHigherOrderOperator.namespaceO      xxr/   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   rp   ro   r>   	_inductorconfig!unsafe_marked_cacheable_functionsrO   
_functorch.autograd_cache_allow_custom_autograd_functions)r,   r   s     r    r   HigherOrderOperator.cacheableS  sr    L OO //"!DMM?3%%GGH 47 [$$++ZZ	
r/   c                 D    U R                   R                  U5      U l         g r&   )r   remove)r,   r   s     r    r   HigherOrderOperator.fallthrougha  s    $($=$=$D$D\$R!r/   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      $ )NrQ   )r>   r?   _dispatch_keysrA   )tensors    r    has_python_key4HigherOrderOperator.dispatch.<locals>.has_python_keyx  s"    xx..v6::8DDr/   c                    > [        U [        R                  5      (       a   T" U 5      (       a  TR                  U 5        g g g r&   )rO   r>   rL   append)r   r   overloaded_args_lists    r    check_overloaded6HigherOrderOperator.dispatch.<locals>.check_overloaded{  s5    c5<<00^C5H5H(//4 6I0r/   )_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 rw   z (resolved from )z&unexpected DispatchKey in py_kernels: )%torch.utils._python_dispatchr   r'   rO   r   rM   FuncTorchDynamicLayerFrontModer   rQ   valueslisttupler   rP   r)   supports_higher_order_operators__torch_dispatch__r2   r   NotImplementedr>   r?   _disabled_torch_dispatch_impl_subclassesfake_tensor
FakeTensorFakeTensorMode	fake_mode	TypeErrorro   _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   r4   r5   r   kernelr   r   aoverloaded_argsr   	curr_modehandlerra   resultsubclass_typefunctionality_key	final_keyr   r   s                     @@r    dispatchHigherOrderOperator.dispatchf  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,   r4   r5   	flat_argsdispatch_key_sets        r    r6   HigherOrderOperator.__call__  s    "40	??--i88??88"&*0  +49R9RS}}-CCEWWPVWWr/   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.)r2   r   r3   s      r    r   HigherOrderOperator.gen_schema  s$    !"4::, // 0
 	
r/   c                 $    U R                  5        $ r&   )rS   r+   s    r    __str__HigherOrderOperator.__str__  s    ))+r/   c                     U R                   $ r&   r   r+   s    r    rS   HigherOrderOperator.name      zzr/   c                     U $ r&   r^   r,   memos     r    __deepcopy__ HigherOrderOperator.__deepcopy__#      r/   )rp   ro   r   r   r   r   r&   ) ro   rp   rq   rr   r-   rP   r   r>   rL   r   r   r   r   r   rV   r   propertyr   r	   boolr   r   r   abcabstractmethodr6   r   r  rS   r  rt   __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,
  r/   c                 .    [         R                  " U 0 UD6$ r&   )r   arg_tree_leavesr4   r5   s     r    r   r   '  s    !!42622r/   c                 .    [        X5      n[        X25      $ r&   )_get_tensorskey_extractor)r4   r5   r   tensorss       r    r   r   +  s    4(G77r/   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   rO   r>   rL   r   )r4   r5   flat_allr   tensor_argss        r    r  r  0  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  8  s[    hh668GEHH33F;; @@BBG GNr/   c                   ,    \ rS rSrS rS rS rS rSrg)_ModeStackStateForPreDispatchiN  c                 $    S S /U l         S U l        g r&   )*_ModeStackStateForPreDispatch__infra_modes_schema_check_moder+   s    r    r-   &_ModeStackStateForPreDispatch.__init__O  s    "D\"&r/   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*  rM   )r,   indexra   s      r    set!_ModeStackStateForPreDispatch.setS  sO    C**++ Ec$J\J\F]E^_  %)5!r/   c                     U[        U R                  5      :  a$  [        SU S[        U R                  5       35      eU R                  U   $ r.  r/  )r,   r1  s     r    get!_ModeStackStateForPreDispatch.getZ  sR    C**++ Ec$J\J\F]E^_  !!%((r/   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&   )r0  r*  intr+  )r,   is     r    count#_ModeStackStateForPreDispatch.counta  sD    t11C1!A1CDs##4/H
 
 	
Cs
   AA)__infra_modesr+  N)	ro   rp   rq   rr   r-   r2  r5  r:  rt   r^   r/   r    r(  r(  N  s    '))
r/   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PROXYr5  !mode_stack_state_for_pre_dispatchr2  
FUNCTIONALr+  )current_modecurrent_mode_stack_pre_dispatchmode_keys    r    _unset_mode,unset_mode_pre_dispatch.<locals>._unset_modex  s     uxx55;;;:>>qAL-/33At<77BBB:>>qAL-/33At<<>QQLEI-/Br/   r   F)rB  r>   r?   r@  rA  rC  rM   r   '_dispatch_tls_set_dispatch_key_includedr   r   )rF  schema_check
valid_keysrG  rD  new_pre_dispatch_lenrE  s   `     @r    unset_mode_pre_dispatchrM  j  s    &G&I#&&,,&&11J 
 :.zl&
K
 	
  !RSS   =LAC
 q 889P9PRWXr/   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   )rZ   )SchemaCheckMode)ProxyTorchDispatchModezSmode must be FunctionalTensorMode, ProxyTorchDispatchMode, or SchemaCheckMode, got zYSchemaCheckMode for pre-dispatch must be used exclusively, found other modes on the stackr?  z.FunctionalTensorMode slot already occupied by z0ProxyTorchDispatchMode slot already occupied by T)ri   rZ   #torch._subclasses.schema_check_moderO  "torch.fx.experimental.proxy_tensorrP  rO   rM   rP   r   rB  r+  r5  r2  r>   r?   rI  r   r   )ra   rZ   rO  rP  previous_mode_stack_lenrD  s         r    _set_mode_pre_dispatchrT    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 $r/   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)rJ  r?  )rB  r   rM   r+  rM  r5  r>   r?   r@  rC  rA  )
mode_stackpre_dispatch_lens     r    _pop_mode_from_pre_dispatchrX    s    24J=?1=>>$$0&t$??~~a$&uxx'E'E'P'PQQ~~a$&uxx'E'E'K'KLL %r/   c                  2    [        5       R                  5       $ r&   )rB  r:  r^   r/   r    r   r     s    ,.4466r/   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 r?  )r>   r?   r@  rA  rB  r5  rC  rM   )rF  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9r/   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   r?  r   )rB  r+  r:  r5  )	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?
 r/   c                      [         $ r&   )"_mode_stack_state_for_pre_dispatchr^   r/   r    rB  rB    s    --r/   
OpOverload
cached_opsc                 .    [         R                  U 5        g r&   )rb  r   )op_overloads    r    add_cached_opre    s    NN;r/   c                  ,    [         R                  5         g r&   )rb  rN   r^   r/   r    reset_cached_opsrg    s    r/   c                      [         $ r&   )rb  r^   r/   r    get_cached_opsri    s    r/   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,$ )'ra  i  overloadpacketOpOverloadPacketru   op_dkr   tagsrE   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   ::r?  )r   r-   _op_op_dk_schema_overloadpacket_tagsoverload_name_overloadnamer>   Tagnondeterministic_seeded_nondeterministic_seededrS   r   splitro   rp   rq   __annotations__library_defs_defined_in_pythonr   
alias_infor   is_view)	r,   rk  ru   rm  r   rn  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r/   c                 P    U R                   R                  R                  SSS9S   $ )Nrq  r?  maxsplitr   rt  rS   r|  r+   s    r    
_namespaceOpOverload._namespace:  '    ||  &&ta&8;;r/   c                 P    U R                   R                  R                  SSS9S   $ )Nrq  r?  r  r  r+   s    r    _opnameOpOverload._opname>  r  r/   c                     [         R                  R                  U R                  R                  U R                  R
                  5      $ r&   )r>   r?   _dispatch_find_schema_or_throwrt  rS   rw  r+   s    r    _handleOpOverload._handleB  s2    xx66LLt||99
 	
r/   c                     U $ r&   r^   r  s     r    r  OpOverload.__deepcopy__I  r  r/   c                 V    SU R                    SU R                   SU R                   S3$ )Nz<OpOverload(op='r   z', overload='z')>)r  r  rx  r+   s    r    __repr__OpOverload.__repr__L  s.    !$//!2!DLL>tOaOaNbbeffr/   r4   r5   c                &    U R                   " U0 UD6$ r&   rr  r3   s      r    r6   OpOverload.__call__Q  s    xx(((r/   keysetc                B    U R                   R                  " U/UQ70 UD6$ r&   )r  redispatch_boxed)r,   r  r4   r5   s       r    
redispatchOpOverload.redispatchV  s#     ||,,VEdEfEEr/   c                 ,    [        U R                  5      $ r&   hashrr  r+   s    r    __hash__OpOverload.__hash__[      DHH~r/   c                     SR                   " / U R                  R                  R                  S5      QU R                  P76 $ )Nz{}.{}.{}rq  )formatrt  rS   r|  rx  r+   s    r    r  OpOverload.__str___  s6      T$,,"3"3"9"9$"?TASASTTr/   r:   c                    > [         TU ]  U5      =(       d.    [        R                  R	                  U R                  5       U5      $ r&   )r   r;   r>   r?   %_dispatch_has_kernel_for_dispatch_keyrS   r   s     r    r;   &OpOverload.has_kernel_for_dispatch_keyb  s9    w2
 LXX;;DIIKK	Lr/   rB   c                    > [         R                  R                  U R                  5       U5      =(       d    [        TU ]  U5      $ r&   )r>   r?   )_dispatch_has_kernel_for_any_dispatch_keyrS   r   rC   )r,   rB   r   s     r    rC   *OpOverload.has_kernel_for_any_dispatch_keyg  s7    xxAAIIK
 9W4R8	9r/   c                     U R                   $ r&   )r  r+   s    r    r   OpOverload.namespacel  s    r/   c                     [         R                  nXR                  ;   =(       d.    [        R                  R                  U R                  5       U5      $ r&   )r   r~   r(   r>   r?   r  rS   )r,   dks     r    _can_decomposeOpOverload._can_decomposep  s=    22__$ 
(V(VIIK)
 	
r/   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  rS   rs  r   )r,   r4   r5   r  s       r    	decomposeOpOverload.decomposev  sn    22 
 ??2&777XX;;DIIKLL;;r3D3F33!!r/   keyc                 <    U R                   R                  US 5        g r&   )r'   pop)r,   r  s     r    _uncache_dispatchOpOverload._uncache_dispatch  s      d+r/   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 cacher4   r5   rE   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   rP   rM   r)   rO   TorchBindOpOverloadr>   utils_python_dispatchr   _libraryhandle_dispatch_moders  )r4   r5   r   r   ra   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&   )rX  rT  )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  )r4   r5   r  r   r,   s       r    r   r    s`    ..= /= BCy$~~33HH%t .2 6<  DCCs   /A
A&)r'   rM   r   rQ   rO   r  r)   re  r   r4   r5   r   r>   r?   r   r   r   r   r   rj   torch._dispatch.python	_dispatchpythonCROSSREF_FUNCTIONALIZEmake_crossref_functionalizer(   r5  )	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  %$r/   c                     U R                   $ r&   r	  r+   s    r    rS   OpOverload.name  r  r/   c                     U R                   $ r&   )ru  r+   s    r    rk  OpOverload.overloadpacket  s    ###r/   c                     U R                   $ r&   r  r+   s    r    ru   OpOverload.op  r   r/   c                     U R                   $ r&   )rv  r+   s    r    rn  OpOverload.tags  s    zzr/   )r}  rp   ro   rq   r  r   r{  rr  rs  rx  ru  rt  rv  r  r&   )-ro   rp   rq   rr   r   r   r   r   r   r>   r?   FunctionSchemar   r   r-   r   strr  r  _DispatchOperatorHandler  r  r  r4   r5   r6   DispatchKeySetr  r  r  r  r;   rC   r  r   r  r  r  r  rS   rk  ru   rn  rt   r  r  s   @r    ra  ra    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 $ $    r/   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  rE   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  rS   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r/   )	r   r   AutogradCPUAutogradCUDAADInplaceOrViewBackendSelectPythonTLSSnapshotPythonDispatcherrj   )r,   _DEFAULT_FALLTHROUGH_KEYSr  r  s   `   r    _fallthrough_keys%TorchBindOpOverload._fallthrough_keys  s       ##$$''%%))((%%	%
!		+ 		 1
07< 0
 	
 
s   B,#B,r4   r5   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  rr  r3   s      r    r6   TorchBindOpOverload.__call__(  sG    #D11 ++D,B,B,DVtVvVVxx(((r/   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  rO   r   r  rS   r  rR   r   rM   rP   )	r,   r  r4   r5   r   r  r  r   r   s	            r    r  'TorchBindOpOverload._dispatch_in_python0  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'''r/   r^   N)ro   rp   rq   rr   r   r   r  r   r4   r5   r   r6   r  rt   r^   r/   r    r  r    sh    
4#4 
B) )BII )" )(( $[ 1((:<''((MOYY((	((r/   r  c                 4    [         R                  " S X45      $ )Nc                 ^    [        U [        R                  R                  R                  5      $ r&   )rO   r>   r  fake_class_registryFakeScriptObject)objs    r    r   *_must_dispatch_in_python.<locals>.<lambda>]  s    J33DD
r/   )r   tree_anyr  s     r    r  r  [  s    ??	
 
	 r/   r   rE   c                 :    [        S U R                   5       5      $ )Nc              3   j   #    U  H)  n[        UR                  [        R                  5      v   M+     g 7fr&   )rO   rP   r>   	ClassTyper   s     r    r   )_has_script_object_arg.<locals>.<genexpr>e  s$     Q@Pz#((EOO44@Ps   13)r   r   )r   s    r    _has_script_object_argr  d  s    Q@P@PQQQr/   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	)rl  ij  	torch.ops__file__qualified_op_nameop_nameru   overload_namesrE   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_namero   rr  _overload_names_dirr   _schemasr   _has_torchbind_op_overload)r,   r	  r
  ru   r  s        r    r-   OpOverloadPacket.__init__m  sH     #4-!	*- .
9=9M9M9O.
 +
'r/   c                     U $ r&   r^   r  s     r    r  OpOverloadPacket.__deepcopy__  r  r/   c                 R    SR                   " U R                  R                  S5      6 $ )Nz<OpOverloadPacket(op='{}.{}')>rq  r  r  r|  r+   s    r    r  OpOverloadPacket.__repr__  s)    /66$$**40
 	
r/   c                 ,    [        U R                  5      $ r&   r  r+   s    r    r  OpOverloadPacket.__hash__  r  r/   c                 R    SR                   " U R                  R                  S5      6 $ )Nz{}.{}rq  r  r+   s    r    r  OpOverloadPacket.__str__  s"    ~~t66<<TBCCr/   c                     U R                   $ r&   r  r+   s    r    ru   OpOverloadPacket.op  r   r/   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,   rw  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   rp  zThe underlying op of 'z' has no overload name ')
startswithgetattrrr  AttributeErrorr  r>   r?   _get_operation_overloadr  r!  r  ra  r  setattrr  r   rR   )	r,   r  use_key
op_dk_tagsop_op_dk_rn  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r/   r4   r5   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_pythonrr  r3   s      r    r6   OpOverloadPacket.__call__  sA     **/G/U/U4TKDKFKKxx(((r/   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   &)ro   r  r  rr  r  r  r&   )ro   rp   rq   rr   r  r   r  r}  r   r   r   r   r-   r  r  r  r  r  ru   r  ra  r0  r   r5  r4   r5   r6   r=  rt   r^   r/   r    rl  rl  j  s    )Hhsm)

 
 RV	

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

D   
 
/s /z"b&'9 /b(3- 
) )BII )" )Er/   rl  r4   r5   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_packetr=  r'  &_check_schema_allow_fake_script_objectrt  rR   items)ru   r4   r5   torch_function_calledret
exceptionsfound_oprw  rd  _eerr_msgr  msgs                 r    r9  r9    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$ )_OpNamespacei  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  rS   rE   Nc                 D   > [         TU ]  SU-   5        Xl        / U l        g )Nz
torch.ops.)r   r-   rS   r  )r,   rS   r   s     r    r-   _OpNamespace.__init__2  s!    ,-	!	r/   c                 ,    [        U R                  5      $ r&   r3  r+   s    r    r5  _OpNamespace.__iter__7  r7  r/   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' 'r%  rq  r   z'_OpNamespace' 'z' object has no attribute ')	r(  rS   rp   _get_packetrR   rl  r*  r  r   )	r,   r
  namespace_namer	  module_nameru   r  rI  opoverloadpackets	            r    r0  _OpNamespace.__getattr__:  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  rS   )ro   rp   rq   rr   rs   r  r  r-   r   r5  rl  r0  rt   r  r  s   @r    rM  rM    sK    ( H"S "T "
(3- " 3 " +; "  " r/   rM  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_builtinrp   )qualname	op_moduleru   r  s       r    rU  rU  _  sF    44X>B	~ 			--b;!r/   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 )rU  r  rr  rp   rM   r  )packetru   r  s      r    _refresh_packetrc  i  sK    $V%>%>

@U@UVB	z89R9R8STUUJ+r/   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$ )
_HigherOrderNamespaceiq  r  rE   c                 2   > [         TU ]  S5        / U l        g )Nr   )r   r-   r  r,   r   s    r    r-   _HigherOrderNamespace.__init__t  s    12!	r/   c                 ,    [        U R                  5      $ r&   r3  r+   s    r    r5  _HigherOrderNamespace.__iter__x  r7  r/   rS   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 'r%  )r   r5  r(  r*  r  r   )r,   rS   ru   s      r    r0  !_HigherOrderNamespace.__getattr__{  sV    ""4(: \]a\bbcd  	B			r/   )r  )rE   N)ro   rp   rq   rr   r  r-   r   r  r5  r   r0  rt   r  r  s   @r    re  re  q  s6    H"(3- 	 	(; 	 	r/   re  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-   r2  loaded_librariesre  r   r  rg  s    r    r-   _Ops.__init__  s,    % #13	r/   rS   rE   c                 j    [        U5      n[        XU5        U R                  R                  U5        U$ r&   )rM  r*  r  r   )r,   rS   r   s      r    r0  _Ops.__getattr__  s.     &	I&		r/   c                 ,    [        U R                  5      $ r&   r3  r+   s    r    r5  _Ops.__iter__  r7  r/   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    rx  _Ops.import_module  s    " 	'r/   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OSErrorrp  r   )r,   pathrI  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   rp  )ro   rp   rq   rr   r  r-   r  rM  r0  r   r5  rx  r  rt   r  r  s   @r    rn  rn    s?    H  (3- (&( (r/   rn  ops)F)`r  r  r   rw  rI   r   typescollections.abcr   r   	functoolsr   typingr   r   r   r	   r
   r   typing_extensionsr   r   r>   torch.utils._pytreer  _pytreer   r   torch._Cr   rz   r   torch._functorch.pyfunctorchr   r   r   r   ri   r   r   r   hasattrr   r  r!   r#   r   r   dictr  r}  r  r  r  r  AutocastCPUAutocastCUDAAutocastXPUr   ABCr   r   r   r  r  r(  r`  rM  rT  rX  r   r[  r   rB  r2  rb  re  rg  ri  ra  r  r  r  r  r  rl  r4   r5   r9  
ModuleTyperM  rU  rc  re  rn  r  r^   r/   r    <module>r     s   
     
  . % L L 0  $ $ ! X J : H T3tS! C!12UwsDT7U  & & M" M"b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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 r/   