Ë
    L²jk  ã                   óN  — U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
Zd dlmZ d dl
mZ d dlmZ d dlmZmZmZmZmZmZ ddlmZmZ 	 g d¢Zdd	d
œZh d£Zd„ Zd,dededz  dej<                  fd„Zi Z e!edf   e"d<    G d„ d«      Z#e jH                   G d„ d«      «       Z%dedefd„Z&deddfd„Z'deddfd„Z(dede)eef   fd„Z*deddfd„Z+d ejX                  de-fd!„Z.ded"ej<                  ddfd#„Z/d$ej`                  d%eddfd&„Z1d'„ Z2d(„ Z3d-d)„Z4d*„ Z5d.d+„Z6y)/é    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                  ó<   — t        j                  dt        d¬«       y )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© ó    úT/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torch/_custom_op/impl.pyÚwarn_deprecatedr$   5   s   € Ü‡M�Mð	8äØö	r"   ÚqualnameÚmanual_schemaÚreturnc                 ó*   ‡ ‡— t        «        ˆˆ fd„}|S )úL
    This API is deprecated, please use torch.library.custom_op instead
    c           	      ó–  •— t        j                  | «      st        dt        | «      › �«      ‚t	        ‰
«      \  }}t        |«       | j                  |k7  rt        d‰
› d|› d| j                  › d�«      ‚‰	€t        | d¬«      n‰	}|› |› �}t        j                  |«      }t        |«       ‰	�t        || «       t        j                  |d«      }|j                  |«       t        ||j                   «      }t#        |||||d	¬
«      }| j                  |_        | j$                  |_        | j&                  |_         t        j(                  ||j*                  d«      t-        t/        j0                  |«      «      «       t2        j4                  j7                  |t9        j:                  t<        t/        j0                  |«      «      «       |S )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#   Úinnerzcustom_op.<locals>.innerD   s¨  ø€ Ü×!Ñ! $Ô'Üð"Ü"& t£* ð/óð ô
 " (Ó+‰ˆˆDÜ˜2ÔØ�=‰=˜DÒ ÜØ& x jð 1!Ø!%  k°$·-±-°ð A+ð,óð ð Ð$ô ˜¨BÕ/àð 	ð
 �v˜f˜XÐ&ˆ
Ü(×.Ñ.¨zÓ:ˆÜ˜Ô(ØÐ$Ü,¨_¸dÔCä�o‰o˜b *Ó-ˆØ�
‰
�:ÔÜ)¨"¨o×.BÑ.BÓCˆÜØ��_ d¨HÀdô
ˆð Ÿ-™-ˆŒØ ŸO™OˆÔØŸ™ˆŒà5Œ�‰�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                   ó  ‡ — e Zd ZdZddœˆ fd„
Zd„ Zdd„Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Z	 ddeej                  e   z  dej                  fd„Zd„ Zdej                  fd„Zddej                  fd„Zd„ Zd„ Zd„ Zd„ Zdd„Zdd„Zˆ xZS )r   r)   Fr-   c                ó  •— t         ‰| �  «        t        «        |st        d«      ‚|› d|› �}|| _        || _        || _        || _        || _        || _	        d | _
        i | _        d| _        | t        | j                  <   y )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_indirectionrS   )	ÚselfrO   Úcpp_nsrL   Úoperator_namerP   r.   r>   Ú	__class__s	           €r#   rX   zCustomOp.__init__†   sŽ   ø€ ô 	‰ÑÔÜÔÙÜðSóð ð �˜˜M˜?Ð+ˆØˆŒØˆŒØ%(ˆŒ	Ø5=ˆŒà)ˆŒà"ˆŒØˆŒð :<ˆŒà7<ˆÔ4à*.Œ˜Ÿ™Ò'r"   c                 óÆ   — | j                   rt        d«      ‚| j                  j                  | j                  t        t        j                  | «      «      d«       d| _         y )Nz.autograd kernel indirection already registeredr/   T)r`   ÚAssertionErrorr\   rA   rB   r   rC   rD   ©ra   s    r#   Ú%_register_autograd_kernel_indirectionz.CustomOp._register_autograd_kernel_indirection¢   sK   € Ø×7Ò7Ü Ð!QÓRÐRØ�	‰	�‰Ø�L‰LÔ5´g·m±mÀDÓ6IÓJÈJô	
ð 8<ˆÕ4r"   c                 ór  — | j                  |«      rJ| j                  |   }|€t        d«      ‚|j                  }t	        d|› d| j
                  › d|› d|› d�	«      ‚t        j                  t        j                  |«      «      }|j                  › d|j                  › �}t        ||«      | j                  |<   y )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_implr_   rf   ÚlocationrY   r^   r0   ÚgetframeinfoÚsysÚ	_getframeÚfilenameÚlinenoÚFuncAndLocation)ra   ÚkindrJ   r   Úfunc_and_locationrl   Úframes          r#   Ú_register_implz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                 ó    — | j                   |   S ©N©r_   ©ra   rs   s     r#   Ú	_get_implzCustomOp._get_impl¼   s   € Ø�{‰{˜4Ñ Ð r"   c                 ó   — || j                   v S rx   ry   rz   s     r#   rk   zCustomOp._has_impl¿   s   € Ø�t—{‘{Ð"Ð"r"   c                 óÊ   — | ` t        t        j                  | j                  «      }t        || j                  «      rt        || j                  «       t        | j                  = y rx   )
r\   Úgetattrr   Úopsr[   ÚhasattrrB   ÚdelattrrS   r^   )ra   Úopnamespaces     r#   Ú_destroyzCustomOp._destroyÂ   sE   € ð ˆIäœeŸi™i¨¯©Ó6ˆÜ�; §¡Ô-Ü�K §¡Ô.ä˜DŸN™NÑ+r"   c                 ó"   — d| j                   › d�S )Nz<CustomOp(op="z")>)r^   rg   s    r#   Ú__repr__zCustomOp.__repr__Ñ   s   € Ø §¡Ð/¨sÐ3Ð3r"   c                 óL   — t        j                  | j                  g|¢­i |¤Ž}|S rx   )rE   Ú_dispatch_call_boxedr]   )ra   ÚargsÚkwargsrQ   s       r#   Ú__call__zCustomOp.__call__Ô   s'   € ô ×(Ñ(¨¯©ÐI¸$ÒIÀ&ÑIˆØˆr"   Údevice_typesr'   c                 ód   ‡ ‡‡— t        ‰t        «      r‰gŠ‰D ]  }t        |«       Œ ˆˆˆ fd„}|S )úT
        This API is deprecated, please use torch.library.custom_op instead
        c                 óæ   •— t        ‰«      D ]a  }‰j                  |«       ‰j                  || ‰¬«       t        |   } t	        j
                  ‰j                  ‰j                  |«      | «       Œc | S )Nr   )ÚsetÚ_check_doesnt_have_library_implrv   ÚSUPPORTED_DEVICE_TYPE_TO_KEYr:   rA   r\   rB   )ÚfÚdevice_typeÚdispatch_keyÚ_stacklevelr‹   ra   s      €€€r#   rR   zCustomOp.impl.<locals>.innerè   sl   ø€ Ü" <Ó0ò G�Ø×4Ñ4°[ÔAØ×#Ñ# K°¸{Ð#ÔKÜ;¸KÑH�ØC”—‘˜TŸY™Y¨¯©°lÓCÀAÕFð	Gð
 ˆHr"   )Ú
isinstanceÚstrÚvalidate_device_type)ra   r‹   r•   r“   rR   s   ```  r#   rA   zCustomOp.implÛ   s9   ú€ ô �l¤CÔ(Ø(˜>ˆLØ'ò 	.ˆKÜ  Õ-ð	.ö	ð ˆr"   c                 ó²   — | j                  |«      ry t        |   }t        j                  | j                  |«      rt        d|› d| j                  › d�«      ‚y )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.)rk   r‘   rE   Ú._dispatch_has_computed_kernel_for_dispatch_keyr^   rY   )ra   r“   Úkeys      r#   r�   z(CustomOp._check_doesnt_have_library_implò   sb   € Ø�>‰>˜+Ô&ØÜ*¨;Ñ7ˆÜ×<Ñ<¸T¿^¹^ÈSÔQÜØ)¨+¨Ð6FÀtÇ~Á~ÐFVð WLð Móð ð Rr"   c                 ó   ‡ — ˆ fd„}|S )z2Register an implementation for a factory function.c                 óŽ   •— ‰j                  d| «        t        j                  ‰j                  ‰j                  d«      | «       | S )NÚfactoryÚBackendSelect)rv   r:   rA   r\   rB   )r’   ra   s    €r#   rR   z$CustomOp.impl_factory.<locals>.inner   s7   ø€ Ø×Ñ 	¨1Ô-ØBŒG�L‰L˜Ÿ™ D§L¡L°/ÓBÀ1ÔEØˆHr"   r!   )ra   rR   s   ` r#   Úimpl_factoryzCustomOp.impl_factoryý   s   ø€ ô	ð
 ˆr"   c                 ó   ‡ ‡— ˆˆ fd„}|S )r�   c                 ó0  •‡ ‡‡— ‰j                  «        ‰j                  d‰ ‰¬«       ‰j                  d«      j                  Š‰j                  Št        j                  ‰ «      ˆ ˆˆfd„«       }‰j                  j                  ‰j                  |d«       ‰ S )NÚabstractr   c                  óž   •— ˆˆfd„}t         j                  j                  j                  |«      5   ‰| i |¤Žcd d d «       S # 1 sw Y   y xY w)Nc                  ó&   •— t        d‰› d‰ › �«      ‚)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 ©rY   )rl   r%   s   €€r#   Úerror_on_ctxzOCustomOp.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’   rl   r%   s      €€€r#   Ú
f_with_ctxz9CustomOp.impl_abstract.<locals>.inner.<locals>.f_with_ctx  sD   ø€ õ
ô —^‘^×-Ñ-×<Ñ<¸\ÓJñ .Ù˜dÐ- fÑ-÷.÷ .ò .ús   ±AÁAÚMeta)
Ú$_check_doesnt_have_library_meta_implrv   r{   rl   r^   rG   Úwrapsr\   rA   rB   )r’   r«   rl   r%   r•   ra   s   ` @@€€r#   rR   z%CustomOp.impl_abstract.<locals>.inner  s}   û€ Ø×5Ñ5Ô7Ø×Ñ 
¨A¸+ÐÔFØ—~‘~ jÓ1×:Ñ:ˆHà—~‘~ˆHô �_‰_˜QÓõ.ó  ð.ð  �I‰I�N‰N˜4Ÿ<™<¨°VÔ<ØˆHr"   r!   ©ra   r•   rR   s   `` r#   Úimpl_abstractzCustomOp.impl_abstract  s   ù€ õ
	ð8 ˆr"   c                 ó$  ‡ ‡— ˆˆ fd„}‰ j                   Š‰j                  «       t        j                  k7  r |d«       ‰j                  }‰j                  s |d«       t        |«      dk  rt        dt        |«      › �«      ‚t        d„ |D «       «      }|r |d«       t        t        j                  «      dt        t        j                  «      d	t        t        j                  «      d
t        t        j                  «      dt        t        j                  «      dt        t        t        j                  «      d «      di}‰j                  D ]A  }|j                   |v rŒ |dt#        |j%                  «       «      › d|j                   › d�«       ŒC y )Nc                 ó@   •— t        d| › d‰j                  › d‰› �«      ‚)NzCCannot use torch._custom_ops APIs to register backward formula for z. Got operator z with schema: )rY   r^   )ÚdetailrL   ra   s    €€r#   Úerrorz4CustomOp._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   ój   K  — | ]+  }|j                   d uxr |j                   j                   –— Œ- y ­wrx   )Ú
annotationÚis_write)Ú.0Úrs     r#   ú	<genexpr>z8CustomOp._check_can_register_backward.<locals>.<genexpr><  s3   è ø€ ò #
ØGHˆA�L‰L Ð$ÒB¨Q¯\©\×-BÑ-BÐ)BÓBñ#
ùs   ‚13zoperator that returns viewsÚintÚSymIntÚboolÚfloatÚTensorzList[Tensor]zoperator with return not in z (got ú))rZ   rs   r
   Ú
functionalÚreturnsÚlenrf   Úanyr   r   r»   r¼   r½   r¾   r¿   r   r3   ÚlistÚvalues)ra   r´   ÚretsÚis_non_mutating_viewÚallowed_return_typesÚretrL   s   `     @r#   Ú_check_can_register_backwardz%CustomOp._check_can_register_backward*  sO  ù€ õ	ð —‘ˆØ�;‰;‹=œ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                 ó  — | j                   ry t        j                  | j                  d«      rt	        d| j                  › d�«      ‚dD ]>  }t        j                  | j                  |«      sŒ$t	        d| j                  › d|› d�«      ‚ y )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)r`   rE   Ú%_dispatch_has_kernel_for_dispatch_keyr^   rY   )ra   r›   s     r#   Ú(_check_doesnt_have_library_autograd_implz1CustomOp._check_doesnt_have_library_autograd_implR  s£   € Ø×7Ò7Øä×3Ñ3Ø�N‰NÐ7ô
ô ØEÀdÇnÁnÐEUð V>ð ?óð ð ?ò 	ˆCÜ×7Ñ7¸¿¹ÈÕLÜ"ð$Ø$(§N¡NÐ#3ð 42Ø25°ð 7YðZóð ñ	r"   c                 óŽ  — | j                  d«      ry t        j                  | j                  d«      r!t        j                  | j                  d«      sy t        j                  | j                  d«      rt	        d| j                  › d�«      ‚t        j                  | j                  d«      rt	        d| j                  › d�«      ‚y )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.)rk   rE   rÐ   r^   rY   rg   s    r#   r­   z-CustomOp._check_doesnt_have_library_meta_impln  sÄ   € Ø�>‰>˜*Ô%Øô ×3Ñ3Ø�N‰NÐ7ô
ä×:Ñ:¸4¿>¹>È6ÔRØô ×3Ñ3Ø�N‰NÐ7ô
ô Ø3°D·N±NÐ3Cð D;ð <óð ô ×3Ñ3°D·N±NÀFÔKÜØ3°D·N±NÐ3Cð DVð Wóð ð Lr"   c           
      ój  — | j                  d«      st        d«      ‚| j                  d«      st        d«      ‚t        | j                  | j                  | t        | j                  «      | j                  d«      j                  | j                  d«      j                  «      }| j                  d|«       y )NÚbackwardz&backward impl must be registered firstÚsave_for_backwardz/save_for_backward impl must be registered firstÚautograd)
rk   rf   r   rZ   Ú_output_differentiabilityÚget_opr^   r{   rJ   rv   )ra   Úkernels     r#   Ú_register_autograd_kernelz"CustomOp._register_autograd_kernelš  s“   € Ø�~‰~˜jÔ)Ü Ð!IÓJÐJØ�~‰~Ð1Ô2Ü Ð!RÓSÐSÜ*Ø�L‰LØ×*Ñ*ØÜ�4—>‘>Ó"Ø�N‰NÐ.Ó/×4Ñ4Ø�N‰N˜:Ó&×+Ñ+ó
ˆð 	×Ñ˜J¨Õ/r"   c                 ó   ‡ ‡— ˆˆ fd„}|S )zyRegister a function that tells us what to save for backward.

        Please see impl_backward for more details.
        c                 óê   •— ‰j                  «        ‰j                  «        ‰j                  s‰j                  «        ‰j	                  d| ‰¬«       ‰j                  d«      r‰j                  «        y y )NrÖ   r   rÕ   )rË   rÑ   r`   rh   rv   rk   rÛ   )r’   r•   ra   s    €€r#   rR   z.CustomOp.impl_save_for_backward.<locals>.inner¯  sc   ø€ Ø×-Ñ-Ô/Ø×9Ñ9Ô;Ø×?Ò?Ø×:Ñ:Ô<Ø×ÑÐ 3°QÀ;ÐÔOØ�~‰~˜jÔ)Ø×.Ñ.Õ0ð *r"   r!   r¯   s   `` r#   Úimpl_save_for_backwardzCustomOp.impl_save_for_backward©  s   ù€ õ	1ð ˆr"   c                 óø   ‡ ‡‡— ‰�mˆfd„}t        ‰t        «      s |«        ‰D ]  }t        |t        «      rŒ |«        Œ t        ‰ j                  j
                  «      t        ‰«      k7  r |«        ˆˆˆ fd„}|S )r�   c                  ó    •— t        d‰ › �«      ‚)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#   Úyellz$CustomOp.impl_backward.<locals>.yellÀ  s"   ø€ Ü"ðð 5Ð5ð7óð r"   c                 óø   •— ‰j                  «        ‰j                  «        ‰j                  s‰j                  «        ‰j	                  d| ‰¬«       ‰‰_        ‰j                  d«      r‰j                  «        y y )NrÕ   r   rÖ   )rË   rÑ   r`   rh   rv   rØ   rk   rÛ   )r’   r•   rá   ra   s    €€€r#   rR   z%CustomOp.impl_backward.<locals>.innerÐ  sk   ø€ Ø×-Ñ-Ô/Ø×9Ñ9Ô;Ø×?Ò?Ø×:Ñ:Ô<Ø×Ñ 
¨A¸+ÐÔFØ-EˆDÔ*Ø�~‰~Ð1Ô2Ø×.Ñ.Õ0ð 3r"   )r–   rÅ   r½   rÃ   rZ   rÂ   )ra   rá   r•   râ   ÚdiffrR   s   ```   r#   Úimpl_backwardzCustomOp.impl_backwardº  sp   ú€ ð $Ð/ôô Ð6¼Ô=Ù”Ø0ò �Ü! $¬Õ-Ù•Fðô �4—<‘<×'Ñ'Ó(¬CÐ0HÓ,IÒIÙ”ö	1ð ˆr"   )r   )Nr   )r6   r?   Ú__qualname__r@   rX   rh   rv   r{   rk   rƒ   r…   rŠ   r—   ÚtypingÚIterableÚCallablerA   r�   r    r°   rË   rÑ   r­   rÛ   rÞ   rå   Ú__classcell__)rd   s   @r#   r   r   �   s«   ø„ ñð
 PUö/ò8<ó<ò!ò#ò,ò4òð ñà˜FŸO™O¨CÑ0Ñ0ðð 
�‰ó	ò.	ð˜fŸo™oó ñ!¨f¯o©oó !òF&òPò8%òX0ó÷" r"   c                   ó6   — e Zd ZU ej                  ed<   eed<   y)rr   rJ   rl   N)r6   r?   ræ   rç   ré   Ú__annotations__r—   r!   r"   r#   rr   rr   Ý  s   … à
�/‰/ÓØ„Mr"   rr   rb   rc   c                 ó’   — |j                   €dn|j                   }t        j                  | › dt        |j                  «      › �|«      S )NÚ rV   )Úoverload_namerE   Ú_dispatch_find_schema_or_throwr—   r>   )rb   rc   rï   s      r#   r=   r=   ã  sN   € à×)Ñ)Ð1‰°}×7RÑ7Rð ô ×,Ñ,Øˆ(�"”S˜×+Ñ+Ó,Ð-Ð.°óð r"   rK   c                 ó^   — d| v rt        d| › d�«      ‚| t        v rt        d| › d| › d�«      ‚y )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                 óº   — t         j                  j                  j                  | «      st	        d| › �«      ‚| j
                  j                  �t	        d| › �«      ‚y )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   ù  sn   € Ü�>‰>×Ñ×4Ñ4°VÔ<Üð8ð 9?°xðAó
ð 	
ð ×Ñ× Ñ Ð,Üð*Ø*0¨ð3ó
ð 	
ð -r"   c                 óž   — | j                  dd«      }t        |«      dk7  rt        d| › d�«      ‚d|d   v rt        d| › �«      ‚|d   |d   fS )	NrV   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                 ó\   — | t         vr$t        d| › dt         j                  «       › d�«      ‚y )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                 ó‚   — | j                   t        j                  j                  t        j                  j                  fv S rx   )rs   r0   Ú	ParameterÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLY)rþ   s    r#   Úsupported_paramr  #  s6   € Ø�:‰:Ü×Ñ×/Ñ/Ü×Ñ×&Ñ&ðð ð r"   rJ   c                 óf  ‡ ‡‡‡	— t        j                  |«      Š	t        d„ ‰	j                  j	                  «       D «       «      st        d‰	› �«      ‚t        d„ ‰	j                  j	                  «       D «       «      s&‰	j                  t         j                  j                  urt        d‰	› �«      ‚‰	j                  j	                  «       D ��cg c]0  \  }}|j                  t         j                  j                  k(  r||f‘Œ2 }}}‰	j                  j	                  «       D ��cg c]0  \  }}|j                  t         j                  j                  k(  r||f‘Œ2 }}}ˆ ˆ	fd„Šˆ ˆ	fd„Šˆˆfd„} ||‰ j                  j                  «        ||‰ j                  j                   «       y c c}}w c c}}w )Nc              3   ó8   K  — | ]  \  }}t        |«      –— Œ y ­wrx   )r  ©r¸   Ú_Úps      r#   rº   z3validate_function_matches_schema.<locals>.<genexpr>/  s   è ø€ ÒE¡d a¨Œ˜q×!ÑEù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   ón   K  — | ]-  \  }}|j                   t        j                  j                  u–— Œ/ y ­wrx   )r¶   r0   r   Úemptyr  s      r#   rº   z3validate_function_matches_schema.<locals>.<genexpr>7  s1   è ø€ ò 
á��1ð �L‰L¤× 1Ñ 1× 7Ñ 7Ô7ñ
ùs   ‚35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                  ó&   •— t        d‰› d‰ › �«      ‚)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´   z/validate_function_matches_schema.<locals>.errorN  ó)   ø€ Üð!ð "% Ð%6°v°hð@ó
ð 	
r"   c                  ó&   •— t        d‰› d‰ › �«      ‚)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_argsz<validate_function_matches_schema.<locals>.error_default_argsV  r  r"   c                 ó  •— t        | «      t        |«      k7  r ‰«        t        | |«      D ]X  \  \  }}}||j                  k7  r ‰«        |j                  t        j
                  j                  us|j                  €ŒR ‰«        ŒZ y rx   )rÃ   Úzipr>   Údefaultr0   r   r
  )Úsig_argsÚschema_argsr>   rþ   Úargr´   r  s        €€r#   Úcomparez1validate_function_matches_schema.<locals>.compare^  sp   ø€ Üˆx‹=œC Ó,Ò,ÙŒGÜ"% h°Ó"<ò 	%Ñ‰MˆT�5˜3Ø�s—x‘xÒÙ”Ø�}‰}¤G×$5Ñ$5×$;Ñ$;Ñ;¸s¿{¹{Ñ?VÙ"Õ$ñ		%r"   )r0   Ú	signatureÚallÚ
parametersÚitemsr2   rÄ   Úreturn_annotationÚ	Signaturer
  rs   r   r  r  r÷   Úflat_positionalÚflat_kwarg_only)
rL   rJ   r>   rþ   Ú
positionalÚ	kwargonlyr  r´   r  r  s
   `      @@@r#   r9   r9   *  s‰  û€ ô ×
Ñ
˜DÓ
!€CäÑE¨c¯n©n×.BÑ.BÓ.DÔEÔEÜð<à<?¸5ðBó
ð 	
ô 	ñ 
àŸ™×,Ñ,Ó.ô
ô 	
ð × Ñ ¬×(9Ñ(9×(?Ñ(?Ñ?äð5à58°Eð;ó
ð 	
ð Ÿ>™>×/Ñ/Ó1÷áˆD�%Ø�:‰:œ×*Ñ*×@Ñ@Ò@ð 
ˆuŠð€Jñ ð Ÿ>™>×/Ñ/Ó1÷áˆD�%Ø�:‰:œ×*Ñ*×7Ñ7Ò7ð 
ˆuŠð€Iñ õ
õ
õ%ñ ˆJ˜×(Ñ(×8Ñ8Ô9ÙˆI�v×'Ñ'×7Ñ7Õ8ùóKùó
s   Ã5F'Ä"5F-r   r›   c           
      óÆ   — |dk(  rt        | › d�«      ‚|dk(  rt        | › d�«      ‚|dv r'|j                  «       }t        | › d|› d|› d|› d	�«      ‚t        | › d
|› d�«      ‚)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   k  sº   € Ø
ˆkÒÜ!Øˆkð 'ð (ó
ð 	
ð ˆf‚}Ü!Øˆkð Tð Uó
ð 	
ð
 ˆoÑØ—‘“ˆÜ!ØˆkÐ5°f°XÐ=TØˆhð *Ø*0¨°ð5ó
ð 	
ô
 Øˆ+Ð:¸3¸%ð @ð 	óð r"   c                 ó@  — | j                   }t        j                  j                  |d«      }| j	                  «       j                  d«      d   }t        | j                  «      }|j                  dd¬«      d   }t        j                  |«      }t        ||||| d¬«      S )Nr,   rV   éÿÿÿÿr   )ÚmaxsplitTr-   )Ú	namespacer   r:   r;   r>   rú   r—   rZ   Úrsplitr   r7   r   )ÚoprK   rO   r>   rM   rL   s         r#   Úcustom_op_from_existingr/  ‰  s†   € Ø	�‰€BÜ
�-‰-×
Ñ
  JÓ
/€CØ�7‰7‹9�?‰?˜4Ó  Ñ$€DÜ�R—Z‘Z“€Jà×"Ñ" 4°!Ð"Ó4°RÑ8€JÜ×!Ñ! *Ó-€FÜ�C˜˜V T¨2¸tÔDÐDr"   c                 ó  ‡ — ˆ fd„}t        ‰ «      \  }}t        t        j                  |«      s |«        t	        t        j                  |«      }t        ||«      s |«        t	        ||«      }t        |d«      s |«        |j
                  S )Nc                  ó"   •— t        d‰ › d�«      ‚)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_foundzget_op.<locals>.error_not_found•  s!   ø€ ÜØ*¨8¨*ð 54ð 5ó
ð 	
r"   r  )r4   r€   r   r   r~   r  )r%   r2  rK   r>   r‚   Úpackets   `     r#   rÙ   rÙ   ”  sr   ø€ ô
ô ˜hÓ'�H€BˆÜ”5—9‘9˜bÔ!ÙÔÜœ%Ÿ)™) RÓ(€KÜ�; Ô%ÙÔÜ�[ $Ó'€FÜ�6˜9Ô%ÙÔØ�>‰>Ðr"   c                 óv   — | t         v r	t         |    S |st        d| › d�«      ‚t        | «      }t        |«      }|S )NzCould not find custom op "z5". Did you register it via the torch._custom_ops API?)rS   rY   rÙ   r/  )r%   Úalso_check_torch_libraryÚoverloadrQ   s       r#   Ú_find_custom_opr7  ¨  sQ   € Ø”?Ñ"Ü˜xÑ(Ð(Ù#ÜØ(¨¨
ð 3)ð *ó
ð 	
ô �hÓ€HÜ$ XÓ.€FØ€Mr"   c                 óþ   — | t         j                  j                  j                  vry t         j                  j                  j                  |    }|€y |j	                  d«      sy |j                  d«      j                  S )Nr£   )r   Ú
_custom_oprA   rS   rk   r{   rJ   )r%   r   s     r#   Úget_abstract_implr:  µ  sl   € Ø”u×'Ñ'×,Ñ,×<Ñ<Ñ<ØÜ× Ñ ×%Ñ%×5Ñ5°hÑ?€IØÐØØ×Ñ˜zÔ*ØØ×Ñ˜zÓ*×/Ñ/Ð/r"   c           	      ó4  — | j                  d«      \  }}|› |› �}t        j                  |«      }t        |«       |r%t        j
                  j                  j                  gng }t        j                  |d«      }|j                  ||¬«       t        ||j                  «      }	t        |||||	d¬«      }
|
j                  «        t        j
                  j                  |	t!        j"                  t$        t'        j(                  |
«      «      «       t+        | «      S )NrV   r,   )ÚtagsTr-   )rú   r   r7   r8   r   rE   ÚTagÚneeds_fixed_stride_orderr:   r;   r<   r=   r>   r   rh   rF   rG   rH   rI   rC   rD   rÙ   )r%   rL   r>  rK   r>   rM   rN   r<  rO   rP   rQ   s              r#   Ú_custom_op_with_schemar?  À  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˜2˜°°hÐPTÔU€FØ
×0Ñ0Ô2ä	‡H�H×0Ñ0Ø”)×#Ñ#Ô$9¼7¿=¹=ÈÓ;PÓQôô �(ÓÐr"   rx   )F)T)7ÚdataclassesrG   r0   rn   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—   ré   r   rS   Údictrì   r   Ú	dataclassrr   r=   r5   r8   Útupler4   r˜   r   r½   r  r9   ÚAnyrI   r/  rÙ   r7  r:  r?  r!   r"   r#   ú<module>rJ     s¢  ðä Û Û Û 
Û Û Û ã Ý Û "Ý Ý 4Ý !÷÷ ÷ Mðò
 /€ð Øñ Ð ò€òñ7˜ð 7¨C°$©Jð 7À&Ç/Á/ó 7ð@ *,€��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"   