ó
    EñiBk  ã                   ó|  • % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
rS SKJr  S SK
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QrSS	S
.r1 SkrS r S,S\S\R<                  \   S\R>                  4S jjr 0 r!\"\S4   \#S'    " S S5      r$\ RJ                   " S S5      5       r&S\S\4S jr'S\SS4S jr(S\SS4S jr)S\S\*\\4   4S jr+S\SS4S jr,S \RZ                  S\.4S! jr/S\S"\R>                  SS4S# jr0S$\Rb                  S%\SS4S& jr2S' r3S( r4S-S) jr5S* r6S.S+ jr7g)/é    N)Úinfer_schema)Úget_ctx)ÚBaseTyÚBaseTypeÚFunctionSchemaÚListTypeÚOperatorNameÚ
SchemaKindé   )Úautograd_kernel_indirectionÚconstruct_autograd_kernel)Ú	custom_opÚCustomOpr   ÚCPUÚCUDA)ÚcpuÚcuda>   ÚatÚatenÚprimÚprimsÚtorchÚpytorchc                  ó8   • [         R                  " S[        SS9  g )Nzwtorch._custom_op is deprecated and will be removed in PyTorch 2.6, please use the equivalent torch.library API instead.é   ©Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarning© ó    ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_custom_op/impl.pyÚwarn_deprecatedr$   5   s   € Ü‡M‚Mð	8äØó	r"   ÚqualnameÚmanual_schemaÚreturnc                 ó,   ^ ^• [        5         UU 4S jnU$ )úD
This API is deprecated, please use torch.library.custom_op instead
c           	      óœ  >• [         R                  " U 5      (       d  [        S[        U 5       35      e[	        T
5      u  p[        U5        U R                  U:w  a  [        ST
 SU SU R                   S35      eT	c
  [        U SS9OT	nU U 3n[        R                  " U5      n[        U5        T	b  [        XP5        [        R                  " US5      nUR                  U5        [        XR                   5      n[#        XaXRUS	S
9nU R                  Ul        U R$                  Ul        U R&                  Ul        [        R(                  " XhR*                  S5      " [-        [.        R0                  " U5      5      5        [2        R4                  R7                  U[8        R:                  " [<        [.        R0                  " U5      5      5        U$ )NzDcustom_op(...)(func): Expected `func` to be a Python function, got: zcustom_op(qualname='z-', ...)(func): expected `func` to have name 'z' but got 'zX'. Please either change the name of `func` or the qualname that is passed to `custom_op`r!   )Úmutates_argsÚFRAGMENTT©Ú_private_accessÚAutograd)ÚinspectÚ
isfunctionÚ
ValueErrorÚtypeÚparse_qualnameÚvalidate_namespaceÚ__name__r   r   ÚparseÚvalidate_schemaÚ validate_function_matches_schemaÚlibraryÚLibraryÚdefineÚfind_ophandle_or_throwÚnamer   Ú
__module__Ú__doc__ÚimplÚ_opnamer   ÚweakrefÚproxyr   Ú_CÚ#_dispatch_set_report_error_callbackÚ	functoolsÚpartialÚreport_error_callback)ÚfuncÚnsr>   ÚschemaÚ
schema_strÚfunction_schemaÚlibÚophandleÚresultr&   r%   s            €€r#   ÚinnerÚcustom_op.<locals>.innerF   s�  ø€ Ü×!Ò! $×'Ñ'Üð"Ü"& t£* ð/óð ô
 " (Ó+‰ˆÜ˜2ÔØ�=‰=˜DÓ ÜØ& x jð 1!Ø!%  k°$·-±-°ð A+ð,óð ð Ñ$ô ˜¨BÒ/àð 	ð
 �v˜f˜XÐ&ˆ
Ü(×.Ò.¨zÓ:ˆÜ˜Ô(ØÑ$Ü,¨_ÔCä�oŠo˜b *Ó-ˆØ�
‰
�:ÔÜ)¨"×.BÑ.BÓCˆÜØ�_¨HÀdñ
ˆð Ÿ-™-ˆŒØ ŸO™OˆÔØŸ™ˆŒä�Š�SŸ.™.¨*Ô5Ü'¬¯ª°fÓ(=Ó>ô	
ô 	�‰×4Ñ4Ø”i×'Ò'Ô(=¼w¿}º}ÈVÓ?TÓUô	
ð ˆr"   )r$   )r%   r&   rR   s   `` r#   r   r   >   s   ù€ ô Ôö/ðb €Lr"   r   Úglobal_registryc                   ó@  ^ • \ rS rSrSrSS.U 4S jjrS rSS jrS rS	 r	S
 r
S rS r SS\R                  \\R                   \   4   S\R"                  4S jjrS rS\R"                  4S jrSS\R"                  4S jjrS rS rS rS rSS jrSS jrSrU =r$ )r   éƒ   r)   Fr-   c                ó   >• [         TU ]  5         [        5         U(       d  [        S5      eU SU 3nX0l        X l        Xl        XPl        X@l        Xpl	        S U l
        0 U l        SU l        U [        U R                  '   g )Nz|The CustomOp constructor is private and we do not guarantee BC for it. Please use custom_op(...) to create a CustomOp objectú::F)ÚsuperÚ__init__r$   ÚRuntimeErrorÚ_schemaÚ_cpp_nsÚ_libÚ	_ophandlerB   Ú	_qualnamer6   Ú_implsÚ'_registered_autograd_kernel_indirectionrT   )	ÚselfrO   Úcpp_nsrL   Úoperator_namerP   r.   r>   Ú	__class__s	           €r#   rZ   ÚCustomOp.__init__ˆ   s„   ø€ ô 	‰ÑÔÜÔÞÜðSóð ð �˜˜M˜?Ð+ˆØŒØŒØ%(Œ	Ø5=Œà)Œà"ŒØˆŒð DFˆŒà7<ˆÔ4à*.Œ˜Ÿ™Ò'r"   c                 óÒ   • U R                   (       a  [        S5      eU R                  R                  U R                  [        [        R                  " U 5      5      S5        SU l         g )Nz.autograd kernel indirection already registeredr/   T)rb   ÚAssertionErrorr^   rA   rB   r   rC   rD   ©rc   s    r#   Ú%_register_autograd_kernel_indirectionÚ.CustomOp._register_autograd_kernel_indirection¤   sK   € Ø×7×7Ü Ð!QÓRÐRØ�	‰	�‰Ø�L‰LÔ5´g·m²mÀDÓ6IÓJÈJô	
ð 8<ˆÕ4r"   c                 ó€  • U R                  U5      (       aK  U R                  U   nUc  [        S5      eUR                  n[	        SU SU R
                   SU SU S3	5      e[        R                  " [        R                  " U5      5      nUR                   SUR                   3n[        X%5      U R                  U'   g )Nz&func_and_location is unexpectedly NonezAttempting to register a z impl for operator z that already has a z  impl registered from Python at z. This is not supported.Ú:)Ú	_has_implra   ri   Úlocationr[   r`   r0   ÚgetframeinfoÚsysÚ	_getframeÚfilenameÚlinenoÚFuncAndLocation)rc   ÚkindrJ   r   Úfunc_and_locationrp   Úframes          r#   Ú_register_implÚCustomOp._register_impl¯   s¿   € Ø�>‰>˜$×ÑØ $§¡¨DÑ 1ÐØ Ñ(Ü$Ð%MÓNÐNØ(×1Ñ1ˆHÜØ+¨D¨6Ð1DÀTÇ^Á^ÐDTð U&Ø&* VÐ+KØ�*Ð4ð6óð ô
 ×$Ò$¤S§]¢]°:Ó%>Ó?ˆØ—n‘nÐ% Q u§|¡| nÐ5ˆÜ+¨DÓ;ˆ�‰�DÒr"   c                 ó    • U R                   U   $ ©N©ra   ©rc   rw   s     r#   Ú	_get_implÚCustomOp._get_impl¾   s   € Ø�{‰{˜4Ñ Ð r"   c                 ó   • XR                   ;   $ r}   r~   r   s     r#   ro   ÚCustomOp._has_implÁ   s   € Ø—{‘{Ñ"Ð"r"   c                 óÐ   • U ? [        [        R                  U R                  5      n[        XR                  5      (       a  [        XR                  5        [        U R                  	 g r}   )
r^   Úgetattrr   Úopsr]   ÚhasattrrB   ÚdelattrrT   r`   )rc   Úopnamespaces     r#   Ú_destroyÚCustomOp._destroyÄ   sD   € ð ˆIäœeŸi™i¨¯©Ó6ˆÜ�;§¡×-Ñ-Ü�K§¡Ô.ä˜DŸN™NÑ+r"   c                 ó"   • SU R                    S3$ )Nz<CustomOp(op="z")>)r`   rj   s    r#   Ú__repr__ÚCustomOp.__repr__Ó   s   € Ø §¡Ð/¨sÐ3Ð3r"   c                 óN   • [         R                  " U R                  /UQ70 UD6nU$ r}   )rE   Ú_dispatch_call_boxedr_   )rc   ÚargsÚkwargsrQ   s       r#   Ú__call__ÚCustomOp.__call__Ö   s'   € ô ×(Ò(¨¯©ÐI¸$ÒIÀ&ÑIˆØˆr"   Údevice_typesr'   c                 ót   ^ ^^• [        T[        5      (       a  T/mT H  n[        U5        M     UUU 4S jnU$ )r)   c                 óä   >• [        T5       H_  nTR                  U5        TR                  XTS9  [        U   n[        R
                  " TR                  TR                  U5      " U 5        Ma     U $ )Nr   )ÚsetÚ_check_doesnt_have_library_implrz   ÚSUPPORTED_DEVICE_TYPE_TO_KEYr:   rA   r^   rB   )ÚfÚdevice_typeÚdispatch_keyÚ_stacklevelr•   rc   s      €€€r#   rR   ÚCustomOp.impl.<locals>.innerê   sa   ø€ Ü" <Ö0�Ø×4Ñ4°[ÔAØ×#Ñ# K¸{Ð#ÑKÜ;¸KÑH�Ü—’˜TŸY™Y¨¯©°lÔCÀAÖFñ	  1ð
 ˆHr"   )Ú
isinstanceÚstrÚvalidate_device_type)rc   r•   rž   rœ   rR   s   ```  r#   rA   ÚCustomOp.implÝ   s7   ú€ ô �l¤C×(Ñ(Ø(˜>ˆLÛ'ˆKÜ  Ö-ñ (÷	ð ˆr"   c                 óÈ   • U R                  U5      (       a  g [        U   n[        R                  " U R                  U5      (       a  [        SU SU R                   S35      eg )Nzimpl(..., device_types=z): the operator zs already has an implementation for this device type via a pre-existing torch.library or TORCH_LIBRARY registration.)ro   rš   rE   Ú._dispatch_has_computed_kernel_for_dispatch_keyr`   r[   )rc   rœ   Úkeys      r#   r™   Ú(CustomOp._check_doesnt_have_library_implô   sh   € Ø�>‰>˜+×&Ñ&ØÜ*¨;Ñ7ˆÜ×<Ò<¸T¿^¹^ÈS×QÑQÜØ)¨+¨Ð6FÀtÇ~Á~ÐFVð WLð Móð ð Rr"   c                 ó   ^ • U 4S jnU$ )z2Register an implementation for a factory function.c                 ó�   >• TR                  SU 5        [        R                  " TR                  TR                  S5      " U 5        U $ )NÚfactoryÚBackendSelect)rz   r:   rA   r^   rB   )r›   rc   s    €r#   rR   Ú$CustomOp.impl_factory.<locals>.inner  s5   ø€ Ø×Ñ 	¨1Ô-Ü�LŠL˜Ÿ™ D§L¡L°/ÔBÀ1ÔEØˆHr"   r!   )rc   rR   s   ` r#   Úimpl_factoryÚCustomOp.impl_factoryÿ   s   ø€ õ	ð
 ˆr"   c                 ó   ^ ^• UU 4S jnU$ )r)   c                 ó.  >^ ^^• TR                  5         TR                  ST TS9  TR                  S5      R                  mTR                  m[
        R                  " T 5      U UU4S j5       nTR                  R                  TR                  US5        T $ )NÚabstractr   c                  óª   >• UU4S jn[         R                  R                  R                  U5         T" U 0 UD6sS S S 5        $ ! , (       d  f       g = f)Nc                  ó&   >• [        ST ST  35      e)Nz<Attempted to call get_ctx() for the meta implementation for a  .You have presumably called get_ctx() because the operator has a data-dependent output shape; if so, there is no such meta implementation and this error is the correct behavior. Otherwise, please remove the call to get_ctx() in the implementation registered with impl_abstract at ©r[   )rp   r%   s   €€r#   Úerror_on_ctxÚOCustomOp.impl_abstract.<locals>.inner.<locals>.f_with_ctx.<locals>.error_on_ctx  s+   ø€ Ü&ðØ'˜jð )ð '˜Zð)ó	ð 	r"   )r   Ú_libraryÚ	fake_implÚset_ctx_getter)r‘   r’   rµ   r›   rp   r%   s      €€€r#   Ú
f_with_ctxÚ9CustomOp.impl_abstract.<locals>.inner.<locals>.f_with_ctx  s<   ø€ ö
ô —^‘^×-Ñ-×<Ñ<¸\ÕJÙ˜dÐ- fÑ-÷ K×J×Jús   ²AÁ
AÚMeta)
Ú$_check_doesnt_have_library_meta_implrz   r€   rp   r`   rG   Úwrapsr^   rA   rB   )r›   rº   rp   r%   rž   rc   s   ` @@€€r#   rR   Ú%CustomOp.impl_abstract.<locals>.inner  s}   û€ Ø×5Ñ5Ô7Ø×Ñ 
¨A¸+ÐÑFØ—~‘~ jÓ1×:Ñ:ˆHà—~‘~ˆHô �_Š_˜QÓö.ó  ð.ð  �I‰I�N‰N˜4Ÿ<™<¨°VÔ<ØˆHr"   r!   ©rc   rž   rR   s   `` r#   Úimpl_abstractÚCustomOp.impl_abstract	  s   ù€ ö
	ð8 ˆr"   c                 óH  ^ ^• UU 4S jnT R                   mTR                  5       [        R                  :w  a  U" S5        TR                  nTR                  (       d  U" S5        [        U5      S::  a  [        S[        U5       35      e[        S U 5       5      nU(       a  U" S5        [        [        R                  5      S[        [        R                  5      S	[        [        R                  5      S
[        [        R                  5      S[        [        R                  5      S[        [        [        R                  5      S 5      S0nTR                   HE  nUR                   U;   a  M  U" S[#        UR%                  5       5       SUR                    S35        MG     g )Nc                 ó@   >• [        SU  STR                   ST 35      e)NzCCannot use torch._custom_ops APIs to register backward formula for z. Got operator z with schema: )r[   r`   )ÚdetailrL   rc   s    €€r#   ÚerrorÚ4CustomOp._check_can_register_backward.<locals>.error-  s1   ø€ ÜðØ%˜h oØ—>‘>Ð" .°°ð:óð r"   znon-functional operatorzoperator with no returnsr   z"expected at least one return, got c              3   ó€   #   • U  H4  oR                   S L=(       a    UR                   R                  (       + v •  M6     g 7fr}   )Ú
annotationÚis_write)Ú.0Úrs     r#   Ú	<genexpr>Ú8CustomOp._check_can_register_backward.<locals>.<genexpr>>  s/   é € ð #
ÚLPÀq�L‰L Ð$×B¨Q¯\©\×-BÑ-BÔ)BÔBÊDùs   ‚<>zoperator that returns viewsÚintÚSymIntÚboolÚfloatÚTensorzList[Tensor]zoperator with return not in z (got Ú))r\   rw   r
   Ú
functionalÚreturnsÚlenri   Úanyr   r   rÏ   rÐ   rÑ   rÒ   rÓ   r   r3   ÚlistÚvalues)rc   rÆ   ÚretsÚis_non_mutating_viewÚallowed_return_typesÚretrL   s   `     @r#   Ú_check_can_register_backwardÚ%CustomOp._check_can_register_backward,  sJ  ù€ ö	ð —‘ˆØ�;‰;‹=œJ×1Ñ1Ó1ÙÐ+Ô,à�~‰~ˆØ�~�~ÙÐ,Ô-äˆt‹9˜‹>Ü Ð#EÄcÈ$ÃiÀ[Ð!QÓRÐRÜ"ñ #
ÙLPó#
ó  
Ðö  ÙÐ/Ô0ô ”V—Z‘ZÓ  %Ü”V—]‘]Ó# XÜ”V—[‘[Ó! 6Ü”V—\‘\Ó" GÜ”V—]‘]Ó# XÜ”XœfŸm™mÓ,¨dÓ3°^ð 
Ðð —>”>ˆCØ�x‰xÐ/Ó/ÙÙØ.¬tÐ4H×4OÑ4OÓ4QÓ/RÐ.SÐSYÐZ]×ZbÑZbÐYcÐcdÐeöò "r"   c                 ó<  • U R                   (       a  g [        R                  " U R                  S5      (       a  [	        SU R                   S35      eS HE  n[        R                  " U R                  U5      (       d  M+  [	        SU R                   SU S35      e   g )NÚCompositeImplicitAutogradz3impl_backward/impl_save_for_backward: the operator a3   already has an implementation for this device type via a pre-existing registration to DispatchKey::CompositeImplicitAutograd.CompositeImplicitAutograd operators do not need an autograd formula; instead, the operator will decompose into its constituents and those can have autograd formulas defined on them.)r/   ÚAutogradCPUÚAutogradCUDAz; already has an Autograd kernel registered to DispatchKey::z� vi a pre-existing torch.library or TORCH_LIBRARY registration. Please either remove those registrations or don't use the torch._custom_ops APIs)rb   rE   Ú%_dispatch_has_kernel_for_dispatch_keyr`   r[   )rc   r¦   s     r#   Ú(_check_doesnt_have_library_autograd_implÚ1CustomOp._check_doesnt_have_library_autograd_implT  s¦   € Ø×7×7Øä×3Ò3Ø�N‰NÐ7÷
ñ 
ô ØEÀdÇnÁnÐEUð V>ð ?óð ó ?ˆCÜ×7Ò7¸¿¹È×LÓLÜ"ð$Ø$(§N¡NÐ#3ð 42Ø25°ð 7YðZóð ò ?r"   c                 óÈ  • U R                  S5      (       a  g [        R                  " U R                  S5      (       a'  [        R                  " U R                  S5      (       d  g [        R                  " U R                  S5      (       a  [	        SU R                   S35      e[        R                  " U R                  S5      (       a  [	        SU R                   S35      eg )Nr±   ÚCompositeExplicitAutogradr¼   râ   z!impl_abstract(...): the operator a-   already has an implementation for this device type via a pre-existing registration to DispatchKey::CompositeImplicitAutograd.CompositeImplicitAutograd operators do not need an abstract impl; instead, the operator will decompose into its constituents and those can have abstract impls defined on them.z´ already has an DispatchKey::Meta implementation via a pre-existing torch.library or TORCH_LIBRARY registration. Please either remove that registration or don't call impl_abstract.)ro   rE   rå   r`   r[   rj   s    r#   r½   Ú-CustomOp._check_doesnt_have_library_meta_implp  s×   € Ø�>‰>˜*×%Ñ%Øô ×3Ò3Ø�N‰NÐ7÷
ñ 
ä×:Ò:¸4¿>¹>È6×RÑRØô ×3Ò3Ø�N‰NÐ7÷
ñ 
ô Ø3°D·N±NÐ3Cð D;ð <óð ô ×3Ò3°D·N±NÀF×KÑKÜØ3°D·N±NÐ3Cð DVð Wóð ð Lr"   c           
      ó~  • U R                  S5      (       d  [        S5      eU R                  S5      (       d  [        S5      e[        U R                  U R                  U [        U R                  5      U R                  S5      R                  U R                  S5      R                  5      nU R                  SU5        g )NÚbackwardz&backward impl must be registered firstÚsave_for_backwardz/save_for_backward impl must be registered firstÚautograd)
ro   ri   r   r\   Ú_output_differentiabilityÚget_opr`   r€   rJ   rz   )rc   Úkernels     r#   Ú_register_autograd_kernelÚ"CustomOp._register_autograd_kernelœ  s™   € Ø�~‰~˜j×)Ñ)Ü Ð!IÓJÐJØ�~‰~Ð1×2Ñ2Ü Ð!RÓSÐSÜ*Ø�L‰LØ×*Ñ*ØÜ�4—>‘>Ó"Ø�N‰NÐ.Ó/×4Ñ4Ø�N‰N˜:Ó&×+Ñ+ó
ˆð 	×Ñ˜J¨Õ/r"   c                 ó   ^ ^• UU 4S jnU$ )ziRegister a function that tells us what to save for backward.

Please see impl_backward for more details.
c                 óø   >• TR                  5         TR                  5         TR                  (       d  TR                  5         TR	                  SU TS9  TR                  S5      (       a  TR                  5         g g )Nrí   r   rì   )rß   ræ   rb   rk   rz   ro   rò   )r›   rž   rc   s    €€r#   rR   Ú.CustomOp.impl_save_for_backward.<locals>.inner±  sf   ø€ Ø×-Ñ-Ô/Ø×9Ñ9Ô;Ø×?×?Ø×:Ñ:Ô<Ø×ÑÐ 3°QÀ;ÐÑOØ�~‰~˜j×)Ñ)Ø×.Ñ.Õ0ð *r"   r!   rÀ   s   `` r#   Úimpl_save_for_backwardÚCustomOp.impl_save_for_backward«  s   ù€ ö	1ð ˆr"   c                 ó  ^ ^^• Tb|  U4S jn[        T[        5      (       d  U" 5         T H!  n[        U[        5      (       a  M  U" 5         M#     [        T R                  R
                  5      [        T5      :w  a  U" 5         UUU 4S jnU$ )r)   c                  ó    >• [        ST  35      e)Nz¢impl_backward(output_differentiability): expected output_differentiability to be a list of bools with length equal to the number of outputs of this CustomOp got: r´   )Úoutput_differentiabilitys   €r#   ÚyellÚ$CustomOp.impl_backward.<locals>.yellÂ  s"   ø€ Ü"ðð 5Ð5ð7óð r"   c                 ó  >• TR                  5         TR                  5         TR                  (       d  TR                  5         TR	                  SU TS9  TTl        TR                  S5      (       a  TR                  5         g g )Nrì   r   rí   )rß   ræ   rb   rk   rz   rï   ro   rò   )r›   rž   rû   rc   s    €€€r#   rR   Ú%CustomOp.impl_backward.<locals>.innerÒ  sn   ø€ Ø×-Ñ-Ô/Ø×9Ñ9Ô;Ø×?×?Ø×:Ñ:Ô<Ø×Ñ 
¨A¸+ÐÑFØ-EˆDÔ*Ø�~‰~Ð1×2Ñ2Ø×.Ñ.Õ0ð 3r"   )r    rÙ   rÑ   r×   r\   rÖ   )rc   rû   rž   rü   ÚdiffrR   s   ```   r#   Úimpl_backwardÚCustomOp.impl_backward¼  sq   ú€ ð $Ñ/õô Ð6¼×=Ñ=Ù”Û0�Ü! $¬×-Ó-Ù–Fñ 1ô �4—<‘<×'Ñ'Ó(¬CÐ0HÓ,IÓIÙ”÷	1ð ˆr"   )
r6   r]   ra   r^   r_   rB   rï   r`   rb   r\   )r   )Nr   )r6   r?   Ú__qualname__Ú__firstlineno__r@   rZ   rk   rz   r€   ro   rŠ   r�   r“   ÚtypingÚUnionr¡   ÚIterableÚCallablerA   r™   r­   rÁ   rß   ræ   r½   rò   r÷   r  Ú__static_attributes__Ú__classcell__)rf   s   @r#   r   r   ƒ   s¾   ø† ñð
 PU÷/ð /ò8<ô<ò!ò#ò,ò4òð ñà—l‘l 3¨¯©¸Ñ(<Ð#<Ñ=ðð 
�‰õ	ò.	ð˜fŸo™oô ñ!¨f¯o©oõ !òF&òPò8%òX0ô÷" ò  r"   c                   ó>   • \ rS rSr% \R
                  \S'   \\S'   Srg)rv   iß  rJ   rp   r!   N)	r6   r?   r  r  r  r  Ú__annotations__r¡   r	  r!   r"   r#   rv   rv   ß  s   ‡ à
�/‰/ÓØ†Mr"   rv   rd   re   c                 ó–   • UR                   c  SOUR                   n[        R                  " U  S[        UR                  5       3U5      $ )NÚ rX   )Úoverload_namerE   Ú_dispatch_find_schema_or_throwr¡   r>   )rd   re   r  s      r#   r=   r=   å  sN   € à×)Ñ)Ñ1‰°}×7RÑ7Rð ô ×,Ò,Øˆ(�"”S˜×+Ñ+Ó,Ð-Ð.°óð r"   rK   c                 óf   • SU ;   a  [        SU  S35      eU [        ;   a  [        SU  SU  S35      eg )NÚ.zcustom_op(..., ns="zC"): expected ns to not contain any . (and be a valid variable name)zcustom_op(..., ns='z'): 'z9' is a reserved namespace, please choose something else. )r2   ÚRESERVED_NS)rK   s    r#   r5   r5   î  sZ   € Ø
ˆbƒyÜØ! " ð &#ð $ó
ð 	
ð 
Œ[ÓÜØ! "  U¨2¨$ð /-ð .ó
ð 	
ð r"   rL   c                 óÆ   • [         R                  R                  R                  U 5      (       d  [	        SU  35      eU R
                  R                  b  [	        SU  35      eg )Nz»custom_op only supports functional operators (ops that do not mutate any inputs, do not return views of the inputs, and has at least one return). Got the following non-functional schema: zUcustom_op does not support arguments named 'self'. Please rename your argument. Got: )r   r·   ÚutilsÚis_functional_schemar2   Ú	argumentsÚself_arg)rL   s    r#   r8   r8   û  sq   € Ü�>‰>×Ñ×4Ñ4°V×<Ñ<Üð8ð 9?°xðAó
ð 	
ð ×Ñ× Ñ Ñ,Üð*Ø*0¨ð3ó
ð 	
ð -r"   c                 ó¤   • U R                  SS5      n[        U5      S:w  a  [        SU  S35      eSUS   ;   a  [        SU  35      eUS   US   4$ )	NrX   r   r   z$Expected there to be a namespace in z;, i.e. The operator name should look something like ns::foor  z�The torch.custom_ops APIs do not handle overloads, i.e. operator names with '.' in them. Please name your operator something like ns::foo. Got: r   )Úsplitr×   r2   )r%   Únamess     r#   r4   r4     s|   € Ø�N‰N˜4 Ó#€EÜ
ˆ5ƒz�QƒÜØ2°8°*ð =?ð @ó
ð 	
ð ˆe�A‰hƒÜðð �:ðó
ð 	
ð �‰8�U˜1‘XÐÐr"   rœ   c                 ó`   • U [         ;  a$  [        SU  S[         R                  5        S35      eg )NzCustomOp.impl(device_types=[z(, ...]): we only support device_type in r  )rš   r2   Úkeys)rœ   s    r#   r¢   r¢     s?   € ØÔ6Ó6ÜØ*¨;¨-ð 8Ü.×3Ñ3Ó5Ð6°að9ó
ð 	
ð 7r"   Úparamc                 ó„   • U R                   [        R                  R                  [        R                  R                  4;   $ r}   )rw   r0   Ú	ParameterÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLY)r  s    r#   Úsupported_paramr#  %  s6   € Ø�:‰:Ü×Ñ×/Ñ/Ü×Ñ×&Ñ&ðñ ð r"   rJ   c                 ó”  ^ ^^^	• [         R                  " U5      m	[        S T	R                  R	                  5        5       5      (       d  [        ST	 35      e[        S T	R                  R	                  5        5       5      (       d'  T	R                  [         R                  R                  La  [        ST	 35      eT	R                  R	                  5        VVs/ s H2  u  p#UR                  [         R                  R                  :X  d  M/  X#4PM4     nnnT	R                  R	                  5        VVs/ s H2  u  p#UR                  [         R                  R                  :X  d  M/  X#4PM4     nnnU U	4S jmU U	4S jmUU4S jnU" UT R                  R                  5        U" UT R                  R                   5        g s  snnf s  snnf )Nc              3   ó<   #   • U  H  u  p[        U5      v •  M     g 7fr}   )r#  ©rË   Ú_Úps      r#   rÍ   Ú3validate_function_matches_schema.<locals>.<genexpr>1  s   é € ÐEÒ.D¡d aŒ˜q×!Ð!Ò.Dùs   ‚z¥custom_op(..., manual_schema)(func): positional-only args, varargs, and kwargs are not supported. Please rewrite `func` to not have them. Got `func` with signature: c              3   ór   #   • U  H-  u  pUR                   [        R                  R                  Lv •  M/     g 7fr}   )rÉ   r0   r   Úemptyr&  s      r#   rÍ   r)  9  s.   é € ð 
â.‘�ð �L‰L¤× 1Ñ 1× 7Ñ 7Õ7Ú.ùs   ‚57z¢custom_op(..., manual_schema)(func): When passing in a manual schema, we expect `func` to have no type annotations to avoid ambiguity. Got `func` with signature: c                  ó&   >• [        ST ST  35      e)Nz­custom_op(..., manual_schema)(func): When passing in a manual schema, we expect `func`'s signature to match `manual_schema` (aside from type annotations). func's signature: ú, manual_schema: ©r2   ©rL   Úsigs   €€r#   rÆ   Ú/validate_function_matches_schema.<locals>.errorP  ó)   ø€ Üð!ð "% Ð%6°v°hð@ó
ð 	
r"   c                  ó&   >• [        ST ST  35      e)Nzycustom_op(..., manual_schema)(func): neither func nor manual_schema should have default arguments. Got func's signature: r-  r.  r/  s   €€r#   Úerror_default_argsÚ<validate_function_matches_schema.<locals>.error_default_argsX  r2  r"   c                 ó  >• [        U 5      [        U5      :w  a  T" 5         [        X5       H[  u  u  p#nX$R                  :w  a  T" 5         UR                  [        R
                  R                  Ld  UR                  c  MT  T" 5         M]     g r}   )r×   Úzipr>   Údefaultr0   r   r+  )Úsig_argsÚschema_argsr>   r  ÚargrÆ   r4  s        €€r#   ÚcompareÚ1validate_function_matches_schema.<locals>.compare`  se   ø€ Üˆx‹=œC Ó,Ó,ÙŒGÜ"% hÖ"<Ñ‰MˆT˜3Ø—x‘xÓÙ”Ø�}‰}¤G×$5Ñ$5×$;Ñ$;Ò;¸s¿{¹{Ó?VÙ"Ö$ò	 #=r"   )r0   Ú	signatureÚallÚ
parametersÚitemsr2   rØ   Úreturn_annotationÚ	Signaturer+  rw   r   r!  r"  r  Úflat_positionalÚflat_kwarg_only)
rL   rJ   r>   r  Ú
positionalÚ	kwargonlyr<  rÆ   r4  r0  s
   `      @@@r#   r9   r9   ,  s“  û€ ô ×
Ò
˜DÓ
!€CäÑE¨c¯n©n×.BÑ.BÔ.DÓE×EÑEÜð<à<?¸5ðBó
ð 	
ô 	ñ 
àŸ™×,Ñ,Ô.ó
÷ 	
ñ 	
ð × Ñ ¬×(9Ñ(9×(?Ñ(?Ò?äð5à58°Eð;ó
ð 	
ð Ÿ>™>×/Ñ/Ô1ôâ1‰KˆDØ�:‰:œ×*Ñ*×@Ñ@Ñ@ó 	ˆ‹Ù1ð ñ ð Ÿ>™>×/Ñ/Ô1ôâ1‰KˆDØ�:‰:œ×*Ñ*×7Ñ7Ñ7ó 	ˆ‹Ù1ð ñ ö
ö
ö%ñ ˆJ˜×(Ñ(×8Ñ8Ô9ÙˆI�v×'Ñ'×7Ñ7Õ8ùóKùó
s   Ã.F>ÄF>Ä2.GÅ$Gr   r¦   c           
      óÎ   • US:X  a  [        U  S35      eUS:X  a  [        U  S35      eUS;   a'  UR                  5       n[        U  SU SU SU S	35      e[        U  S
U S35      e)NÚ	Undefineda  : There were no Tensor inputs to this operator (e.g. you passed an empty list of Tensors). If your operator is a factory function (that is, it takes no Tensors and constructs a new one), then please use CustomOp.impl_factory to register an implementation for itr¼   zÀ: when running with device='Meta' tensors: there is no abstract impl registered for this CustomOp. Please register one via CustomOp.impl_abstract to get this CustomOp to work with Meta tensors)r   r   z: when running with device='z' tensors: there is no zW impl registered for this CustomOp. Please register one via CustomOp.impl(device_type='z')z%: No implementation for dispatch key zŸ. It is likely that we have not added this functionality yet, please either open an issue or if you're feeling adventurous, use the low-level torch.library API)ÚNotImplementedErrorÚlower)r   r¦   Údevices      r#   rI   rI   m  sº   € Ø
ˆkÓÜ!Øˆkð 'ð (ó
ð 	
ð ˆfƒ}Ü!Øˆkð Tð Uó
ð 	
ð
 ˆoÓØ—‘“ˆÜ!ØˆkÐ5°f°XÐ=TØˆhð *Ø*0¨°ð5ó
ð 	
ô
 Øˆ+Ð:¸3¸%ð @ð 	óð r"   c           	      ó2  • U R                   n[        R                  R                  US5      nU R	                  5       R                  S5      S   n[        U R                  5      nUR                  SSS9S   n[        R                  " U5      n[        X!XSU SS9$ )Nr,   rX   éÿÿÿÿr   )ÚmaxsplitTr-   )Ú	namespacer   r:   r;   r>   r  r¡   r\   Úrsplitr   r7   r   )ÚoprK   rO   r>   rM   rL   s         r#   Úcustom_op_from_existingrS  ‹  s‚   € Ø	�‰€BÜ
�-‰-×
Ñ
  JÓ
/€CØ�7‰7‹9�?‰?˜4Ó  Ñ$€DÜ�R—Z‘Z“€Jà×"Ñ" 4°!Ð"Ð4°RÑ8€JÜ×!Ò! *Ó-€FÜ�C˜V¨2¸tÑDÐDr"   c                 ó6  ^ • U 4S jn[        T 5      u  p#[        [        R                  U5      (       d  U" 5         [	        [        R                  U5      n[        XC5      (       d  U" 5         [	        XC5      n[        US5      (       d  U" 5         UR
                  $ )Nc                  ó"   >• [        ST  S35      e)NzCould not find the operator z~. Please make sure you have already registered the operator and (if registered from C++) loaded it via torch.ops.load_library.r.  )r%   s   €r#   Úerror_not_foundÚget_op.<locals>.error_not_found—  s!   ø€ ÜØ*¨8¨*ð 54ð 5ó
ð 	
r"   r8  )r4   r‡   r   r†   r…   r8  )r%   rV  rK   r>   r‰   Úpackets   `     r#   rð   rð   –  su   ø€ õ
ô ˜hÓ'�H€BÜ”5—9‘9˜b×!Ñ!ÙÔÜœ%Ÿ)™) RÓ(€KÜ�;×%Ñ%ÙÔÜ�[Ó'€FÜ�6˜9×%Ñ%ÙÔØ�>‰>Ðr"   c                 ó„   • U [         ;   a	  [         U    $ U(       d  [        SU  S35      e[        U 5      n[        U5      nU$ )NzCould not find custom op "z5". Did you register it via the torch._custom_ops API?)rT   r[   rð   rS  )r%   Úalso_check_torch_libraryÚoverloadrQ   s       r#   Ú_find_custom_opr\  ª  sQ   € Ø”?Ó"Ü˜xÑ(Ð(Þ#ÜØ(¨¨
ð 3)ð *ó
ð 	
ô �hÓ€HÜ$ XÓ.€FØ€Mr"   c                 ó  • U [         R                  R                  R                  ;  a  g [         R                  R                  R                  U    nUc  g UR	                  S5      (       d  g UR                  S5      R                  $ )Nr±   )r   Ú
_custom_oprA   rT   ro   r€   rJ   )r%   r   s     r#   Úget_abstract_implr_  ·  so   € Ø”u×'Ñ'×,Ñ,×<Ñ<Ó<ØÜ× Ñ ×%Ñ%×5Ñ5°hÑ?€IØÑØØ×Ñ˜z×*Ñ*ØØ×Ñ˜zÓ*×/Ñ/Ð/r"   c           	      ó0  • U R                  S5      u  p4U U 3n[        R                  " U5      n[        U5        U(       a%  [        R
                  R                  R                  /O/ n[        R                  " US5      nUR                  XWS9  [        X6R                  5      n	[        XƒXdU	SS9n
U
R                  5         [        R
                  R                  U	[         R"                  " [$        [&        R(                  " U
5      5      5        [+        U 5      $ )NrX   r,   )ÚtagsTr-   )r  r   r7   r8   r   rE   ÚTagÚneeds_fixed_stride_orderr:   r;   r<   r=   r>   r   rk   rF   rG   rH   rI   rC   rD   rð   )r%   rL   rc  rK   r>   rM   rN   ra  rO   rP   rQ   s              r#   Ú_custom_op_with_schemard  Â  sÙ   € Ø�~‰~˜dÓ#�H€BØ�6˜&˜Ð"€JÜ$×*Ò*¨:Ó6€OÜ�OÔ$Þ6NŒE�H‰H�L‰L×1Ñ1Ñ2ÐTV€DÜ
�/Š/˜"˜jÓ
)€CØ‡J�Jˆz€JÑ%Ü% b×*>Ñ*>Ó?€HÜ�c˜°hÐPTÑU€FØ
×0Ñ0Ô2ä	‡H�H×0Ñ0Ø”)×#Ò#Ô$9¼7¿=º=ÈÓ;PÓQôô �(ÓÐr"   r}   )F)T)8ÚdataclassesrG   r0   rr   r  r   rC   r   Útorch._CrE   Útorch._library.infer_schemaÚtorch.libraryr:   r   r   Útorchgen.modelr   r   r   r   r	   r
   rî   r   r   Ú__all__rš   r  r$   r¡   ÚOptionalr  r   rT   Údictr  r   Ú	dataclassrv   r=   r5   r8   Útupler4   r¢   r   rÑ   r#  r9   ÚAnyrI   rS  rð   r\  r_  rd  r!   r"   r#   Ú<module>rp     s¯  ðä Û Û Û 
Û Û Û ã Ý Û "Ý Ý 4Ý !÷÷ ÷ Mðò
 /€ð Øñ Ð ò€òð :>ñ9Øð9Ø"(§/¡/°#Ñ"6ð9à‡_�_õ9ðD *,€��c˜:�oÑ&Ó +÷Yñ Yðx
 ×Ñ÷ð ó ðð
 3ð °|ô ð

˜3ð 

 4ô 

ð
˜Nð 
¨tô 
ð"˜Sð  U¨3°¨8¡_ô ð"
 cð 
¨dô 
ð˜7×,Ñ,ð °ô ð>9Øð>9Ø"(§/¡/ð>9à	ô>9ðB V§Z¡Zð °cð ¸dô ò<Eòô(
ò0õr"   