Ë
    L²jø7  ã                   ó®  — 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mZmZmZ d dl	m
Z
 ddlmZmZmZ ej                  Z e
d«      ddœd	ej                   d
edz  defd„«       Zdeej(                  z  dedededef
d„Zd„ Zedej0                  e   dee   dedededej8                  diZd„ Z e«       Zdej@                  defd„Z!dee"   dee   fd„Z#y)é    N)ÚGenericAlias)ÚdeviceÚdtypeÚTensorÚtypes)Ú
exposed_iné   )Ú_resolve_opaque_type_infoÚis_opaque_reference_typeÚis_opaque_typeztorch.library)Úop_nameÚprototype_functionr   Úreturnc               ó 
  ‡‡‡‡‡‡‡— d}| j                   ŠdŠt        j                  | «      Šˆfd„Šdt        fˆˆˆfd„Šdt        t
        t           t        z  df   dt        t        t        j                  df   t        f   fˆfd	„Šd
t
        t           t        z  dt        t        j                  t        f   fˆˆfd„Šg }t        «       }d}t        ‰j                  j                  «       «      D �]›  \  }\  }}	t        |	«      s ‰d«       |	j                  t        j                   j"                  k(  r|s|j%                  d«       d}|	j&                  t        j                   j(                  u r ‰d|› d�«        ‰|	j&                  «      \  }
}d}|
t*        vråt-        |
«      rt/        |
«      j0                  }nÍ|
t2        j4                  j6                  k(  r ‰d|› d�«       n£t9        |
d«      r_|
j:                  t        u rMt=        |
«      }d}|t*        v rd|› d�} ‰d|› d|	j&                  › d|› dt*        j?                  «       › d�	«       n8 ‰d|› d|	j&                  › dt*        j?                  «       › d�«       n	t*        |
   }|€tA        d|› �«      ‚t        |«      t        u r6||k7  rtC        d«      ‚|jE                  d«      rJd|› d |tG        d«      d › �}n5||v r1|jE                  d«      s ‰d|› d!�«       d|› d |tG        d«      d › �}|jI                  |«       |	jJ                  t        j                   j(                  u r|j%                  |› d"|› �«       �Œsd}|	jJ                  �%tM        |	jJ                  tN        tP        t        f«      rt        |	jJ                  «      }nÇtM        |	jJ                  t        t2        jR                  f«      rd#|	jJ                  › d#�}nŒtM        |	jJ                  t2        jT                  «      rFt        |	jJ                  «      }d$}|jE                  |«      stA        d%|›d&�«      ‚|tG        |«      d }n" ‰d|› d't        |	jJ                  «      › d(�«       |j%                  |› d"|› d)|› �«       �Œž ||k7  r't        |«      |z
  }tG        |«      d*kD  r ‰|› d+�«        ‰‰jV                  «      \  }}tY        |‰«      }|�|› d,d-j[                  |«      › d.|› �S d,d-j[                  |«      › d.|› �S )/aJ  Parses the schema of a given function with type hints. The schema is inferred from the
    function's type hints, and can be used to define a new operator.

    We make the following assumptions:

    * None of the outputs alias any of the inputs or each other.
    * | String type annotations "device, dtype, Tensor, types" without library specification are
      | assumed to be torch.*. Similarly, string type annotations "Optional, List, Sequence, Union"
      | without library specification are assumed to be typing.*.
    * | Only the args listed in ``mutates_args`` are being mutated. If ``mutates_args`` is "unknown",
      | it assumes that all inputs to the operator are being mutates.

    Callers (e.g. the custom ops API) are responsible for checking these assumptions.

    Args:
        prototype_function: The function from which to infer a schema for from its type annotations.
        op_name (Optional[str]): The name of the operator in the schema. If ``name`` is None, then the
            name is not included in the inferred schema. Note that the input schema to
            ``torch.library.Library.define`` requires a operator name.
        mutates_args ("unknown" | Iterable[str]): The arguments that are mutated in the function.

    Returns:
        The inferred schema.

    Example:
        >>> def foo_impl(x: torch.Tensor) -> torch.Tensor:
        >>>     return x.sin()
        >>>
        >>> infer_schema(foo_impl, op_name="foo", mutates_args={})
        foo(Tensor x) -> Tensor
        >>>
        >>> infer_schema(foo_impl, mutates_args={})
        (Tensor x) -> Tensor
    ÚunknownNc                 ó(   •— t        d| › d‰› d�«      ‚)Nzinfer_schema(func): z Got func with signature ú))Ú
ValueError)ÚwhatÚsigs    €úZ/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torch/_library/infer_schema.pyÚerror_fnzinfer_schema.<locals>.error_fnI   s    ø€ ÜÐ/°¨vÐ5NÈsÈeÐSTÐUÓVÐVó    Úannotation_typec                 óV   •— 	 t        | ‰‰«      S # t        $ r  ‰d| › d�«       Y y w xY w)NzUnsupported type annotation z. It is not a type.)ÚevalÚ	Exception)r   r   Ú
pf_globalsÚ	pf_localss    €€€r   Úconvert_type_stringz)infer_schema.<locals>.convert_type_stringL   s<   ø€ ð	Ü˜¨°YÓ?Ð?øÜò 	ÙØ.¨Ð.?Ð?RÐSöð	ús   ƒ �(§(Útys.r   c                 ó‚   •— g }d}| D ]#  } ‰|«      \  }}|j                  |«       ||z  }Œ% |rt        |«      dfS | dfS )NFT)ÚappendÚtuple)r!   ÚresÚchangedÚtyÚ
ty_changedÚunstringify_types        €r   Úunstringify_typesz'infer_schema.<locals>.unstringify_typesT   s_   ø€ ð ˆØˆØò 	"ˆBÙ-¨bÓ1‰NˆB�
Ø�J‰J�rŒNØ�zÑ!‰Gð	"ñ Ü˜“:˜tÐ#Ð#à˜�:Ðr   r'   c                 óÊ   •— t        | t        «      r
 ‰| «      dfS t        j                  | «      x}r. ‰t        j                  | «      «      \  }}|rt        ||«      dfS | dfS )NTF)Ú
isinstanceÚstrÚtypingÚ
get_originÚget_argsr   )r'   ÚoriginÚargsÚargs_changedr    r*   s       €€r   r)   z&infer_schema.<locals>.unstringify_typeb   sl   ø€ ô �bœ#ÔÙ& rÓ*¨DÐ0Ð0Ü×(Ñ(¨Ó,Ð,ˆVÐ,Ù!2´6·?±?À2Ó3FÓ!GÑˆD�,ÙÜ# F¨DÓ1°4Ð7Ð7à�5ˆyÐr   Fz>We do not support positional-only args, varargs, or varkwargs.Ú*Tz
Parameter z must have a type annotation.zª's type cannot be inferred from the schema as it is a ScriptObject. Please manually specify the schema using the `schema=` kwarg with the actual type of the ScriptObject.Ú
__origin__z

zFor example, z.

z has unsupported type z]. We do not support Tuple inputs in schema. As a workaround, please try to use List instead. zThe valid types are: ú.ú. The valid types are: zschema_type is None for param zomutates_args must either be a sequence of the names of the arguments that are mutated or the string 'unknown'. r   zTensor(az!)zM is in mutable_args but only Tensors or collections of Tensors can be mutatedú ú"ztorch.zdtype repr z must start with 'torch.'z' has an unsupported default value type z;. Please file an issue on GitHub so we can prioritize this.ú=r   z» in mutates_args were not found in the custom op's signature. mutates_args should contain the names of all args that the custom op mutates, or just the string 'unknown' if you don't know.ú(ú, z) -> ).Ú__globals__ÚinspectÚ	signaturer-   r$   ÚtypeÚobjectr.   ÚAnyÚboolÚsetÚ	enumerateÚ
parametersÚitemsÚsupported_paramÚkindÚ	ParameterÚKEYWORD_ONLYr#   Ú
annotationÚemptyÚSUPPORTED_PARAM_TYPESr   r
   Ú
class_nameÚtorchÚ_CÚScriptObjectÚhasattrr5   Útuple_to_listÚkeysÚAssertionErrorr   Ú
startswithÚlenÚaddÚdefaultr,   ÚintÚfloatr   r   Úreturn_annotationÚparse_returnÚjoin)r   Úmutates_argsr   ÚUNKNOWN_MUTATESÚparamsÚ	seen_argsÚsaw_kwarg_only_argÚidxÚnameÚparamr   Ú_Úschema_typeÚ	list_typeÚexample_type_strÚdefault_reprÚ
dtype_reprÚ	torch_dotÚmutates_args_not_seenr]   Úretr    r   r   r   r   r)   r*   s                        @@@@@@@r   Úinfer_schemarq      s8  þ€ ðT  €OØ#×/Ñ/€JØ€Iô ×
Ñ
Ð.Ó
/€CôWð¬S÷ ðÜ”4œ‘<¤#Ñ% sÐ*Ñ+ðä	Œu”V—Z‘Z �_Ñ%¤tÐ+Ñ	,õðœT¤&™\¬CÑ/ð ´E¼&¿*¹*ÄdÐ:JÑ4Kö ð €FÜ“€IØÐÜ'¨¯©×(<Ñ(<Ó(>Ó?ó [BÑˆ‰]ˆd�EÜ˜uÔ%ÙÐUÔVà�:‰:œ×*Ñ*×7Ñ7Ò7á%Ø—‘˜cÔ"Ø%)Ð"à×Ñœw×0Ñ0×6Ñ6Ñ6Ù�z $ Ð'DÐEÔFñ .¨e×.>Ñ.>Ó?Ñˆ˜àˆØÔ"7Ñ7Ü˜oÔ.Ü7¸ÓH×SÑS‘Ø ¤E§H¡H×$9Ñ$9Ò9ÙØ   ð 'Zð Zõô ˜¨Ô6Ø#×.Ñ.´%Ñ7ä)¨/Ó:�	Ø#)Ð àÔ 5Ñ5Ø)6°y°kÀÐ'GÐ$ÙØ   Ð&<¸U×=MÑ=MÐ<Nð Orà'Ð(Ø+Ô,A×,FÑ,FÓ,HÐ+IÈðLõñ Ø   Ð&<¸U×=MÑ=MÐ<Nð O,Ü,A×,FÑ,FÓ,HÐ+IÈðLõô
 0°Ñ@ˆKàÐÜ Ð#AÀ$ÀÐ!HÓIÐIä�Ó¤Ñ$Ø˜Ò.Ü ðOóð ð ×%Ñ% hÔ/Ø (¨¨¨R°¼CÀ»M¸OÐ0LÐ/MÐN‘Ø�\Ñ!Ø×)Ñ)¨(Ô3ÙØ   Ð&sÐtôð % S E¨¨K¼¸H»¸Ð,HÐ+IÐJˆKØ�‰�dÔØ�=‰=œG×-Ñ-×3Ñ3Ñ3à�M‰M˜[˜M¨¨4¨&Ð1Ö2àˆLØ�}‰}Ð$¬
°5·=±=Ä3ÌÌtÐBTÔ(UÜ" 5§=¡=Ó1‘Ü˜EŸM™M¬C´·±Ð+>Ô?Ø!" 5§=¡= /°Ð3‘Ü˜EŸM™M¬5¯;©;Ô7Ü  §¡Ó/�
Ø$�	Ø!×,Ñ,¨YÔ7Ü(Ø% j ^Ð3LÐMóð ð  *¬#¨i«.Ð*:Ð;‘áØ   Ð&MÌdÐSX×S`ÑS`ÓNaÐMbð cPð Qôð
 �M‰M˜[˜M¨¨4¨&°°,°Ð@ÖAðw[Bðx �Ò&Ü # LÓ 1°IÑ =ÐÜÐ$Ó%¨Ò)ÙØ(Ð)ð *Uð Vôñ ,¨C×,AÑ,AÓBÑÐ�qÜ
Ð(¨(Ó
3€CØÐØ�˜!˜DŸI™I fÓ-Ð.¨e°C°5Ð9Ð9Øˆt�y‰y˜Ó Ð!  s eÐ,Ð,r   Ú	base_typeÚcpp_typeÚ	list_baseÚoptional_base_listÚoptional_list_basec                 ód  ‡— | ‰ft         j                  |    ‰› d�fg}dt        t         j                  z  fd„}|r |j	                  ˆfd„ || «      D «       «       |r1|j	                  ˆfd„ |t         j                  |    «      D «       «       |r |j	                  ˆfd„ || «      D «       «       |S )Nú?Útypc                 ó¶   — t         j                  |    t         j                  |    t        t        j
                  j                  | f«      t        t        | f«      fS ©N)r.   ÚSequenceÚListr   ÚcollectionsÚabcÚlist)ry   s    r   Úderived_seq_typesz(derived_types.<locals>.derived_seq_typesë   sF   € ä�O‰O˜CÑ Ü�K‰K˜ÑÜœŸ™×1Ñ1°C°6Ó:Üœ ˜vÓ&ð	
ð 	
r   c              3   ó,   •K  — | ]  }|‰› d �f–— Œ y­w)z[]N© ©Ú.0Úseq_typrs   s     €r   ú	<genexpr>z derived_types.<locals>.<genexpr>ô   s!   øè ø€ ò 
Ø+2ˆW˜˜
 "�oÔ&ñ
ùó   ƒc              3   ó,   •K  — | ]  }|‰› d �f–— Œ y­w)z?[]Nrƒ   r„   s     €r   r‡   z derived_types.<locals>.<genexpr>ø   s'   øè ø€ ò 
ð ð ˜˜
 #Ð&Ô'ñ
ùrˆ   c              3   óN   •K  — | ]  }t         j                  |   ‰› d �f–— Œ y­w)z[]?N)r.   ÚOptionalr„   s     €r   r‡   z derived_types.<locals>.<genexpr>þ   s.   øè ø€ ò 
àô �_‰_˜WÑ%¨(¨°3Ð'7Ô8ñ
ùs   ƒ"%)r.   r‹   r@   Ú_SpecialFormÚextend)rr   rs   rt   ru   rv   Úresultr�   s    `     r   Úderived_typesr�   Þ   s¾   ø€ ð 
�HÐä	�‰˜Ñ	#¨ z° ^Ð4ðK€Fð
œt¤f×&9Ñ&9Ñ9ó 
ñ Ø�‰ó 
Ù6GÈ	Ó6Rô
ô 	
ñ Ø�‰ó 
ñ -¬V¯_©_¸YÑ-GÓHô
ô 	
ñ
 Ø�‰ó 
á,¨YÓ7ô
ô 	
ð €Mr   c                  ó´  — t         ddddft        ddddft        ddddft        ddddft        ddddft
        j                  ddddft        d	dddft        d
dddfg} t        j                  j                  «       r4ddlm} | j                  t        j                   t"        |«      ddddf«       g }| D ]  }|j%                  t'        |Ž «       Œ t)        |«      S )Nr   TFÚSymIntr\   rC   r-   ÚScalarÚ
ScalarTypeÚDevicer   )Ú	GroupName)r   r[   r\   rC   r-   r   ÚNumberr   r   rP   ÚdistributedÚis_availableÚ"torch.distributed.distributed_c10dr•   r#   r.   Úcastr@   r�   r�   Údict)Údatar•   rŽ   Úlines       r   Úget_supported_param_typesrž     sè   € ô 
�˜4  uÐ-Ü	ˆh˜˜e TÐ*Ü	�˜˜u dÐ+Ü	ˆv�t˜U DÐ)Ü	ˆe�U˜E 5Ð)Ü	�‰�x  u¨eÐ4Ü	�˜e U¨EÐ2Ü	�˜5 %¨Ð/ð
L€Dô ×Ñ×%Ñ%Ô'Ý@à�‰”V—[‘[¤ yÓ1°5¸%ÀÈÐNÔOà€FØò ,ˆØ�‰”m TÐ*Õ+ð,ä�‹<Ðr   r   zTensor[]r‘   r\   rC   r’   c                 ó  ‡— | €y| t         j                  j                  u r |d«       t        j                  | «      }|t
        urD| t        vr3t        | «      rt        | «      j                  S  |d| › dt        › d�«       t        |    S t        j                  | «      }|D ]*  }|t        vsŒt        |«      rŒ |d| › dt        › d�«       Œ, d„ Šdj                  ˆfd„|D «       «      }t        |«      d	k(  rd
|z   dz   }d
|z   dz   S )Nz()z7No return type annotation was provided. Please add one.zReturn has unsupported type r7   r6   c                 ó^   — t         j                  | «      x}r|S t        | «      j                  S r{   )ÚSUPPORTED_RETURN_TYPESÚgetr
   rO   )Úargr'   s     r   Ú_return_type_strz&parse_return.<locals>._return_type_strC  s.   € Ü'×+Ñ+¨CÓ0Ð0ˆ2Ð0ØˆIÜ(¨Ó-×8Ñ8Ð8r   r<   c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wr{   rƒ   )r…   r£   r¤   s     €r   r‡   zparse_return.<locals>.<genexpr>H  s   øè ø€ Ò@°CÑ*¨3×/Ñ@ùs   ƒr	   r;   r   )r>   rJ   rM   r.   r/   r$   r¡   r   r
   rO   r0   r_   rX   )rL   r   r1   r2   r£   Ú	output_tyr¤   s         @r   r^   r^   (  s'  ø€ ØÐØà”W×&Ñ&×,Ñ,Ñ,ÙÐJÔKä×Ñ˜zÓ*€FØ”UÑØÔ3Ñ3Ü'¨
Ô3Ü0°Ó<×GÑGÐGÙØ.¨z¨lð ;(Ü(>Ð'?¸qðBôô
 & jÑ1Ð1ä�?‰?˜:Ó&€DØò ˆØÔ,Ò,Ô5MÈcÕ5RÙØ.¨z¨lð ;(Ü(>Ð'?¸qðBõðò9ð
 —	‘	Ó@¸4Ô@Ó@€Iô ˆ4ƒy�A‚~Ø˜)‘O cÑ)ˆ	Ø�‰?˜SÑ Ð r   rg   c                 ó‚   — | j                   t        j                  j                  t        j                  j                  fv S r{   )rI   r>   rJ   ÚPOSITIONAL_OR_KEYWORDrK   )rg   s    r   rH   rH   S  s6   € Ø�:‰:Ü×Ñ×/Ñ/Ü×Ñ×&Ñ&ðð ð r   Ú
tuple_typec                 ó.  — t        | dd«      }| t        j                  u s| t        u s|dk(  s|€t        S t        |«      dk(  rt        |d      S t        |«      dk(  r|d   t        u rt        |d      S t        t        j                  t        |«            S )z}
    Convert `tuple_type` into a list type with the same type arguments. Assumes that `tuple_type` is typing.Tuple type.
    Ú__args__Nrƒ   r	   r   é   )Úgetattrr.   ÚTupler$   r€   rX   ÚEllipsisÚUnion)r©   Ú	type_argss     r   rT   rT   Z  s–   € ô ˜
 J°Ó5€Ið 	”f—l‘lÑ"ØœÑØ˜Š?ØÐô ˆÜ	ˆY‹˜1Ò	ä�I˜a‘LÑ!Ð!Ü	ˆY‹˜1Ò	 ¨1¡´Ñ!9Ü�I˜a‘LÑ!Ð!ä”F—L‘L¤ yÓ!1Ñ2Ñ3Ð3r   )$r~   r>   r.   r   r   rP   r   r   r   Útorch.utils._exposed_inr   Úopaque_objectr
   r   r   Ú_TestTensorÚCallabler-   rq   r@   rŒ   rC   r�   rž   r}   r€   r[   r\   r–   r¡   r^   rN   rJ   rH   r$   rT   rƒ   r   r   ú<module>r¶      sA  ðã Û Û Ý ã ß .Ó .Ý .÷ñ ð �l‰l€ñ ˆOÓð òC-ØŸ™ðC-ð
 �4‰ZðC-ð 	òC-ó ðC-ðL$Ø�f×)Ñ)Ñ)ð$àð$ð ð$ð ð	$ð
 ó$òNð2 ˆHØ
‡K�K�Ñ˜Øˆ�L�*ØˆØ	ˆ7Øˆ&Ø	‡L�L�(ðÐ ò%!ñP 2Ó3Ð ð˜7×,Ñ,ð °ó ð4˜d 5™kð 4¨d°4©jô 4r   