§
    ŠŠtj
k  ã                   ó<  — 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 j$         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j,        de-fd!„Z.ded"ej        ddfd#„Z/d$ej0        d%eddfd&„Z1d'„ Z2d(„ Z3d/d*„Z4d+„ Z5d0d-„Z6dS )1é    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¬¦  «         d S )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© ó    úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/_custom_op/impl.pyÚwarn_deprecatedr$   5   s0   € Ý„Mð	8åØð	ñ ô ð ð ð r"   ÚqualnameÚmanual_schemaÚreturnc                 ó2   ‡ ‡— 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        |k    rt          d‰
› d|› d| j        › d�¦  «        ‚‰	€t          | d¬¦  «        n‰	}|› |› �}t          j	        |¦  «        }t          |¦  «         ‰	�t          || ¦  «         t          j        |d¦  «        }|                     |¦  «         t          ||j        ¦  «        }t#          |||||d	¬
¦  «        }| j        |_        | j        |_        | j        |_         t          j        ||j        d¦  «        t-          t/          j        |¦  «        ¦  «        ¦  «         t2          j                             |t9          j        t<          t/          j        |¦  «        ¦  «        ¦  «         |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ð ,ð ,Ø!%ð,ð ,Ø26´-ð,ð ,ð ,ñô ð ð Ð$õ ˜¨BÐ/Ñ/Ô/Ð/àð 	ð
 Ð&˜fÐ&Ð&ˆ
Ý(Ô.¨zÑ:Ô:ˆÝ˜Ñ(Ô(Ð(ØÐ$Ý,¨_¸dÑCÔCÐCåŒo˜b *Ñ-Ô-ˆØ�
Š
�:ÑÔÐÝ)¨"¨oÔ.BÑCÔCˆÝØ��_ d¨HÀdð
ñ 
ô 
ˆð œ-ˆŒØ œOˆÔØœˆŒà5�Œ�S˜&œ.¨*Ñ5Ô5Ý'­¬°fÑ(=Ô(=Ñ>Ô>ñ	
ô 	
ð 	
õ 	Œ×4Ò4Ø•iÔ'Õ(=½w¼}ÈVÑ?TÔ?TÑUÔUñ	
ô 	
ð 	
ð ˆr"   )r$   )r%   r&   rR   s   `` r#   r   r   >   s8   øø€ õ ÑÔÐð/ð /ð /ð /ð /ð /ð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                ó0  •— t          ¦   «                              ¦   «          t          ¦   «          |st          d¦  «        ‚|› d|› �}|| _        || _        || _        || _        || _        || _	        d | _
        i | _        d| _        | t          | j	        <   d S )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        t          t          j        | ¦  «        ¦  «        d¦  «         d| _         d S )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¢   sa   € ØÔ7ð 	SÝ Ð!QÑRÔRÐRØŒ	�ŠØŒLÕ5µg´mÀDÑ6IÔ6IÑJÔJÈJñ	
ô 	
ð 	
ð 8<ˆÔ4Ð4Ð4r"   r   c                 óZ  — |                       |¦  «        rF| j        |         }|€t          d¦  «        ‚|j        }t	          d|› d| j        › d|› d|› d�	¦  «        ‚t          j        t          j	        |¦  «        ¦  «        }|j
        › d|j        › �}t          ||¦  «        | j        |<   d S )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ÐNØ(Ô1ˆHÝð6¨Dð 6ð 6ÀTÄ^ð 6ð 6Ø&*ð6ð 6àð6ð 6ð 6ñô ð õ
 Ô$¥S¤]°:Ñ%>Ô%>Ñ?Ô?ˆØ”nÐ5Ð5 u¤|Ð5Ð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	        = d S rx   )
r\   Úgetattrr   Úopsr[   ÚhasattrrB   ÚdelattrrS   r^   )ra   Úopnamespaces     r#   Ú_destroyzCustomOp._destroyÂ   sR   € ð ˆIå�eœi¨¬Ñ6Ô6ˆÝ�; ¤Ñ-Ô-ð 	/Ý�K ¤Ñ.Ô.Ð.å˜DœNÐ+Ð+Ð+r"   c                 ó   — d| j         › d�S )Nz<CustomOp(op="z")>)r^   rg   s    r#   Ú__repr__zCustomOp.__repr__Ñ   s   € Ø3 ¤Ð3Ð3Ð3Ð3r"   c                 ó:   — t          j        | j        g|¢R i |¤Ž}|S rx   )rE   Ú_dispatch_call_boxedr]   )ra   ÚargsÚkwargsrQ   s       r#   Ú__call__zCustomOp.__call__Ô   s+   € õ Ô(¨¬ÐI¸$ÐIÐIÐIÀ&ÐIÐIˆØˆr"   Údevice_typesr'   c                 ór   ‡ ‡‡— t          ‰t          ¦  «        r‰gŠ‰D ]}t          |¦  «         Œˆˆˆ fd„}|S )úT
        This API is deprecated, please use torch.library.custom_op instead
        c                 óò   •— t          ‰¦  «        D ]e}‰                     |¦  «         ‰                     || ‰¬¦  «         t          |         } t	          j        ‰j        ‰j        |¦  «        | ¦  «         Œf| 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è   s   ø€ Ý" <Ñ0Ô0ð Gð G�Ø×4Ò4°[ÑAÔAÐAØ×#Ò# K°¸{Ð#ÑKÔKÐKÝ;¸KÔH�ØC•”˜TœY¨¬°lÑCÔCÀAÑFÔFÐFÐFØˆHr"   )Ú
isinstanceÚstrÚvalidate_device_type)ra   r‹   r•   r“   rR   s   ```  r#   rA   zCustomOp.implÛ   sj   øøø€ õ �l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ'ð 	.ð 	.ˆKÝ  Ñ-Ô-Ð-Ð-ð	ð 	ð 	ð 	ð 	ð 	ð 	ð ˆr"   c                 ó¸   — |                       |¦  «        rd S t          |         }t          j        | j        |¦  «        rt          d|› d| j        › d�¦  «        ‚d S )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ò   s‚   € Ø�>Š>˜+Ñ&Ô&ð 	ØˆFÝ*¨;Ô7ˆÝÔ<¸T¼^ÈSÑQÔQð 	ÝðM¨+ð Mð MÀtÄ~ð Mð Mð Mñô ð ð	ð 	r"   c                 ó   ‡ — ˆ fd„}|S )z2Register an implementation for a factory function.c                 ó†   •— ‰                      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   s@   ø€ Ø×Ò 	¨1Ñ-Ô-Ð-ØB�GŒL˜œ D¤L°/ÑBÔBÀ1ÑEÔEÐEØˆHr"   r!   )ra   rR   s   ` r#   Úimpl_factoryzCustomOp.impl_factoryý   s#   ø€ ð	ð 	ð 	ð 	ð 	ð
 ˆr"   c                 ó   ‡ ‡— ˆˆ fd„}|S )r�   c                 ó,  •‡ ‡‡— ‰                      ¦   «          ‰                     d‰ ‰¬¦  «         ‰                     d¦  «        j        Š‰j        Št          j        ‰ ¦  «        ˆ ˆˆfd„¦   «         }‰j                             ‰j	        |d¦  «         ‰ S )NÚabstractr   c                  óœ   •— ˆˆfd„}t           j        j                             |¦  «        5   ‰| i |¤Žcd d d ¦  «         S # 1 swxY w Y   d S )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  s6   ø€ Ý&ð)Ø'ð)ð )ð 'ð)ð )ñ	ô 	ð 	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  s²   ø€ ð
ð 
ð 
ð 
ð 
ð 
õ ”^Ô-×<Ò<¸\ÑJÔJð .ð .Ø˜1˜dÐ- fÐ-Ð-ð.ð .ð .ð .ñ .ô .ð .ð .ð .ð .ð .ð .øøøð .ð .ð .ð .ð .ð .s   ¬AÁ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Ô7Ð7Ø×Ò 
¨A¸+ÐÑFÔFÐFØ—~’~ jÑ1Ô1Ô:ˆHà”~ˆHõ Œ_˜QÑÔð.ð .ð .ð .ð .ð .ñ  Ôð.ð  ŒI�NŠN˜4œ<¨°VÑ<Ô<Ð<ØˆHr"   r!   ©ra   r•   rR   s   `` r#   Úimpl_abstractzCustomOp.impl_abstract  s)   øø€ ð
	ð 	ð 	ð 	ð 	ð 	ð8 ˆr"   c                 ó@  ‡ ‡— ˆˆ fd„}‰ j         Š‰                     ¦   «         t          j        k    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 ]B}|j        |v rŒ |dt#          |                     ¦   «         ¦  «        › d|j        › d�¦  «         ŒCd S )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+  sC   ø€ Ýð:Ø%ð:ð :à”>ð:ð :à17ð:ð :ñô ð r"   znon-functional operatorzoperator with no returnsr   z"expected at least one return, got c              3   óB   K  — | ]}|j         d uo|j         j         V — Œd S rx   )Ú
annotationÚis_write)Ú.0Úrs     r#   ú	<genexpr>z8CustomOp._check_can_register_backward.<locals>.<genexpr><  sG   è è € ð #
ð #
ØGHˆAŒL Ð$ÐB¨Q¬\Ô-BÐ)Bð#
ð #
ð #
ð #
ð #
ð #
r"   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*  sË  øø€ ð	ð 	ð 	ð 	ð 	ð 	ð ”ˆØ�;Š;‰=Œ=�JÔ1Ò1Ð1ØˆEÐ+Ñ,Ô,Ð,àŒ~ˆØŒ~ð 	.ØˆEÐ,Ñ-Ô-Ð-åˆt‰9Œ9˜Š>ˆ>Ý Ð!QÅcÈ$ÁiÄiÐ!QÐ!QÑRÔRÐRÝ"ð #
ð #
ØLPð#
ñ #
ô #
ñ  
ô  
Ðð  ð 	1ØˆEÐ/Ñ0Ô0Ð0õ •V”ZÑ Ô  %Ý•V”]Ñ#Ô# XÝ•V”[Ñ!Ô! 6Ý•V”\Ñ"Ô" GÝ•V”]Ñ#Ô# XÝ•X�fœmÑ,Ô,¨dÑ3Ô3°^ð 
Ðð ”>ð 	ð 	ˆCØŒxÐ/Ð/Ð/ØØˆEØe­tÐ4H×4OÒ4OÑ4QÔ4QÑ/RÔ/RÐeÐeÐZ]ÔZbÐeÐeÐeñô ð ð ð	ð 	r"   c                 óð   — | j         rd S t          j        | j        d¦  «        rt	          d| j        › d�¦  «        ‚dD ]7}t          j        | j        |¦  «        rt	          d| j        › d|› d�¦  «        ‚Œ8d S )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ð 	ØˆFåÔ3ØŒNÐ7ñ
ô 
ð 
	õ ð?ÀdÄnð ?ð ?ð ?ñô ð ð ?ð 	ð 	ˆCÝÔ7¸¼ÈÑLÔLð Ý"ðZØ$(¤NðZð Zà25ðZð Zð Zñô ð ðð	ð 	r"   c                 óh  — |                       d¦  «        rd S t          j        | j        d¦  «        rt          j        | j        d¦  «        sd S t          j        | j        d¦  «        rt	          d| j        › d�¦  «        ‚t          j        | j        d¦  «        rt	          d| j        › d�¦  «        ‚d S )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 a 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ô   € Ø�>Š>˜*Ñ%Ô%ð 	ØˆFõ Ô3ØŒNÐ7ñ
ô 
ð 	åÔ:¸4¼>È6ÑRÔRð	ð ˆFõ Ô3ØŒNÐ7ñ
ô 
ð 
	õ ð<°D´Nð <ð <ð <ñô ð õ Ô3°D´NÀFÑKÔKð 	ÝðW°D´Nð Wð Wð Wñô ð ð	ð 	r"   c           
      ó‚  — |                       d¦  «        st          d¦  «        ‚|                       d¦  «        st          d¦  «        ‚t          | j        | j        | t          | j        ¦  «        |                      d¦  «        j        |                      d¦  «        j        ¦  «        }|  	                    d|¦  «         d S )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Ñ)Ô)ð 	KÝ Ð!IÑJÔJÐJØ�~Š~Ð1Ñ2Ô2ð 	TÝ Ð!RÑSÔSÐSÝ*ØŒLØÔ*ØÝ�4”>Ñ"Ô"Ø�NŠNÐ.Ñ/Ô/Ô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        s‰                     ¦   «          ‰                     d| ‰¬¦  «         ‰                     d¦  «        r‰                     ¦   «          d S d S )NrÖ   r   rÕ   )rË   rÑ   r`   rh   rv   rk   rÛ   )r’   r•   ra   s    €€r#   rR   z.CustomOp.impl_save_for_backward.<locals>.inner¯  s–   ø€ Ø×-Ò-Ñ/Ô/Ð/Ø×9Ò9Ñ;Ô;Ð;ØÔ?ð =Ø×:Ò:Ñ<Ô<Ð<Ø×ÒÐ 3°QÀ;ÐÑOÔOÐOØ�~Š~˜jÑ)Ô)ð 1Ø×.Ò.Ñ0Ô0Ð0Ð0Ð0ð1ð 1r"   r!   r¯   s   `` r#   Úimpl_save_for_backwardzCustomOp.impl_save_for_backward©  s)   øø€ ð	1ð 	1ð 	1ð 	1ð 	1ð 	1ð ˆr"   Nc                 ó  ‡ ‡‡— ‰�|ˆfd„}t          ‰t          ¦  «        s
 |¦   «          ‰D ]!}t          |t          ¦  «        s
 |¦   «          Œ"t          ‰ j        j        ¦  «        t          ‰¦  «        k    r
 |¦   «          ˆˆˆ fd„}|S )r�   Nc                  ó(   •— 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)   ø€ Ý"ð7ð 5ð7ð 7ñô ð r"   c                 ó"  •— ‰                      ¦   «          ‰                     ¦   «          ‰j        s‰                     ¦   «          ‰                     d| ‰¬¦  «         ‰‰_        ‰                     d¦  «        r‰                     ¦   «          d S d S )NrÕ   r   rÖ   )rË   rÑ   r`   rh   rv   rØ   rk   rÛ   )r’   r•   rá   ra   s    €€€r#   rR   z%CustomOp.impl_backward.<locals>.innerÐ  sž   ø€ Ø×-Ò-Ñ/Ô/Ð/Ø×9Ò9Ñ;Ô;Ð;ØÔ?ð =Ø×:Ò:Ñ<Ô<Ð<Ø×Ò 
¨A¸+ÐÑFÔFÐFØ-EˆDÔ*Ø�~Š~Ð1Ñ2Ô2ð 1Ø×.Ò.Ñ0Ô0Ð0Ð0Ð0ð1ð 1r"   )r–   rÅ   r½   rÃ   rZ   rÂ   )ra   rá   r•   râ   ÚdiffrR   s   ```   r#   Úimpl_backwardzCustomOp.impl_backwardº  sÉ   øøø€ ð $Ð/ðð ð ð ð õ Ð6½Ñ=Ô=ð Ø�‘”�Ø0ð ð �Ý! $­Ñ-Ô-ð Ø�D‘F”F�FøÝ�4”<Ô'Ñ(Ô(­CÐ0HÑ,IÔ,IÒIÐIØ�‘”�ð	1ð 	1ð 	1ð 	1ð 	1ð 	1ð 	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ð 4ð 4ðð ð ð ðð à˜FœO¨CÔ0Ñ0ðð 
Œð	ð ð ð ð.	ð 	ð 	ð˜fœoð ð ð ð ð!ð !¨f¬oð !ð !ð !ð !ðF&ð &ð &ðPð ð ð8%ð %ð %ðX0ð 0ð 0ðð ð ð ð" ð  ð  ð  ð  ð  ð  ð  r"   c                   ó.   — e Zd ZU ej        ed<   eed<   dS )rr   rJ   rl   N)r6   r?   ræ   rç   ré   Ú__annotations__r—   r!   r"   r#   rr   rr   Ý  s'   € € € € € € à
Œ/ÐÐÑØ€M€M�M€M€Mr"   rr   rb   rc   c                 óz   — |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ð õ Ô,ØÐ.Ð.•S˜Ô+Ñ,Ô,Ð.Ð.°ñô ð r"   rK   c                 ór   — d| v rt          d| › d�¦  «        ‚| t          v rt          d| › d| › d�¦  «        ‚d S )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   ì  s|   € Ø
ˆb€y€yÝð$ "ð $ð $ð $ñ
ô 
ð 	
ð 
�[ÐÐÝð. "ð .ð .¨2ð .ð .ð .ñ
ô 
ð 	
ð Ðr"   rL   c                 ó®   — t           j        j                             | ¦  «        st	          d| › �¦  «        ‚| j        j        �t	          d| › �¦  «        ‚d S )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   ù  s€   € ÝŒ>Ô×4Ò4°VÑ<Ô<ð 
ÝðAð 9?ðAð Añ
ô 
ð 	
ð ÔÔ Ð,Ýð3Ø*0ð3ð 3ñ
ô 
ð 	
ð -Ð,r"   c                 óÒ   — |                       dd¦  «        }t          |¦  «        dk    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„z�Q‚€Ýð@°8ð @ð @ð @ñ
ô 
ð 	
ð ˆe�AŒh€€Ýðð ðð ñ
ô 
ð 	
ð �Œ8�U˜1”XÐÐr"   r“   c                 ór   — | t           vr-t          d| › dt                                ¦   «         › d�¦  «        ‚d S )NzCustomOp.impl(device_types=[z(, ...]): we only support device_type in rò   )r‘   r2   Úkeys)r“   s    r#   r˜   r˜     sW   € ØÕ6Ð6Ð6Ýð9¨;ð 9ð 9Ý.×3Ò3Ñ5Ô5ð9ð 9ð 9ñ
ô 
ð 	
ð 7Ð6r"   Úparamc                 óT   — | j         t          j        j        t          j        j        fv S rx   )rs   r0   Ú	ParameterÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLY)rþ   s    r#   Úsupported_paramr  #  s(   € ØŒ:ÝÔÔ/ÝÔÔ&ðð ð r"   rJ   c                 óv  ‡ ‡‡‡— t          j        |¦  «        Št          d„ ‰j                             ¦   «         D ¦   «         ¦  «        st          d‰› �¦  «        ‚t          d„ ‰j                             ¦   «         D ¦   «         ¦  «        s‰j        t           j        j	        urt          d‰› �¦  «        ‚d„ ‰j         
                    ¦   «         D ¦   «         }d„ ‰j         
                    ¦   «         D ¦   «         }ˆ ˆfd„Šˆ ˆfd„Šˆˆfd	„} ||‰ j        j        ¦  «          ||‰ j        j        ¦  «         d S )
Nc              3   ó4   K  — | ]}t          |¦  «        V — Œd S rx   )r  ©r¸   Úps     r#   rº   z3validate_function_matches_schema.<locals>.<genexpr>/  s*   è è € ÐCÐC a�˜qÑ!Ô!ÐCÐCÐCÐCÐCÐCr"   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   óF   K  — | ]}|j         t          j        j        uV — Œd S rx   )r¶   r0   r   Úemptyr  s     r#   rº   z3validate_function_matches_schema.<locals>.<genexpr>7  s@   è è € ð 
ð 
Ø<=ˆAŒL¥Ô 1Ô 7Ð7ð
ð 
ð 
ð 
ð 
ð 
r"   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                 óP   — g | ]#\  }}|j         t          j        j        k    ¯||f‘Œ$S r!   )rs   r0   r   r  ©r¸   r>   rþ   s      r#   ú
<listcomp>z4validate_function_matches_schema.<locals>.<listcomp>B  s=   € ð ð ð áˆD�%ØŒ:�Ô*Ô@Ò@Ð@ð 
ˆuˆà@Ð@Ð@r"   c                 óP   — g | ]#\  }}|j         t          j        j        k    ¯||f‘Œ$S r!   )rs   r0   r   r  r  s      r#   r  z4validate_function_matches_schema.<locals>.<listcomp>G  s=   € ð ð ð áˆD�%ØŒ:�Ô*Ô7Ò7Ð7ð 
ˆuˆà7Ð7Ð7r"   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>.errorM  ó=   ø€ Ýð@ð "%ð@ð @ð 8>ð@ð @ñ
ô 
ð 	
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_argsU  r  r"   c                 ó
  •— t          | ¦  «        t          |¦  «        k    r
 ‰¦   «          t          | |¦  «        D ]F\  \  }}}||j        k    r
 ‰¦   «          |j        t          j        j        us|j        �
 ‰¦   «          ŒGd S rx   )rÃ   Úzipr>   Údefaultr0   r   r	  )Úsig_argsÚschema_argsr>   rþ   Úargr´   r  s        €€r#   Úcomparez1validate_function_matches_schema.<locals>.compare]  s•   ø€ Ýˆx‰=Œ=�C Ñ,Ô,Ò,Ð,ØˆE‰GŒGˆGÝ"% h°Ñ"<Ô"<ð 	%ð 	%Ñ‰MˆT�5˜3Ø�s”xÒÐØ�‘”�ØŒ}¥GÔ$5Ô$;Ð;Ð;¸s¼{Ð?VØ"Ð"Ñ$Ô$Ð$øð		%ð 	%r"   )r0   Ú	signatureÚallÚ
parametersrÆ   r2   rÄ   Úreturn_annotationÚ	Signaturer	  Úitemsr÷   Úflat_positionalÚflat_kwarg_only)rL   rJ   Ú
positionalÚ	kwargonlyr  r´   r  r  s   `    @@@r#   r9   r9   *  sÎ  øøøø€ õ Ô
˜DÑ
!Ô
!€CåÐCÐC¨3¬>×+@Ò+@Ñ+BÔ+BÐCÑCÔCÑCÔCð 
ÝðBà<?ðBð Bñ
ô 
ð 	
õ 	ð 
ð 
ØADÄ×AVÒAVÑAXÔAXð
ñ 
ô 
ñ 	
ô 	
ð

ð Ô ­Ô(9Ô(?Ð?Ð?åð;à58ð;ð ;ñ
ô 
ð 	
ðð àœ>×/Ò/Ñ1Ô1ðñ ô €Jð
ð àœ>×/Ò/Ñ1Ô1ðñ ô €Ið
ð 
ð 
ð 
ð 
ð 
ð
ð 
ð 
ð 
ð 
ð 
ð%ð %ð %ð %ð %ð %ð €GˆJ˜Ô(Ô8Ñ9Ô9Ð9Ø€GˆI�vÔ'Ô7Ñ8Ô8Ð8Ð8Ð8r"   r   r›   c           
      óò   — |dk    rt          | › d�¦  «        ‚|dk    rt          | › d�¦  «        ‚|dv r/|                     ¦   «         }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   j  sù   € Ø
ˆkÒÐÝ!Øð (ð (ð (ñ
ô 
ð 	
ð ˆf‚}€}Ý!Øð Uð Uð Uñ
ô 
ð 	
ð
 ˆoÐÐØ—’‘”ˆÝ!Øð 5ð 5°fð 5ð 5Øð5ð 5à*0ð5ð 5ð 5ñ
ô 
ð 	
õ
 Øð 	ð 	¸3ð 	ð 	ð 	ñô ð r"   c                 ó^  — | j         }t          j                             |d¦  «        }|                      ¦   «                              d¦  «        d         }t          | 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_existingr2  ˆ  s“   € Ø	Œ€BÝ
Œ-×
Ò
  JÑ
/Ô
/€CØ�7Š7‰9Œ9�?Š?˜4Ñ Ô  Ô$€DÝ�R”Z‘”€Jà×"Ò" 4°!Ð"Ñ4Ô4°RÔ8€JÝÔ! *Ñ-Ô-€FÝ�C˜˜V T¨2¸tÐDÑDÔDÐDr"   c                 óD  ‡ — ˆ 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+   ø€ Ýð5¨8ð 5ð 5ð 5ñ
ô 
ð 	
r"   r  )r4   r€   r   r   r~   r  )r%   r5  rK   r>   r‚   Úpackets   `     r#   rÙ   rÙ   “  s¹   ø€ ð
ð 
ð 
ð 
ð 
õ ˜hÑ'Ô'�H€BˆÝ•5”9˜bÑ!Ô!ð ØˆÑÔÐÝ�%œ) RÑ(Ô(€KÝ�; Ñ%Ô%ð ØˆÑÔÐÝ�[ $Ñ'Ô'€FÝ�6˜9Ñ%Ô%ð ØˆÑÔÐØŒ>Ðr"   Fc                 ó˜   — | 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Ù   r2  )r%   Úalso_check_torch_libraryÚoverloadrQ   s       r#   Ú_find_custom_opr:  §  si   € Ø•?Ð"Ð"Ý˜xÔ(Ð(Ø#ð 
Ýð*¨ð *ð *ð *ñ
ô 
ð 	
õ �hÑÔ€HÝ$ XÑ.Ô.€FØ€Mr"   c                 óØ   — | t           j        j        j        vrd S t           j        j        j        |          }|€d S |                     d¦  «        sd S |                     d¦  «        j        S )Nr£   )r   Ú
_custom_oprA   rS   rk   r{   rJ   )r%   r   s     r#   Úget_abstract_implr=  ´  sk   € Ø•uÔ'Ô,Ô<Ð<Ð<ØˆtÝÔ Ô%Ô5°hÔ?€IØÐØˆtØ×Ò˜zÑ*Ô*ð ØˆtØ×Ò˜zÑ*Ô*Ô/Ð/r"   Tc           	      ó@  — |                       d¦  «        \  }}|› |› �}t          j        |¦  «        }t          |¦  «         |rt          j        j        j        gng }t          j	        |d¦  «        }| 
                    ||¬¦  «         t          ||j        ¦  «        }	t          |||||	d¬¦  «        }
|
                     ¦   «          t          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   rA  rK   r>   rM   rN   r?  rO   rP   rQ   s              r#   Ú_custom_op_with_schemarB  ¿  s  € Ø�~Š~˜dÑ#Ô#�H€BˆØÐ"˜&Ð"Ð"€JÝ$Ô*¨:Ñ6Ô6€OÝ�OÑ$Ô$Ð$Ø6NÐV�EŒHŒLÔ1Ð2Ð2ÐTV€DÝ
Œ/˜"˜jÑ
)Ô
)€CØ‡J‚Jˆz €JÑ%Ô%Ð%Ý% b¨/Ô*>Ñ?Ô?€HÝ�c˜2˜°°hÐPTÐUÑUÔU€FØ
×0Ò0Ñ2Ô2Ð2å	„H×0Ò0Ø•)Ô#Õ$9½7¼=ÈÑ;PÔ;PÑQÔ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   r2  rÙ   r:  r=  rB  r!   r"   r#   ú<module>rM     s¨  ðà Ð Ð Ð Ð Ø Ð Ð Ð Ø €€€Ø 
€
€
€
Ø €€€Ø €€€Ø €€€à €€€Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø !Ð !Ð !Ð !Ð !Ð !ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð MÐ LÐ LÐ LÐ LÐ LÐ LÐ Lðð
 /Ð
.Ð
.€ð Øð ð  Ð ðð ð €ðð ð ð7ð 7˜ð 7¨C°$©Jð 7À&Ä/ð 7ð 7ð 7ð 7ð@ *,€��c˜:�oÔ&Ð +Ð +Ñ +ðYð Yð Yð Yð Yñ Yô Yð Yðx
 Ôðð ð ð ð ñ ô ñ Ôðð
 3ð °|ð ð ð ð ð

˜3ð 

 4ð 

ð 

ð 

ð 

ð
˜Nð 
¨tð 
ð 
ð 
ð 
ð"˜Sð  U¨3°¨8¤_ð ð ð ð ð"
 cð 
¨dð 
ð 
ð 
ð 
ð˜7Ô,ð °ð ð ð ð ð=9Øð=9Ø"(¤/ð=9à	ð=9ð =9ð =9ð =9ð@ V¤Zð °cð ¸dð ð ð ð ð<Eð Eð Eðð ð ð(
ð 
ð 
ð 
ð0ð 0ð 0ðð ð ð ð ð r"   