ó
    Eñi{¾  ã                   óˆ  • % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	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  S SKJrJrJr  S SKrSˆS jrS‰S jrS	 rS
 rS r S r!S r"S r# SŠS jr$ SŠS jr%/ r&\'S   \(S'   S r)S r*S r+S r,S r-\-r.S r/S r0S r1S r2S r3S r4S r5S r6S  r7S! r8S" r9S# r:S$ r;S% r<S& r=S' r> " S( S)\?5      r@ " S* S+5      rAS, rBS- rCS. rDS/ rES0 rFS1\G4S2 jrH  S‹S3\S4\IS5\IS1\G4S6 jjrJS7 rKS8 rL " S9 S:5      rMS; rN\(       a  \" S<\OS=9S1\I4S> j5       rPOS1\I4S? jrPS@ rQ\R¤                  " SA5      SB\?4SC j5       rSSD\?S1\T4SE jrU " SF SG5      rV\R®                  " \X5      rY\" SH5      rZ " SI SJ\\Z   5      r[SK\?S1\S-  4SL jr\SMSNSOSPSQSRSRSRSSSTSTSU.r]0 SVSW_SXSY_SZS[_S\S]_S^S__S`Sa_SbSc_SdSe_SfSg_ShSi_SjSk_SlSm_SnSo_SpSq_SrS__SsSt_SuSm_r^SvSSw\GSx\GS1S4Sy jr_ " Sz S{\5      r` " S| S}\5      ra " S~ S\5      rb " S€ S�\5      rc " S‚ Sƒ\5      rdS„\'\`   S1\G4S… jreS†\?\d-  S1\d4S‡ jrfg)Œé    N)Údefaultdict)ÚCallable)Ú
ModuleType)ÚAnyÚcastÚGenericÚTYPE_CHECKINGÚ	TypedDict)Ú
deprecatedÚNotRequiredÚ	ParamSpecc                 óô  • [        SX#5      nUc&  U R                  S-   U R                  R                  -   $ [	        U[
        5      (       a  [        U5      nU[        U 5      L a  U $ U R                  (       aÂ  UR                  (       d  [        S5      eUR                  R                  SS5      nUS-   UR                  -   n[        R                  R                  U 5      R                  XR5      nUS-   n[        R                  R                  U 5      R                  Xr5      nU" X†U R                  5       5      $ UR                  (       a  [        S5      eU" U R                  5       5      R!                  X5      $ )ay  Returns the type if `dtype` is not provided, else casts this object to
the specified type.

If this is already of the correct type, no copy is performed and the
original object is returned.

Args:
    dtype (type or string): The desired type
    non_blocking (bool): If ``True``, and the source is in pinned memory
        and destination is on the GPU or vice versa, the copy is performed
        asynchronously with respect to the host. Otherwise, the argument
        has no effect.
    **kwargs: For compatibility, may contain the key ``async`` in place of
        the ``non_blocking`` argument. The ``async`` arg is deprecated.
ÚtypeÚ.z)Cannot cast sparse tensor to dense tensorz.sparseÚ z.LongTensorz)Cannot cast dense tensor to sparse tensor)Ú_get_async_or_non_blockingÚ
__module__Ú	__class__Ú__name__Ú
isinstanceÚstrÚ_import_dotted_namer   Ú	is_sparseÚRuntimeErrorÚreplaceÚtorchÚTensorÚ_valuesÚ_indicesÚsizeÚcopy_)	ÚselfÚdtypeÚnon_blockingÚkwargsÚnew_module_nameÚnew_values_type_nameÚ
new_valuesÚnew_indices_type_nameÚnew_indicess	            ÚI/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_utils.pyÚ_typer,      s2  € ô  .¨f°lÓK€LØ�}Ø�‰ Ñ$ t§~¡~×'>Ñ'>Ñ>Ð>ä�%œ×ÑÜ# EÓ*ˆØ”�T“
ÒØˆØ‡~‡~Ø��ÜÐJÓKÐKØ×*Ñ*×2Ñ2°9¸bÓAˆØ.°Ñ4°u·~±~ÑEÐÜ—\‘\×)Ñ)¨$Ó/×4Ñ4Ð5IÓXˆ
Ø /°-Ñ ?ÐÜ—l‘l×+Ñ+¨DÓ1×6Ñ6Ø!ó
ˆñ �[¨d¯i©i«kÓ:Ð:Ø‡‡ÜÐFÓGÐGÙ�—‘“Ó×#Ñ# DÓ7Ð7ó    c                 óä  • U R                   U:X  a  U $ UR                  S:X  a“  U=(       a7    U R                   R                  S[        R                  R	                  5       4;   n[        R
                  " U R                  5       [        R                  XS9R                  5       nUR                  X5        U$ [        [        UR                  S5      nUc&  [        UR                  R                  5        S35      eUR                  U5         U R                  (       aÍ  [        US5      (       a¼  [        UR                  U R                   R"                  5      n[        [        R$                  R'                  U 5      UR                  5      " X5      n[        [        R$                  R)                  U 5      UR                  5      " X5      nU" XxU R+                  5       5      sSSS5        $ U R                  (       a'  [        SUR                  R                  5        S35      e[        R,                  " U R+                  5       US	9nUR                  X5        UsSSS5        $ ! , (       d  f       g= f)
aŠ  Returns a copy of this object in device memory.

If this object is already on the correct device, then no copy is performed
and the original object is returned.

Args:
    device (int): The destination device.
    non_blocking (bool): If ``True`` and the source is in pinned memory,
        the copy will be asynchronous with respect to the host. Otherwise,
        the argument has no effect.
ÚcpuÚcuda)r#   ÚdeviceÚ
pin_memoryNz device module is not loadedÚsparsez$sparse storage is not supported for z tensors)r1   )r1   r   r   Ú_CÚ_get_privateuse1_backend_nameÚemptyÚnbytesÚuint8Úuntyped_storager!   ÚgetattrÚAssertionErrorÚupperr   Úhasattrr3   r   r   r   r   r   r    ÚUntypedStorage)	r"   r1   r$   r2   r9   Údevice_moduleÚnew_typeÚindicesÚvaluess	            r+   Ú_torC   >   sÝ  € ð ‡{�{�fÓØˆà‡{�{�eÓØ!÷ 
 d§k¡k×&6Ñ&6ØÜ�H‰H×2Ñ2Ó4ð;
ñ '
ˆ
ô  Ÿ+š+Ø�K‰K‹M¤§¡°Vñ
ç
‰/Ó
ð 	ð 	×Ñ˜dÔ1ØÐäœE 6§;¡;°Ó5€MØÑÜ §¡× 1Ñ 1Ó 3Ð4Ð4PÐQÓRÐRØ	×	Ñ	˜fÕ	%Ø�>�>œg m°X×>Ñ>Ü˜}×3Ñ3°T·^±^×5LÑ5LÓMˆHÜœeŸl™l×3Ñ3°DÓ9¸6¿;¹;ÔGØóˆGô œUŸ\™\×1Ñ1°$Ó7¸¿¹ÔEØóˆFñ ˜G¨T¯Y©Y«[Ó9÷ 
&Ñ	%ð �~�~Ü$Ø:¸6¿;¹;×;LÑ;LÓ;NÐ:OÈxÐXóð ô $×2Ò2°4·9±9³;ÀvÑNˆOØ×!Ñ! $Ô5Ø"÷# 
&×	%×	%ús   ÄCI!Ç*A-I!É!
I/c                 óø   • U(       d  U$ [        U5      S:w  d  SU;  aC  Sn[        UR                  5       5      R                  5       n[	        UR                  X5      5      e[        R                  " SSS9  US   $ )zêReturn the non-blocking flag given the function name and kwargs.

Args:
    function_name (str): the name of the function being used.
    non_blocking (bool): the default value.
    **kwargs (dict): the kwargs passed to the function.
é   Úasyncz,{}() got an unexpected keyword argument '{}'z)'async' is deprecated; use 'non_blocking'é   ©Ú
stacklevel)ÚlenÚlistÚkeysÚpopÚ	TypeErrorÚformatÚwarningsÚwarn)Úfunction_namer$   r%   ÚmessageÚarguments        r+   r   r   o   sk   € ö ØÐÜ
ˆ6ƒ{�aÓ˜7¨&Ó0Ø@ˆÜ˜Ÿ™›Ó&×*Ñ*Ó,ˆÜ˜Ÿ™ }Ó?Ó@Ð@Ü‡M‚MÐ=È!ÒLØ�'‰?Ðr-   c                 óf  • [         R                  R                  R                  nUc  U $ [	        U[
        5      (       a  UR                  X 5      $ [	        U[        [         R                  45      (       a  U$ [        U5      (       d!  [        S[        U5      R                   35      e[        S5      e)zsReturn the map_location location.

Used for rebuild functions where the tensor device is distinct from the storage
z$expected callable map_location, got zgCallable map_location not supported with _rebuild_wrapper_subclass or _rebuild_device_tensor_from_numpy)r   ÚserializationÚ_serialization_tlsÚmap_locationr   ÚdictÚgetr   r1   Úcallabler;   r   r   r   )r1   rX   s     r+   Ú_get_restore_locationr\   �   s¢   € ô ×&Ñ&×9Ñ9×FÑF€LØÑØˆä�l¤D×)Ñ)Ø×#Ñ# FÓ3Ð3Ü˜¤s¬E¯L©LÐ&9×:Ñ:ØÐä˜L×)Ñ)Ü$Ø:¼4ÀÓ;M×;VÑ;VÐ:WÐXóð ô ð7óð r-   c                 ó¤   • [         R                  " SU R                  U R                  R                  S9nUR                  U R                  XU5      $ )N©r   ©r#   r1   )r   r6   r#   Ú_untyped_storager1   Úset_)ÚstorageÚstorage_offsetr    ÚstrideÚts        r+   Ú_rebuild_tensorrf   Á   s=   € ä�Š�D §¡°g×6NÑ6N×6UÑ6UÑV€AØ�6‰6�'×*Ñ*¨NÀ&ÓIÐIr-   c                 óÀ   • [        U [        R                  5      (       d!  [        S[	        U 5      R
                   35      e[        R                  R                  U 5      $ )Núexpected torch.Tensor, got )r   r   r   r;   r   r   r4   Ú_get_tensor_metadata©Útensors    r+   Úget_tensor_metadatarl   Ç   sH   € ô �fœeŸl™l×+Ñ+ÜÐ:¼4À»<×;PÑ;PÐ:QÐRÓSÐSÜ�8‰8×(Ñ(¨Ó0Ð0r-   c                 ó.  • [        U[        5      (       d!  [        S[        U5      R                   35      e[        U [
        R                  5      (       d!  [        S[        U 5      R                   35      e[
        R                  R                  X5        g )Nzexpected dict, got rh   )	r   rY   r;   r   r   r   r   r4   Ú_set_tensor_metadata)rk   Úmetadatas     r+   Úset_tensor_metadatarp   Ð   sn   € ä�h¤×%Ñ%ÜÐ2´4¸³>×3JÑ3JÐ2KÐLÓMÐMÜ�fœeŸl™l×+Ñ+ÜÐ:¼4À»<×;PÑ;PÐ:QÐRÓSÐSÜ	‡H�H×!Ñ! &Õ3r-   c                 ób  • [         R                  R                  S 5      bŽ  U R                  5       R                  bs  [        U R                  5       R                  5      n[        U[         R                  5      (       d  [         R                  " U5      n[         R                  " U5      U l        U $ ©N)	r   Ú_guardsÚdetect_fake_moder9   Ú_fake_devicer\   r   r1   Úfake_device)rk   r1   s     r+   Ú_restore_device_fake_moderw   Ù   sz   € Ü‡}�}×%Ñ% dÓ+Ñ7Ø×!Ñ!Ó#×0Ñ0Ñ<Ü*¨6×+AÑ+AÓ+C×+PÑ+PÓQˆFÜ˜f¤e§l¡l×3Ñ3ÜŸš fÓ-�Ü!&§¢¨fÓ!5ˆFÔØ€Mr-   c                 óp   • [        XX#5      nXGl        U(       a  [        Xv5        XWl        [	        U5      nU$ rr   )rf   Úrequires_gradrp   Ú_backward_hooksrw   )rb   rc   r    rd   ry   Úbackward_hooksro   rk   s           r+   Ú_rebuild_tensor_v2r|   ã   s8   € ô ˜W°dÓC€FØ(ÔÞÜ˜FÔ-ð
 ,Ôä& vÓ.€FØ€Mr-   c                 óÜ   • [         R                  " SUU R                  R                  US9nUR	                  U R                  XU5        U(       a  [        X‡5        XXl        [        U5      nU$ )Nr^   ©r#   r1   ry   )r   r6   r`   r1   ra   rp   rz   rw   )	rb   rc   r    rd   ry   r{   r#   ro   re   s	            r+   Ú_rebuild_tensor_v3r   ú   sb   € ô 	�ŠØØØ×'Ñ'×.Ñ.Ø#ñ		€Að ‡F�Fˆ7×#Ñ# ^¸6ÔBÞÜ˜AÔ(Ø&ÔÜ! !Ó$€AØ€Hr-   ztorch.TensorÚ_sparse_tensors_to_validatec            
      ó
  • [         R                  R                  5       R                  5       (       d  [        R                  5         g  [         GH„  n U R                  [         R                  L aR  [         R                  " U R                  5       U R                  5       U R                  5       U R                  5       SS9  Ms  U R                  [         R                  [         R                  [         R                  [         R                   1;   a¯  U R                  [         R                  [         R                  1;   a   U R#                  5       U R%                  5       p!OU R'                  5       U R)                  5       p![         R*                  " UUU R-                  5       U R                  5       U R                  SS9  GMn  [/        SU R                   S35      e   [        R                  5         g ! [        R                  5         f = f)NF)Úcheck_pinningz,_validate_loaded_sparse_tensors for layout `Ú`)r   r3   Úcheck_sparse_tensor_invariantsÚ
is_enabledr€   ÚclearÚlayoutÚ
sparse_cooÚ _validate_sparse_coo_tensor_argsr   r   r    Úis_coalescedÚ
sparse_csrÚ
sparse_cscÚ
sparse_bsrÚ
sparse_bscÚcrow_indicesÚcol_indicesÚccol_indicesÚrow_indicesÚ'_validate_sparse_compressed_tensor_argsrB   ÚNotImplementedError)re   Úcompressed_indicesÚplain_indicess      r+   Ú_validate_loaded_sparse_tensorsr—     s‚  € Ü�<‰<×6Ñ6Ó8×CÑC×EÑEô
 	$×)Ñ)Ô+Øð-,÷ -Ð,ˆAØ�x‰xœ5×+Ñ+Ò+Ü×6Ò6Ø—J‘J“LØ—I‘I“KØ—F‘F“HØ—N‘NÓ$Ø"'ôð —‘Ü× Ñ Ü× Ñ Ü× Ñ Ü× Ñ ð	ó ð —8‘8¤× 0Ñ 0´%×2BÑ2BÐCÓCàŸ™Ó(ØŸ™›ñ )6ð Ÿ™Ó(ØŸ™›ð )6ô ×=Ò=Ø&Ø!Ø—H‘H“JØ—F‘F“HØ—H‘HØ"'õô *ØBÀ1Ç8Á8À*ÈAÐNóð ñI -ôR 	$×)Ñ)Õ+øÔ#×)Ñ)Õ+ús   ÁFG, Ç,Hc           	      óÈ  • U [         R                  :X  aJ  [        U5      S:X  a  Uu  p#nSnOUu  p#pE[         R                  " X#USUS9n[        R                  U5        U$ U [         R                  [         R                  [         R                  [         R                  1;   a5  Uu  pxp4[         R                  " UUUUU SS9n[        R                  U5        U$ [        SU  35      e)zÂ
Rebuilds a sparse tensor from its sparse storage representation.

Args:
    layout (str): The sparse storage layout of the tensor.
    data (tuple): The tensor's sparse storage representation.
é   NF)Úcheck_invariantsrŠ   )r‡   rš   z$rebuilding sparse tensor for layout )r   rˆ   rJ   Úsparse_coo_tensorr€   Úappendr‹   rŒ   r�   rŽ   Úsparse_compressed_tensorr”   )	r‡   ÚdatarA   rB   r    rŠ   Úresultr•   r–   s	            r+   Ú_rebuild_sparse_tensorr    W  sì   € ð ”×!Ñ!Ó!Üˆt‹9˜‹>à$(Ñ!ˆG˜TØ‰Là26Ñ/ˆG˜TÜ×(Ò(Ø˜T°EÈñ
ˆô 	$×*Ñ*¨6Ô2Øˆà	Ü×ÑÜ×ÑÜ×ÑÜ×Ñð	ó 
ð ;?Ñ7Ð¨6Ü×/Ò/ØØØØØØ"ñ
ˆô 	$×*Ñ*¨6Ô2Øˆä
Ð DÀVÀHÐMÓ
NÐNr-   c                 ó0   • [         R                  " XX#5      $ rr   )r   Ú_nested_view_from_buffer)ÚbufferÚsizesÚstridesÚstorage_offsetss       r+   Ú_rebuild_nested_tensorr§   �  s   € Ü×)Ò)¨&¸ÓRÐRr-   c                 óF   • [        U5      nU R                  XS9nX4l        U$ ©Nr_   )r\   Útory   ©rž   r#   r1   ry   rk   s        r+   Ú&_rebuild_device_tensor_from_cpu_tensorr¬   …  s'   € Ü" 6Ó*€FØ�W‰W˜5ˆWÐ0€FØ(ÔØ€Mr-   c                 ón   • [        U5      n[        R                  " U 5      R                  XS9nX4l        U$ r©   )r\   r   Ú
from_numpyrª   ry   r«   s        r+   Ú!_rebuild_device_tensor_from_numpyr¯   Œ  s5   € Ü" 6Ó*€FÜ×Ò˜dÓ#×&Ñ&¨UÐ&ÐB€FØ(ÔØ€Mr-   c                 ó0   • [         R                  " XU SUS9$ )NÚmetar~   )r   Úempty_strided)r#   r    rd   ry   s       r+   Ú_rebuild_meta_tensor_no_storager³   —  s   € Ü×ÒØ˜E¨&Àñð r-   c                 ó`   • [        U5      n[        R                  R                  U UUUUUUUS9$ )N)r¥   r#   rc   r‡   r1   ry   )r\   r   r   Ú_make_wrapper_subclass)Úclsr#   r    rd   rc   r‡   r1   ry   s           r+   Ú_rebuild_wrapper_subclassr·   �  sB   € ô # 6Ó*€FÜ�<‰<×.Ñ.ØØØØØ%ØØØ#ð /ð 	ð 	r-   c           	      óˆ  • US   nU[         R                  :X  a3  Uu  p‰n
[         R                  " UU	U
U R                  U R                  S9nGOWU[         R
                  [         R                  4;   Ga$  Uu  pŒpÞ[        U5      [        L aß  [        U5      [        L aÍ  U[         R
                  :X  a]  [         R                  " U[         R                  U R                  S9n[         R                  " U[         R                  U R                  S9nO\[         R                  " U[         R                  U R                  S9n[         R                  " U[         R                  U R                  S9n[         R                  " UUUUU R                  U R                  S9nO[        SU 35      eUR                  XX#5        X[l        Xkl        U$ )Nr   )ÚscaleÚ
zero_pointr#   r1   r_   )ÚscalesÚzero_pointsÚaxisr#   r1   z0Can't deserialize quantized tensor with qscheme )r   Úper_tensor_affineÚ_empty_affine_quantizedr#   r1   Úper_channel_affineÚ per_channel_affine_float_qparamsr   rK   rk   ÚdoubleÚlongÚfloatÚ#_empty_per_channel_affine_quantizedr   ra   ry   rz   )rb   rc   r    rd   Úquantizer_paramsry   r{   ÚqschemeÚ_r¹   rº   rk   r»   r¼   r½   s                  r+   Ú_rebuild_qtensorrÉ   ¶  sj  € ð ˜qÑ!€GØ”%×)Ñ)Ó)Ø/Ñˆ�*Ü×.Ò.ØØØ!Ø—-‘-Ø—>‘>ñ
Šð 
”U×-Ñ-¬u×/UÑ/UÐVÔ	VØ'7Ñ$ˆ�;Ü�‹<œ4Ò¤D¨Ó$5¼Ò$=Øœ%×2Ñ2Ó2ÜŸš f´E·L±LÈÏÉÑX�Ü#ŸlšlØ¤u§z¡z¸'¿.¹.ñ‘ô Ÿš f´E·K±KÈÏÉÑW�Ü#ŸlšlØ¤u§{¡{¸7¿>¹>ñ�ô ×:Ò:ØØØ#ØØ—-‘-Ø—>‘>ñ
‰ô ÐMÈgÈYÐWÓXÐXØ
‡K�K�¨Ô6Ø(Ôð ,ÔØ€Mr-   c                 óP   • [         R                  R                  X5      nX#l        U$ rr   )r   ÚnnÚ	Parameterrz   )rž   ry   r{   Úparams       r+   Ú_rebuild_parameterrÎ   é  s#   € Ü�H‰H×Ñ˜tÓ3€Eð +Ôà€Lr-   c                 óf   • [         R                  R                  X5      nX$l        [	        XC5      nU$ rr   )r   rË   rÌ   rz   Ú_set_obj_state)rž   ry   r{   ÚstaterÍ   s        r+   Ú_rebuild_parameter_with_staterÒ   ó  s/   € Ü�H‰H×Ñ˜tÓ3€Eð +Ôô ˜5Ó(€EØ€Lr-   c           	      ó*  • [        U SS 5      nU(       a	  U" 5       nU$ [        R                  " U R                  5      nU(       a=  U R                  U Vs0 s H!  n[        X5      (       d  M  U[        X5      _M#     sn4nU$ U R                  nU$ s  snf )NÚ__getstate__)r:   ÚcopyregÚ
_slotnamesr   Ú__dict__r=   )ÚobjÚgetstate_fnrÑ   Úslots_to_saveÚnames        r+   Ú_get_obj_staterÜ   ÿ  s—   € ô ˜#˜~¨tÓ4€KÞÙ“ˆð €Lô  ×*Ò*¨3¯=©=Ó9ˆÞà—‘ñ !.óâ -˜Ü˜s×)ó -�Dœ' #Ó,Ò,Ù -ñðˆEð €Lð —L‘LˆEà€Lùòs   ÁBÁ,Bc                 ó8  • [        U[        5      (       a(  [        U5      S:X  d  [        SU 35      eUS   nUS   nOUnS nU(       a%  UR	                  5        H  u  pE[        XU5        M     U(       a%  UR	                  5        H  u  pE[        XU5        M     U $ )NrG   zInvalid serialized state: r   rE   )r   ÚtuplerJ   r   ÚitemsÚsetattr)rØ   rÑ   Ú
dict_stateÚslots_stateÚkÚvs         r+   rÐ   rÐ     s–   € Ü�%œ×ÑÜ�5‹z˜Q‹ÜÐ!;¸E¸7ÐCÓDÐDØ˜1‘Xˆ
Ø˜A‘h‰àˆ
Øˆö Ø×$Ñ$Ö&‰DˆAÜ�C˜AÖñ 'ö Ø×%Ñ%Ö'‰DˆAÜ�C˜AÖñ (à€Jr-   c                 ór   • U R                  S5      n[        US   5      nUSS   H  n[        X#5      nM     U$ )Nr   r   rE   )ÚsplitÚ
__import__r:   )rÛ   Ú
componentsrØ   Ú	components       r+   r   r   0  s<   € Ø—‘˜C“€JÜ
�Z ‘]Ó
#€CØ  “^ˆ	Ü�cÓ%Šñ $à€Jr-   c                 óT   • [         R                  R                  R                  U 5      $ )a~  Flatten dense tensors into a contiguous 1D buffer. Assume tensors are of
same dense type.

Since inputs are dense, the resulting tensor will be a concatenated 1D
buffer. Element-wise operation on this buffer will be equivalent to
operating individually.

Args:
    tensors (Iterable[Tensor]): dense tensors to flatten.

Returns:
    A contiguous 1D buffer containing input tensors.
)r   r4   Ú_nnÚflatten_dense_tensors)Útensorss    r+   Ú_flatten_dense_tensorsrî   8  s   € ô �8‰8�<‰<×-Ñ-¨gÓ6Ð6r-   c                 óx  • [         R                  R                  R                  U  Vs/ s H"  n[         R                  R                  U5      PM$     sn5      n[         R                  R                  R                  U  Vs/ s H"  n[         R                  R                  U5      PM$     sn5      nX#4$ s  snf s  snf )aF  Flatten sparse tensors into two contiguous 1D buffers, one of indices and
one of values. Assume tensors are of same sparse type.

Args:
    tensors (Iterable[Tensor]): sparse tensors to flatten.

Returns:
    A tuple of two contiguous 1D buffers, one containing input tensors'
    indices and the other containing the values.
)r   r4   rë   rì   r   r   r   )rí   re   Úflat_indicesÚflat_valuess       r+   Ú_flatten_sparse_tensorsrò   I  s�   € ô —8‘8—<‘<×5Ñ5Ù+2Ó3ª7 aŒ�‰×	Ñ	˜qÖ	!©7Ñ3ó€Lô —(‘(—,‘,×4Ñ4Ù*1Ó2ª' QŒ�‰×	Ñ	˜aÖ	 ©'Ñ2ó€Kð Ð$Ð$ùò 	4ùò 	3s   ¨)B2Á?)B7c                 óT   • [         R                  R                  R                  X5      $ )aŠ  View a flat buffer using the sizes of tensors. Assume that tensors are of
same dense type, and that flat is given by _flatten_dense_tensors.

Args:
    flat (Tensor): flattened dense tensors to unflatten.
    tensors (Iterable[Tensor]): dense tensors whose sizes will be used to
      unflatten flat.

Returns:
    Unflattened dense tensors with sizes same as tensors and values from
    flat.
)r   r4   rë   Úunflatten_dense_tensors)Úflatrí   s     r+   Ú_unflatten_dense_tensorsrö   ]  s   € ô �8‰8�<‰<×/Ñ/°Ó>Ð>r-   c           	      ó  • U u  p#[         R                  R                  R                  X! Vs/ s H"  n[         R                  R                  U5      PM$     sn5      n[         R                  R                  R                  X1 Vs/ s H"  n[         R                  R                  U5      PM$     sn5      n/ n[        XU5       H5  u  pHn	UR                  UR                  X‰UR                  5       5      5        M7     [        U5      $ s  snf s  snf )aØ  View flat buffer (containing indices and values) using the sizes of
tensors. Assume that tensors are of same sparse type, and that flat is given
by _flatten_sparse_tensors.

Args:
    flat (tuple(Tensor, Tensor)): flattened indices and values of sparse
      tensors to unflatten.
    tensors (Iterable[Tensor]): sparse tensors whose sizes will be used to
      unflatten flat.

Returns:
    Unflattened sparse tensors with sizes same as tensors and values from
    flat.
)r   r4   rë   rô   r   r   r   Úziprœ   Únewr    rÞ   )
rõ   rí   rð   rñ   re   rA   rB   ÚoutputsÚirä   s
             r+   Ú_unflatten_sparse_tensorsrü   m  sÓ   € ð !%Ñ€LÜ�h‰h�l‰l×2Ñ2Ø¸ÓAº°A”u—|‘|×,Ñ,¨QÖ/¹ÑAó€Gô �X‰X�\‰\×1Ñ1Ø°wÓ?²w°!”e—l‘l×*Ñ*¨1Ö-±wÑ?ó€Fð €GÜ�w¨Ö0‰ˆˆaØ�‰�q—u‘u˜Q 1§6¡6£8Ó,Ö-ñ 1ä�‹>Ðùò Bùò @s   ¬)D
Â)D

c                 ó
  ^• [        [        5      nU  H$  nX#R                  5          R                  U5        M&     UR	                  5        VVs0 s H  u  pEU[        U5      _M     snnm[        U4S jU 5       5      $ s  snnf )aë  Assume that tensors are of same order as ordered_tensors within their
types, e.g., from _take_tensors. Reorder them to be of same order as
ordered_tensors.

Args:
    tensors (Iterable[Tensor]): tensors to be reordered. They should be of
      the same order as ordered_tensors within their own types.
    ordered_tensors (Iterable[Tensor]): tensors whose order will be the
      reference.

Returns:
    Ordered tuple of tensors with contents from tensors and order of
    ordered_tensors.
c              3   ó\   >#   • U  H!  n[        TUR                  5          5      v •  M#     g 7frr   )Únextr   )Ú.0rk   Ú
type_dict_s     €r+   Ú	<genexpr>Ú&_reorder_tensors_as.<locals>.<genexpr>œ  s$   øé € ÐOº°V”�j §¡£Ñ/×0Ð0ºùs   ƒ),)r   rK   r   rœ   rß   ÚiterrÞ   )rí   Úordered_tensorsÚ	type_dictrk   re   Úcollr  s         @r+   Ú_reorder_tensors_asr  ‰  sn   ø€ ô œDÓ!€IÛˆØ—+‘+“-Ñ ×'Ñ'¨Ö/ñ à/8¯©Ô/@ÔAÒ/@¡G A�!”T˜$“Z’-Ñ/@ÒA€JÜÔO¹ÓOÓOÐOùó Bs   ÁA?c              #   ó°  #   • [        S 5      nU  GH  nUR                  5       nUR                  (       a‚  [        R                  R                  U5      n[        R                  R                  U5      nUR                  5       UR                  5       -  UR                  5       UR                  5       -  -   nO!UR                  5       UR                  5       -  nX$   nUS   U-   U:”  a  US   S:”  a  US   v •  / S/=o‚U'   US   R                  U5        US==   U-  ss'   GM     UR                  5        H  u  pš[        U	5      S:”  d  M  U	v •  M     g7f)aµ  Group tensors into chunks. This generator yields a chunk at each time,
each containing tensors of same type up to certain byte limit in total size.

Args:
    tensors (Sequence): A sequence of tensors to be separated into chunks.
    size_limit (int): The limit of each chunk in bytes.

Yields:
    Blocks of tensors of same type and within size_limit. The yielded
    tensors are only ordered as the original sequence within its types.
c                  ó
   • / S/$ )Nr   © r  r-   r+   Ú<lambda>Ú_take_tensors.<locals>.<lambda>«  s   € ¸BÀ¹7r-   rE   r   N)r   r   r   r   r   r   r   ÚnumelÚelement_sizerœ   rB   rJ   )rí   Ú
size_limitÚbuf_dictrk   re   rA   rB   r    Úbuf_and_sizeÚbufrÈ   s              r+   Ú_take_tensorsr  Ÿ  s,  é € ô (3±?Ó'C€HÜˆØ�K‰K‹MˆØ××Ü—l‘l×+Ñ+¨FÓ3ˆGÜ—\‘\×)Ñ)¨&Ó1ˆFà—‘“ '×"6Ñ"6Ó"8Ñ8Ø—,‘,“. 6×#6Ñ#6Ó#8Ñ8ñ9ñ ð
 —<‘<“> F×$7Ñ$7Ó$9Ñ9ˆDØ‘{ˆØ˜‰?˜TÑ! JÓ.°<À±?ÀQÓ3FØ˜q‘/Ò!Ø*,¨a¨Ð0ˆL A™;Ø�Q‰×Ñ˜vÔ&Ø�Q‹˜4ÑŽñ! ð" —/‘/Ö#‰ˆÜˆs‹8�a�<ØŒIò $ùs   ‚EEÅ	Ec                 ó   ^ ^• UU 4S jnU$ )Nc                 óF   >• [        T5      U l        TU R                  S'   U $ )NÚreturn)rY   Ú__annotations__)Úfunr%   Úrets    €€r+   ÚdecÚannotate.<locals>.decÅ  s$   ø€ Ü" 6›lˆÔØ(+ˆ×Ñ˜HÑ%Øˆ
r-   r  )r  r%   r  s   `` r+   Úannotater  Ä  s   ù€ öð
 €Jr-   c                 ó€  • [         R                  R                  U 5      nUc  [        U 5      n/ n[         R                  R                  SSS9   UR                  S U 5       5        UR                  S UR                  5        5       5        U SSR                  U5       S3nS S S 5        U$ ! , (       d  f       W$ = f)Nr   )Ú	thresholdÚ	edgeitemsc              3   ó8   #   • U  H  n[        U5      v •  M     g 7frr   ©Úrepr)r   Úas     r+   r  Úrender_call.<locals>.<genexpr>Ô  s   é € Ð.ª Aœ˜QŸ˜ªùs   ‚c              3   óF   #   • U  H  u  pU S [        U5       3v •  M     g7f)Ú=Nr"  )r   rã   rä   s      r+   r  r%  Õ  s!   é € ÐD²^©T¨Q˜1˜#˜Qœt A›w˜iÕ(²^ùs   ‚!Ú(z, Ú))	r   Ú	overridesÚresolve_namer   Ú_tensor_strÚprintoptionsÚextendrß   Újoin)ÚfnÚargsr%   Ústr_fnÚstr_argsÚrs         r+   Úrender_callr5  Í  s¦   € Ü�_‰_×)Ñ)¨"Ó-€FØ�~Ü�R“ˆà€HÜ	×	Ñ	×	'Ñ	'°!¸qÐ	'Ò	AØ�‰Ñ.©Ó.Ô.Ø�‰ÑD°V·\±\´^ÓDÔDØˆh�a˜Ÿ	™	 (Ó+Ð,¨AÐ.ˆ÷ 
Bð €H÷	 
BÔ	Að €Hús   ÁAB.Â.
B=c                   ó"   • \ rS rSrSrSrS rSrg)ÚKeyErrorMessageiã  z(str subclass that returns itself in reprr  c                 ó   • U $ rr   r  ©r"   s    r+   Ú__repr__ÚKeyErrorMessage.__repr__è  s   € Øˆr-   N)r   r   Ú__qualname__Ú__firstlineno__Ú__doc__Ú	__slots__r:  Ú__static_attributes__r  r-   r+   r7  r7  ã  s   † Ù3à€Iõr-   r7  c                   ó(   • \ rS rSrSrSS jrS rSrg)ÚExceptionWrapperiì  z?Wraps an exception plus traceback to communicate across threadsNc                 ó¢   • Uc  [         R                  " 5       nUS   U l        SR                  [        R
                  " U6 5      U l        X l        g )Nr   r   )ÚsysÚexc_infoÚexc_typer/  Ú	tracebackÚformat_exceptionÚexc_msgÚwhere)r"   rE  rJ  s      r+   Ú__init__ÚExceptionWrapper.__init__ï  s@   € ð ÑÜ—|’|“~ˆHØ  ™ˆŒà—w‘wœy×9Ò9¸8ÐDÓEˆŒØ�
r-   c                 óX  • SU R                   R                   SU R                   SU R                   3nU R                   [        L a  [        U5      nO+[        U R                   SS5      (       a  U R                  US9e U R                  U5      nUe! [         a    [        U5      Sef = f)z4Reraises the wrapped exception in the current threadzCaught Ú z.
Original rS   N)rS   )	rF  r   rJ  rI  ÚKeyErrorr7  r:   Ú	Exceptionr   )r"   ÚmsgÚ	exceptions      r+   ÚreraiseÚExceptionWrapper.reraiseù  s¯   € ð ˜Ÿ™×.Ñ.Ð/¨q°·±°¸LÈÏÉÈÐWˆØ�=‰=œHÒ$ô " #Ó&‰CÜ�T—]‘] I¨t×4Ñ4ð —-‘-àð  ð ð ð	.ØŸ™ cÓ*ˆIð
 ˆøô	 ó 	.ô ˜sÓ#¨Ð-ð	.ús   Á?B ÂB))rI  rF  rJ  )Nzin background)r   r   r<  r=  r>  rK  rS  r@  r  r-   r+   rB  rB  ì  s   † ÙJôõr-   rB  c                  ó&  • [         R                  R                  5       (       a  g[         R                  R                  R                  5       (       a  g[        [         S5      (       a$  [         R                  R                  5       (       a  g[        [         S5      (       a$  [         R                  R                  5       (       a  g[         R                  R                  5       n [        [         U S 5      nU(       a  UR                  5       (       a  U $ g ©Nr0   ÚmpsÚxpuÚmtia)r   r0   Úis_availableÚbackendsrW  r=   rX  rY  r4   r5   r:   )Úcustom_backend_nameÚcustom_device_mods     r+   Ú_get_available_device_typer^    s¶   € Ü‡z�z×Ñ× Ñ ØÜ‡~�~×Ñ×&Ñ&×(Ñ(ØÜŒu�e×Ñ¤§¡×!7Ñ!7×!9Ñ!9ØÜŒu�f×Ñ¤%§*¡*×"9Ñ"9×";Ñ";ØÜŸ(™(×@Ñ@ÓBÐÜ¤Ð':¸DÓAÐÞÐ.×;Ñ;×=Ñ=Ø"Ð"àr-   c                 ó  • [        5       nU(       a*  UR                  5       S:X  a  U " [        R                  5      $ U(       a*  UR                  5       S:X  a  U " [        R                  5      $ U(       a*  UR                  5       S:X  a  U " [        R
                  5      $ U(       a*  UR                  5       S:X  a  U " [        R                  5      $ U[        R                  R                  5       :X  a  U " [        [        U5      5      $ g rV  )
r^  Úlowerr   r0   rW  rX  rY  r4   r5   r:   )Ú
get_memberÚdevice_types     r+   Ú_get_device_attrrc  %  s¼   € Ü,Ó.€KÞ�{×(Ñ(Ó*¨fÓ4Ùœ%Ÿ*™*Ó%Ð%Þ�{×(Ñ(Ó*¨eÓ3Ùœ%Ÿ)™)Ó$Ð$Þ�{×(Ñ(Ó*¨eÓ3Ùœ%Ÿ)™)Ó$Ð$Þ�{×(Ñ(Ó*¨fÓ4Ùœ%Ÿ*™*Ó%Ð%Ø”e—h‘h×<Ñ<Ó>Ó>Ùœ'¤%¨Ó5Ó6Ð6àr-   c                  ó   • [        S 5      $ )Nc                 ó"   • U R                  5       $ rr   )Úcurrent_device©Úms    r+   r  Ú+_get_current_device_index.<locals>.<lambda>7  s   €  a×&6Ñ&6Ô&8r-   ©rc  r  r-   r+   Ú_get_current_device_indexrk  5  s   € äÑ8Ó9Ð9r-   c                  ó   • [        S 5      $ )Nc                 óF   • [        [        U R                  5       5      5      $ rr   )rK   ÚrangeÚdevice_countrg  s    r+   r  Ú)_get_all_device_indices.<locals>.<lambda><  s   € ¤d¬5°·±Ó1AÓ+BÔ&Cr-   rj  r  r-   r+   Ú_get_all_device_indicesrq  :  s   € äÑCÓDÐDr-   c                 óP   ^• U  V^s/ s H  m[        U4S j5      PM     sn$ s  snf )Nc                 ó&   >• U R                  T5      $ rr   )Úget_device_properties)rh  rû   s    €r+   r  Ú)_get_devices_properties.<locals>.<lambda>A  s   ø€  q×'>Ñ'>¸qÔ'Ar-   rj  )Ú
device_idsrû   s    `r+   Ú_get_devices_propertiesrw  ?  s"   ø€ áLVÔWÊJÀqÔÔAÖBÉJÑWÐWùÒWs   ‡#r  c                  ó„   • [         R                  R                  5       S:”  a  [         R                  R                  5       $ g)z¸Checks if there are CUDA devices available and
returns the device index of the current default CUDA device.
Returns -1 in case there are no CUDA devices available.
Arguments: ``None``
r   éÿÿÿÿ)r   r0   ro  rf  r  r-   r+   Úget_current_device_indexrz  D  s/   € ô ‡z�z×ÑÓ  1Ó$Ü�z‰z×(Ñ(Ó*Ð*Ør-   r1   ÚoptionalÚ	allow_cpuc                 óú  • [        U [        5      (       a  [        R                  " U 5      n Sn[        U [        R                  5      (       aC  U(       d  U R                  S:X  a  [        SU  35      eU R                  S:X  a  SOU R                  n[        U [        5      (       a  U nUcQ  U(       a<  [        R                  R                  5       (       a  [        5       nU$ [        5       n U$ [        SU  35      eU$ )aû  Gets the device index from :attr:`device`, which can be a torch.device
object, a Python integer, or ``None``.

If :attr:`device` is a torch.device object, returns the device index if it
has index. Note that for a device without a specified index,
i.e., ``torch.device('xxx')``, this will return the current default
device of that type if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``,
CPU devices will be accepted and ``-1`` will be returned in this case.

If :attr:`device` is a Python integer, it is returned as is.

If :attr:`device` is ``None``, this will return the current default
device of the supported runtime platform if :attr:`optional` is ``True``.
i.e., the current default CUDA device will be returned if CUDA runtime is supported.
Nr/   z$Expected a non cpu device, but got: ry  zFExpected a torch.device with a specified index or an integer, but got:)r   r   r   r1   r   Ú
ValueErrorÚindexÚintÚjitÚis_scriptingrz  rk  )r1   r{  r|  Ú
device_idxs       r+   Ú_get_device_indexr„  O  sá   € ô( �&œ#×ÑÜ—’˜fÓ%ˆØ!€JÜ�&œ%Ÿ,™,×'Ñ'Þ˜VŸ[™[¨EÓ1ÜÐCÀFÀ8ÐLÓMÐMØ!Ÿ;™;¨%Ó/‘R°V·\±\ˆ
Ü�&œ#×ÑØˆ
ØÑÞô �y‰y×%Ñ%×'Ñ'Ü5Ó7�
ð Ðô 7Ó8‘
ð
 Ðô ØXÐY_ÐX`Ðaóð ð Ðr-   c                 ó®   • [        U [        R                  R                  5      (       d+  U R	                  5       (       a  [        R
                  " U 5      $ U $ )z´
Returns a real view of a tensor if complex dtype else just the tensor
need to check if a UninitializedParameter because otherwise checking is_complex is an error for a LazyModule
)r   r   rË   ÚUninitializedParameterÚ
is_complexÚview_as_realrj   s    r+   Ú_handle_complexr‰  ~  sI   € ô ˜&¤%§(¡(×"AÑ"A×BÑBØ×Ñ×Ñô 	×Ò˜6Ó"ðð ð	r-   c                 ó®  • [        U [        R                  5      (       d  [        S[	        U 5       35      eU R
                  (       a#  [        R                  " U 5      R                  S-	  $ U R                  (       a#  [        R                  " U 5      R                  S-	  $ U [        R                  :X  a  g[        R                  " U 5      R                  S-	  $ )z0
Returns the element size for a dtype, in bytes
zexpected torch.dtype, but got rG   r™   rE   )r   r   r#   r   r   r‡  ÚfinfoÚbitsÚis_floating_pointÚboolÚiinfo)r#   s    r+   Ú_element_sizer�  ‹  s›   € ô �eœUŸ[™[×)Ñ)ÜÐ;¼DÀ»K¸=ÐIÓJÐJà××Ü�{Š{˜5Ó!×&Ñ&¨!Ñ+Ð+Ø	×	 ×	 Ü�{Š{˜5Ó!×&Ñ&¨!Ñ+Ð+Ø	”%—*‘*Ó	àä�{Š{˜5Ó!×&Ñ&¨!Ñ+Ð+r-   c                   ó(   • \ rS rSrSS jrSS jrSrg)Ú_ClassPropertyDescriptori�  Nc                 ó   • Xl         g rr   ©Úfget)r"   r•  Úfsets      r+   rK  Ú!_ClassPropertyDescriptor.__init__ž  s   € Ø�	r-   c                 ó^   • Uc  [        U5      nU R                  R                  X5      " 5       $ rr   )r   r•  Ú__get__)r"   ÚinstanceÚowners      r+   r™  Ú _ClassPropertyDescriptor.__get__¡  s(   € Ø‰=Ü˜“NˆEØ�y‰y× Ñ  Ô1Ó3Ð3r-   r”  rr   )r   r   r<  r=  rK  r™  r@  r  r-   r+   r’  r’  �  s   † ô÷4r-   r’  c                 ód   • [        U [        [        45      (       d  [        U 5      n [        U 5      $ rr   )r   ÚclassmethodÚstaticmethodr’  )Úfuncs    r+   Úclasspropertyr¡  §  s)   € Ü�dœ[¬,Ð7×8Ñ8Ü˜4Ó ˆÜ# DÓ)Ð)r-   úU`torch._utils.is_compiling` is deprecated. Use `torch.compiler.is_compiling` instead.)Úcategoryc                  ó>   • [         R                  R                  5       $ rr   )r   ÚcompilerÚis_compilingr  r-   r+   r¦  r¦  °  s   € ô
 �~‰~×*Ñ*Ó,Ð,r-   c                  óh   • [         R                  " SSS9  [        R                  R	                  5       $ )zT
Indicates whether we are tracing/compiling with torch.compile() or torch.export().
r¢  rG   rH   )rP   rQ   r   r¥  r¦  r  r-   r+   r¦  r¦  ¹  s+   € ô 	�ŠØcàò	
ô
 �~‰~×*Ñ*Ó,Ð,r-   c                 ó¸  • SSK Jn  [        X5      (       a†  [        R                  R                  [        R                  R                  R                  5      n [        R                  " U R                  5        Ub   [        R                  R                  U5        g g [        R                  " U 5        g ! Ub   [        R                  R                  U5        f f = f)Nr   )ÚFunctionalTensor)Ú#torch._subclasses.functional_tensorr©  r   r   r4   Ú_unset_dispatch_modeÚ_TorchDispatchModeKeyÚ
FUNCTIONALÚ_functionalize_syncÚelemÚ_set_dispatch_mode)re   r©  Úmaybe_functional_modes      r+   r®  r®  Å  s¥   € õ Eä�!×&Ñ&ô !&§¡× =Ñ =Ü�H‰H×*Ñ*×5Ñ5ó!
Ðð	CÜ×%Ò% a§f¡fÔ-à$Ñ0Ü—‘×+Ñ+Ð,AÕBð 1ô 	×!Ò! !Õ$øð %Ñ0Ü—‘×+Ñ+Ð,AÕBð 1ús   Á B4 Â4%CrG   rb  c                 óR   • [        [        U S 5      nUc  [        SU  SU  S35      eU$ )NzDevice 'z<' does not have a corresponding module registered as 'torch.z'.)r:   r   r   )rb  r?   s     r+   Ú_get_device_moduler³  ã  sA   € äœE ;°Ó5€MØÑÜØ�{�mÐ#_Ð`kÐ_lÐlnÐoó
ð 	
ð Ðr-   rÛ   c                 óZ   • S[         4S jn[        U [        4U" S5      U" S5      S.5      $ )NÚis_initc                 ó   ^ • U 4S jnU$ )Nc                 ót   >• T(       a  U R                   R                  nOU R                  n[        SU 35      e)Nz&Tried to instantiate dummy base class )r   r   r   )rØ   r1  r%   Ú
class_namerµ  s       €r+   Úerr_fnÚ/_dummy_type.<locals>.get_err_fn.<locals>.err_fnï  s1   ø€ ÞØ Ÿ]™]×3Ñ3‘
à Ÿ\™\�
ÜÐ!GÈ
À|ÐTÓUÐUr-   r  )rµ  r¹  s   ` r+   Ú
get_err_fnÚ_dummy_type.<locals>.get_err_fnî  s   ø€ õ	Vð ˆr-   TF)rK  Ú__new__)rŽ  r   Úobject)rÛ   r»  s     r+   Ú_dummy_typer¿  í  s5   € ðœDô ô ØŒvˆi¡j°Ó&6Á:ÈeÓCTÑUóð r-   c                   ó4   • \ rS rSrS rS rS rS\4S jrSr	g)	Ú_LazySeedTrackeriý  c                 ó.   • S U l         S U l        / U l        g rr   ©Úmanual_seed_all_cbÚmanual_seed_cbÚ
call_orderr9  s    r+   rK  Ú_LazySeedTracker.__init__  s   € Ø"&ˆÔØ"ˆÔØˆ�r-   c                 óN   • X4U l         U R                  U R                   /U l        g rr   rÃ  ©r"   ÚcbrG  s      r+   Úqueue_seed_allÚ_LazySeedTracker.queue_seed_all  s$   € Ø#% /ˆÔà×.Ñ.°×0GÑ0GÐHˆ�r-   c                 óN   • X4U l         U R                  U R                   /U l        g rr   )rÅ  rÄ  rÆ  rÉ  s      r+   Ú
queue_seedÚ_LazySeedTracker.queue_seed  s$   € Ø!˜oˆÔà×2Ñ2°D×4GÑ4GÐHˆ�r-   r  c                 ó   • U R                   $ rr   )rÆ  r9  s    r+   Ú	get_callsÚ_LazySeedTracker.get_calls  s   € Ø�‰Ðr-   )rÆ  rÄ  rÅ  N)
r   r   r<  r=  rK  rË  rÎ  rK   rÑ  r@  r  r-   r+   rÁ  rÁ  ý  s   † ò
ò
Iò
Ið
˜4÷ r-   rÁ  ÚPc                   ó|   • \ rS rSrS\4S jrS\\S4   SS4S jrS\R                  S	\R                  SS4S
 jrSrg)ÚCallbackRegistryi  rÛ   c                 ó   • Xl         / U l        g rr   )rÛ   Úcallback_list)r"   rÛ   s     r+   rK  ÚCallbackRegistry.__init__  s   € ØŒ	Ø68ˆÕr-   rÊ  Nr  c                 ó:   • U R                   R                  U5        g rr   )r×  rœ   )r"   rÊ  s     r+   Úadd_callbackÚCallbackRegistry.add_callback  s   € Ø×Ñ×!Ñ! "Õ%r-   r1  r%   c                 óž   • U R                    H  n U" U0 UD6  M     g ! [         a$    [        R                  SU R                  5         M>  f = f)Nz6Exception in callback for %s registered with gpu trace)r×  rP  ÚloggerrR  rÛ   )r"   r1  r%   rÊ  s       r+   Úfire_callbacksÚCallbackRegistry.fire_callbacks!  sL   € Ø×$Ô$ˆBðÙ�DÐ#˜FÔ#ò %øô ó Ü× Ñ ØLÈdÏiÉi÷ðús   ‘ž*AÁA)r×  rÛ   )r   r   r<  r=  r   rK  r   rÓ  rÚ  r1  r%   rÞ  r@  r  r-   r+   rÕ  rÕ    sL   † ð9˜Sô 9ð&˜x¨¨4¨Ñ0ð &°Tô &ð A§F¡Fð °a·h±hð À4÷ r-   rÕ  Úmodule_namec                 ó`  • [         R                  R                  U S 5      =nb  U$ [        R                  R                  U 5      =nbg  [        R                  R                  U5      nU[         R                  U '   UR                  c  [        S5      eUR                  R                  U5        U$ g )Nz)The loader attribute should always be set)
rD  ÚmodulesrZ   Ú	importlibÚutilÚ	find_specÚmodule_from_specÚloaderr;   Úexec_module)rà  ÚmoduleÚspecs      r+   Ú
try_importrë  +  s‘   € ô —+‘+—/‘/ +¨tÓ4Ð4ˆÑAØˆä—‘×(Ñ(¨Ó5Ð5ˆÑBÜ—‘×0Ñ0°Ó6ˆØ#)Œ�‰�KÑ ð �;‰;ÑÜ Ð!LÓMÐMØ�‰×Ñ Ô'Øˆàr-   ÚbuiltinsrÕ   ÚqueueÚreprlibzcollections.abcÚcollectionsÚdbmÚio)Ú__builtin__Úcopy_regÚQueuer#  Ú_abcollÚUserDictÚUserListÚ
UserStringÚwhichdbÚStringIOÚ	cStringIO)rò  Úxrange)rì  rn  )rò  Úreduce)Ú	functoolsrý  )rò  Úintern)rD  rÿ  )rò  Úunichr)rì  Úchr)rò  Úunicode)rì  r   )rò  rÃ   )rì  r€  )Ú	itertoolsÚizip)rì  rø   )r  Úimap)rì  Úmap)r  Úifilter)rì  Úfilter)r  Úifilterfalse)r  Úfilterfalse)r  Úizip_longest)r  Úzip_longest)rö  ÚIterableUserDict)rï  rö  )r÷  r÷  )rï  r÷  )rø  rø  )rï  rø  )rò  Ú
basestring)Ú
exceptionsÚStandardError)rì  rP  )rö  rö  ÚresÚ
group_sizeÚ
gather_dimc                 óH  • US:X  a  U $ [        U R                  5      nUS:”  a  [        R                  " USU 5      OSnUS   U:X  a4  US:X  a.  S/USU -   US   X2   -  /-   X2S-   S -   nU R	                  U5      $ [
        R                  " [
        R                  " XSS9US9$ )a³  
This is intuitively the same as torch.cat(torch.chunk(res, group_size,
dim=0), dim=gather_dim), but returns a view if data movement is not
necessary.  This operation arises in NCCL all_gather, where you always get
a result which is concatenated on dim=0, even though actually you may need
to undo this concatenation and then re-cat on the gather dim.

When is data-movement not necessary?  Intuitively, we need to understand if
the unflatten in this reference implementation of this code triggers a
copy or not:

    chunks = torch.unflatten(res, 0, [group_size, -1])
    return torch.flatten(torch.movedim(chunks, 0, gather_dim), gather_dim, gather_dim + 1)

Assume res is contiguous (it will be coming out of the collective).  We
essentially need to know if the movedim maintains the contiguity of the
tensor.  Moving a dimension typically does NOT preserve contiguity, unless
EVERY dimension it is moved across is size 1.

Example: shape [4, d1, d2] with group_size=4, gather_dim=1 -> [1, 4*d1, d2]

    [4, d1, d2] -> [4, 1, d1, d2] -> [1, 4, d1, d2] (contiguous!)

Example: shape [4, 2, d2] with group_size=4, gather_dim=2 -> [1, 2, 4*d2]

    [4, 2, d2] -> [4, 1, 2, d2] -> [1, 2, 4, d2] (not contiguous!)

Args:
    res: Tensor with gathered data in dim 0, shape [group_size, ...]
    group_size: Number of ranks in the group
    gather_dim: Dimension to gather along in the output

Returns:
    Tensor with data rearranged to gather along gather_dim
r   rE   N)Údim)rK   ÚshapeÚmathÚprodÚviewr   ÚcatÚchunk)r  r  r  r  Únumel_betweenÚfinal_shapes         r+   Ú_maybe_view_chunk_catr  k  sÆ   € ðN �Qƒàˆ
ä�—‘‹O€Eð
 7AÀ1³n”D—I’I˜e A jÐ1Ô2È!€MàˆQ�x�:Ó -°1Ó"4ð ˆCØ�A�jÐ!ñ"à�Q‰x˜%Ñ+Ñ+Ð,ñ-ð  ‘NÐ$Ð%ñ&ð 	ð �x‰x˜Ó$Ð$ô
 �yŠyœŸš S¸!Ñ<À*ÑMÐMr-   c                   óx   • \ rS rSr% Sr\\S'   \\S'   \\S'   \\   \S'   \\   \S'   \\   \S'   \\   \S	'   S
r	g)Ú_Framei­  z1Frame information from memory profiler snapshots.ÚfilenameÚlinerÛ   Ú
fx_node_opÚfx_node_nameÚfx_node_targetÚfx_original_tracer  N)
r   r   r<  r=  r>  r   r  r€  r   r@  r  r-   r+   r   r   ­  s@   ‡ Ù;àƒMØ
ƒIØ
ƒIà˜CÑ Ó Ø˜cÑ"Ó"Ø Ñ$Ó$Ø" 3Ñ'Ö'r-   r   c                   óR   • \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\	   \S'   Sr
g	)
Ú_Blockiº  zMemory block information.r    Úrequested_sizeÚaddressrÑ   Úframesr  N)r   r   r<  r=  r>  r€  r  r   rK   r   r@  r  r-   r+   r(  r(  º  s$   ‡ Ù#à
ƒIØÓØƒLØƒJØ�‰LÖr-   r(  c                   óf   • \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\	   \S	'   S
r
g)Ú_SegmentiÄ  zMemory segment information.r*  Ú
total_sizeÚstreamÚsegment_typeÚallocated_sizeÚactive_sizeÚblocksr  N)r   r   r<  r=  r>  r€  r  r   rK   r(  r@  r  r-   r+   r-  r-  Ä  s0   ‡ Ù%àƒLØƒOØƒKØÓØÓØÓØ�‰LÖr-   r-  c                   óh   • \ rS rSr% Sr\\S'   \\   \S'   \	\
   \S'   \\S'   \\S'   \\   \S'   S	rg
)Ú_TraceEntryiÐ  zMemory trace entry information.ÚactionÚaddrr+  r    r/  Údevice_freer  N)r   r   r<  r=  r>  r   r  r   r€  rK   r   r@  r  r-   r+   r5  r5  Ð  s4   ‡ Ù)àƒKØ
�cÑ
ÓØ�‰LÓØ
ƒIØƒKØ˜SÑ!Ö!r-   r5  c                   óF   • \ rS rSr% Sr\\   \S'   \\\\	         \S'   Sr
g)Ú	_SnapshotiÛ  zMemory snapshot structure.ÚsegmentsÚdevice_tracesr  N)r   r   r<  r=  r>  rK   r-  r  r   r5  r@  r  r-   r+   r:  r:  Û  s$   ‡ Ù$à�8‰nÓØ˜t D¨Ñ$5Ñ6Ñ7Ö7r-   r:  r+  c                 ó   • SSK Jn  SSKJn  [        R
                  " [        R                  " U5       S35      nSnU  GHK  nUR                  S5      nUR                  S5      nU(       a  U(       d  M6  UR                  [        R                  R                  U5      5      (       d  Mk  UR                  U5      nUc  M�  UR                  S0 5      n	UR                  S0 5      n
UR                  S	S5      nU	R                  X{-
  5      nUc  MÏ  U
R                  U5      nUc  Må  UR                  S
5      US'   UR                  S5      US'   [        UR                  S5      5      US'   UR                  S5      nU(       a  XåS'   US-  nGMN     U$ )aQ  
Augment a list of frames with FX debug information. For each frame corresponding
to an FX-generated Python file, this function attaches additional FX node
metadata (op, name, target, and original trace).

Args:
    frames (list[_Frame]): List of frame dictionaries to augment

Returns:
    int: The count of frames that were augmented.
r   )ÚFX_GRAPH_MODULE_FILE_PREFIX)Ú_FX_METADATA_REGISTRYz.*\.py$r!  r"  Ú
lineno_mapÚnode_metadataÚprologue_startÚopr#  rÛ   r$  Útargetr%  Ústack_tracer&  rE   )Útorch.fx.graph_moduler>  Útorch.fx.tracebackr?  ÚreÚcompileÚescaperZ   ÚsearchÚosÚpathÚbasenamer   )r+  r>  r?  Ú_FX_GENERATED_PATTERNÚcountÚframer!  Úlinenoro   r@  rA  rB  Únode_idxÚ	node_infoÚoriginal_traces                  r+   Ú_augment_framesrV  â  sy  € õ BÝ8ô ŸJšJÜ�IŠIÐ1Ó2Ð3°7Ð;óÐð €EäˆØ—9‘9˜ZÓ(ˆØ—‘˜6Ó"ˆÞžvÙð %×+Ñ+¬B¯G©G×,<Ñ,<¸XÓ,F×GÑGÙà(×,Ñ,¨XÓ6ˆØÑÙà—\‘\ ,°Ó3ˆ
Ø Ÿ™ _°bÓ9ˆØ!Ÿ™Ð&6¸Ó:ˆð —>‘> &Ñ"9Ó:ˆØÑÙà!×%Ñ% hÓ/ˆ	ØÑÙð (Ÿm™m¨DÓ1ˆˆlÑØ )§¡¨fÓ 5ˆˆnÑÜ"% i§m¡m°HÓ&=Ó">ˆÐÑð #Ÿ™ }Ó5ˆÞØ)7Ð%Ñ&à�‰
‹ñK ðN €Lr-   Úsnapshotc                 óø  • [        U [        5      (       a:  [        U S5       n[        [        [
        R                  " U5      5      nSSS5        OU nWR                  S/ 5       H2  nUR                  S/ 5       H  nSU;   d  M  [        US   5        M     M4     UR                  S/ 5       H9  nU H0  n[        U[        5      (       d  M  SU;   d  M"  [        US   5        M2     M;     U$ ! , (       d  f       N§= f)a€  
Augment a memory snapshot with original source stack traces from FX metadata.

IMPORTANT: This function reads from a global in-memory registry (_FX_METADATA_REGISTRY)
that is populated during graph module compilation. It must be called in the same
Python process where the FX graphs were compiled. It cannot be used to augment
snapshots loaded from disk in a different process.

Args:
    snapshot (str or _Snapshot): Either a memory snapshot dict or path to a snapshot pickle file

Returns:
    _Snapshot: The augmented snapshot dictionary with fx_node_op, fx_node_name,
        fx_original_trace, and fx_node_info fields added to frames
ÚrbNr;  r3  r+  r<  )
r   r   Úopenr   r:  ÚpickleÚloadrZ   rV  rY   )rW  ÚfÚsnapshot_dictÚsegmentÚblockÚ
trace_listÚtrace_entrys          r+   Ú%_augment_memory_snapshot_stack_tracesrc  "  s×   € ô( �(œC× Ñ ä�(˜DÔ! QÜ ¤¬F¯KªK¸«NÓ;ˆM÷ "Ð!ð !ˆð !×$Ñ$ Z°Ö4ˆØ—[‘[ ¨2Ö.ˆEØ˜5Õ Ü  h¡Ö0ó /ñ 5ð $×'Ñ'¨¸Ö<ˆ
Û%ˆKÜ˜+¤t×,Ó,°¸[Õ1HÜ ¨HÑ 5Ö6ó &ñ =ð
 Ð÷# "Õ!ús   ¢%C+Ã+
C9)NF)Frr   )FF)grÕ   rþ  rã  Úloggingr  rL  r[  rH  rD  rG  rP   rï  r   Úcollections.abcr   Útypesr   Útypingr   r   r   r	   r
   Útyping_extensionsr   r   r   r   r,   rC   r   r\   rf   rl   rp   rw   r|   r   r€   rK   r  r—   r    r§   r¬   r¯   Ú_rebuild_xla_tensorr³   r·   rÉ   rÎ   rÒ   rÜ   rÐ   r   rî   rò   rö   rü   r  r  r  r5  r   r7  rB  r^  rc  rk  rq  rw  r€  rz  rŽ  r„  r‰  r�  r’  r¡  ÚFutureWarningr¦  r®  Ú	lru_cacher³  r   r¿  rÁ  Ú	getLoggerr   rÝ  rÓ  rÕ  rë  ÚIMPORT_MAPPINGÚNAME_MAPPINGr  r   r(  r-  r5  r:  rV  rc  r  r-   r+   Ú<module>ro     sõ  ðä Û Û Û Û Û 	Û Û 	Û 
Û Û Ý #Ý $Ý ß ?Õ ?ß @Ñ @ã ô%8ôP.#òbò$ò@Jò1ò4òð" ôð> ôð0 57Ð ˜T .Ñ1Ó 6ò5,òp'OòTSòòð 8Ð òòò20òfò	òò6ò,ò7ò"%ò(?ò ò8Pò, òJò
ô,�cô ÷%ñ %òPò"ò :ò
Eò
Xð
 #ô ð Øñ,Øð,àð,ð ð,ð 	õ	,ò^
ò,÷$4ñ 4ò*ö ñ Ø_Øñð-˜$ó -ó	ñ-ð
	-˜$ô 	-ò%ð< ×Ò�QÓð Có ó ðð�cð ˜dô ÷ ñ ð0 
×	Ò	˜8Ó	$€ÙˆcƒN€ô�w˜q‘zô ð$˜Cð  J°Ñ$5ô ð0 ØØØØ àØØØØØñ€ð&ØÐ4ðàÐ6ðð Ð0ðð Ð2ð	ð
 Ð 3ðð Ð0ðð Ð.ðð Ð.ðð Ð4ðð "Ð#?ðð "Ð#?ðð %Ð&Aðð Ð9ðð !Ð"?ðð  "Ð#6ð!ð" $Ð%>ð#ð$ Ð9ð%€ð,?NØ	ð?NØ%(ð?NØ69ð?Nàô?NôD
(ˆYô 
(ôˆYô ô	ˆyô 	ô"�)ô "ô8�	ô 8ð=˜D ™Lð =¨Sô =ð@'Ø�I‰oð'àõ'r-   