Ë
    øÿæi{¾  ã                   óf  — 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Zd dl	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 d dlmZmZmZ d dlZdˆd„Zd‰d„Zd	„ Zd
„ Zd„ Z d„ Z!d„ Z"d„ Z#	 dŠd„Z$	 dŠd„Z%g Z&e'd   e(d<   d„ Z)d„ Z*d„ Z+d„ Z,d„ Z-e-Z.d„ Z/d„ Z0d„ Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6d „ Z7d!„ Z8d"„ Z9d#„ Z:d$„ Z;d%„ Z<d&„ Z=d'„ Z> G d(„ d)e?«      Z@ G d*„ d+«      ZAd,„ ZBd-„ ZCd.„ ZDd/„ ZEd0„ ZFd1eGfd2„ZH	 	 d‹d3ed4eId5eId1eGfd6„ZJd7„ ZKd8„ ZL G d9„ d:«      ZMd;„ ZNer ed<eO¬=«      d1eIfd>„«       ZPnd1eIfd?„ZPd@„ ZQ ej¤                  dA«      dBe?fdC„«       ZSdDe?d1eTfdE„ZU G dF„ dG«      ZV ej®                  eX«      ZY edH«      ZZ G dI„ dJeeZ   «      Z[dKe?d1edz  fdL„Z\dMdNdOdPdQdRdRdRdSdTdTdUœZ]i dVdW“dXdY“dZd[“d\d]“d^d_“d`da“dbdc“ddde“dfdg“dhdi“djdk“dldm“dndo“dpdq“drd_“dsdt“dudm“Z^dvddweGdxeGd1dfdy„Z_ G dz„ d{e«      Z` G d|„ d}e«      Za G d~„ de«      Zb G d€„ d�e«      Zc G d‚„ dƒe«      Zdd„e'e`   d1eGfd…„Zed†e?edz  d1edfd‡„Zfy)Œé    N)Údefaultdict)ÚCallable)Ú
ModuleType)ÚAnyÚcastÚGenericÚTYPE_CHECKINGÚ	TypedDict)Ú
deprecatedÚNotRequiredÚ	ParamSpecc                 óÒ  — t        d||«      }|€&| j                  dz   | j                  j                  z   S t	        |t
        «      rt        |«      }|t        | «      u r| S | j                  rÀ|j                  st        d«      ‚|j                  j                  dd«      }|dz   |j                  z   }t        j                  j                  | «      j                  ||«      }|dz   }t        j                  j                  | «      j                  ||«      } |||| j                  «       «      S |j                  rt        d«      ‚ || j                  «       «      j!                  | |«      S )a©  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	            úa/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch/_utils.pyÚ_typer,      s9  € ô  .¨f°lÀFÓ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                 ó¾  — | j                   |k(  r| S |j                  dk(  r‘|xr6 | j                   j                  dt        j                  j	                  «       fv }t        j
                  | j                  «       t        j                  ||¬«      j                  «       }|j                  | |«       |S t        t        |j                  d«      }|€&t        |j                  j                  «       › d�«      ‚|j                  |«      5  | j                  rËt        |d«      r¿t        |j                  | j                   j"                  «      } t        t        j$                  j'                  | «      |j                  «      ||«      } t        t        j$                  j)                  | «      |j                  «      ||«      } |||| j+                  «       «      cddd«       S | j                  r't        d|j                  j                  «       › d�«      ‚t        j,                  | j+                  «       |¬	«      }|j                  | |«       |cddd«       S # 1 sw Y   yxY w)
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 LÔ1ØÐäœE 6§;¡;°Ó5€MØÐÜ §¡× 1Ñ 1Ó 3Ð4Ð4PÐQÓRÐRØ	×	Ñ	˜fÕ	%Ø�>Š>œg m°XÔ>Ü˜}×3Ñ3°T·^±^×5LÑ5LÓMˆHØG”gœeŸl™l×3Ñ3°DÓ9¸6¿;¹;ÓGØ˜óˆGð F”WœUŸ\™\×1Ñ1°$Ó7¸¿¹ÓEØ˜óˆFñ ˜G V¨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                 óî   — |s|S t        |«      dk7  sd|vrDd}t        |j                  «       «      j                  «       }t	        |j                  | |«      «      ‚t        j                  dd¬«       |d   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   sm   € ñ ØÐÜ
ˆ6ƒ{�aÒ˜7¨&Ñ0Ø@ˆÜ˜Ÿ™›Ó&×*Ñ*Ó,ˆÜ˜Ÿ™ }°hÓ?Ó@Ð@Ü‡M�MÐ=È!ÕLØ�'‰?Ðr-   c                 óH  — t         j                  j                  j                  }|€| S t	        |t
        «      r|j                  | | «      S t	        |t        t         j                  f«      r|S t        |«      s!t        dt        |«      j                  › �«      ‚t        d«      ‚)z{Return 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¨FÓ3Ð3Ü˜¤s¬E¯L©LÐ&9Ô:ØÐä˜LÔ)Ü$Ø:¼4ÀÓ;M×;VÑ;VÐ:WÐXóð ô ð7óð r-   c                 óª   — t        j                  d| j                  | j                  j                  ¬«      }|j                  | j                  |||«      S )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¸DÀ&ÓIÐIr-   c                 ó¶   — t        | t        j                  «      s!t        dt	        | «      j
                  › �«      ‚t        j                  j                  | «      S )Núexpected torch.Tensor, got )r   r   r   r;   r   r   r4   Ú_get_tensor_metadata©Útensors    r+   Úget_tensor_metadatarl   Ç   sE   € ô �fœeŸl™lÔ+ÜÐ:¼4À»<×;PÑ;PÐ:QÐRÓSÐSÜ�8‰8×(Ñ(¨Ó0Ð0r-   c                 ó  — t        |t        «      s!t        dt        |«      j                  › �«      ‚t        | t
        j                  «      s!t        dt        | «      j                  › �«      ‚t
        j                  j                  | |«       y )Nzexpected dict, got rh   )	r   rY   r;   r   r   r   r   r4   Ú_set_tensor_metadata)rk   Úmetadatas     r+   Úset_tensor_metadatarp   Ð   sj   € ä�h¤Ô%ÜÐ2´4¸³>×3JÑ3JÐ2KÐLÓMÐMÜ�fœeŸl™lÔ+ÜÐ:¼4À»<×;PÑ;PÐ:QÐRÓSÐSÜ	‡H�H×!Ñ! &¨(Õ3r-   c                 óP  — t         j                  j                  d «      �†| j                  «       j                  �lt        | j                  «       j                  «      }t        |t         j                  «      st        j                  |«      }t        j                  |«      | _        | S ©N)	r   Ú_guardsÚdetect_fake_moder9   Ú_fake_devicer\   r   r1   Úfake_device)rk   r1   s     r+   Ú_restore_device_fake_moderw   Ù   sw   € Ü‡}�}×%Ñ% dÓ+Ð7Ø×!Ñ!Ó#×0Ñ0Ð<Ü*¨6×+AÑ+AÓ+C×+PÑ+PÓQˆFÜ˜f¤e§l¡lÔ3ÜŸ™ fÓ-�Ü!&§¡¨fÓ!5ˆFÔØ€Mr-   c                 óp   — t        | |||«      }||_        |rt        ||«       ||_        t	        |«      }|S rr   )rf   Úrequires_gradrp   Ú_backward_hooksrw   )rb   rc   r    rd   ry   Úbackward_hooksro   rk   s           r+   Ú_rebuild_tensor_v2r|   ã   sB   € ô ˜W n°d¸FÓC€FØ(€FÔÙÜ˜F HÔ-ð
 ,€FÔä& vÓ.€FØ€Mr-   c                 óÜ   — t        j                  d|| j                  j                  |¬«      }|j	                  | j                  |||«       |rt        ||«       ||_        t        |«      }|S )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   ú   sh   € ô 	�‰ØØØ×'Ñ'×.Ñ.Ø#ô		€Að ‡F�Fˆ7×#Ñ# ^°T¸6ÔBÙÜ˜A˜xÔ(Ø&€AÔÜ! !Ó$€AØ€Hr-   ztorch.TensorÚ_sparse_tensors_to_validatec            	      óþ  — t         j                  j                  «       j                  «       st        j                  «        y 	 t        D �]ƒ  } | j                  t         j                  u rSt        j                  | j                  «       | j                  «       | j                  «       | j                  «       d¬«       Œs| j                  t         j                  t         j                  t         j                  t         j                   hv r°| j                  t         j                  t         j                  hv r!| j#                  «       | j%                  «       }}n | j'                  «       | j)                  «       }}t        j*                  ||| j-                  «       | j                  «       | j                  d¬«       �Œmt/        d| j                  › d�«      ‚ 	 t        j                  «        y # t        j                  «        w xY w)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ô
 	$×)Ñ)Ô+Øð-,÷ -Ð,ˆ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& Ç&G<c                 óÔ  — | t         j                  k(  rOt        |«      dk(  r	|\  }}}d}n|\  }}}}t        j                  |||d|¬«      }t        j                  |«       |S | t         j                  t         j                  t         j                  t         j                  hv r9|\  }}}}t        j                  ||||| d¬«      }t        j                  |«       |S t        d| › �«      ‚)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�V˜TØ‰Là26Ñ/ˆG�V˜T <Ü×(Ñ(Ø�V˜T°EÈô
ˆô 	$×*Ñ*¨6Ô2Øˆà	Ü×ÑÜ×ÑÜ×ÑÜ×Ñð	ñ 
ð ;?Ñ7Ð˜M¨6°4Ü×/Ñ/ØØØØØØ"ô
ˆô 	$×*Ñ*¨6Ô2Øˆä
Ð DÀVÀHÐMÓ
NÐNr-   c                 ó2   — t        j                  | |||«      S rr   )r   Ú_nested_view_from_buffer)ÚbufferÚsizesÚstridesÚstorage_offsetss       r+   Ú_rebuild_nested_tensorr§   �  s   € Ü×)Ñ)¨&°%¸À/ÓRÐRr-   c                 óP   — t        |«      }| j                  ||¬«      }||_        |S ©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Ø(€FÔØ€Mr-   c                 óv   — t        |«      }t        j                  | «      j                  ||¬«      }||_        |S r©   )r\   r   Ú
from_numpyrª   ry   r«   s        r+   Ú!_rebuild_device_tensor_from_numpyr¯   Œ  s9   € Ü" 6Ó*€FÜ×Ñ˜dÓ#×&Ñ&¨U¸6Ð&ÓB€FØ(€FÔØ€Mr-   c                 ó6   — t        j                  ||| d|¬«      S )NÚmetar~   )r   Úempty_strided)r#   r    rd   ry   s       r+   Ú_rebuild_meta_tensor_no_storager³   —  s    € Ü×ÑØˆf˜E¨&Àôð r-   c           
      óf   — t        |«      }t        j                  j                  | |||||||¬«      S )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                 ó¢  — |d   }|t         j                  k(  r6|\  }}	}
t        j                  ||	|
| j                  | j                  ¬«      }�n^|t         j
                  t         j                  fv �r-|\  }}}}t        |«      t        u råt        |«      t        u rÔ|t         j
                  k(  rat        j                  |t         j                  | j                  ¬«      }t        j                  |t         j                  | j                  ¬«      }n`t        j                  |t         j                  | j                  ¬«      }t        j                  |t         j                  | j                  ¬«      }t        j                  ||||| j                  | j                  ¬«      }nt        d|› �«      ‚|j                  | |||«       ||_        ||_        |S )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É   ¶  sx  € ð ˜qÑ!€GØ”%×)Ñ)Ò)Ø/Ñˆˆ5�*Ü×.Ñ.ØØØ!Ø—-‘-Ø—>‘>ô
Šð 
”U×-Ñ-¬u×/UÑ/UÐVÒ	VØ'7Ñ$ˆˆ6�; Ü�‹<œ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�˜¨¨vÔ6Ø(€FÔð ,€FÔØ€Mr-   c                 óT   — t         j                  j                  | |«      }||_        |S rr   )r   ÚnnÚ	Parameterrz   )rž   ry   r{   Úparams       r+   Ú_rebuild_parameterrÎ   é  s'   € Ü�H‰H×Ñ˜t ]Ó3€Eð +€EÔà€Lr-   c                 ól   — t         j                  j                  | |«      }||_        t	        ||«      }|S rr   )r   rË   rÌ   rz   Ú_set_obj_state)rž   ry   r{   ÚstaterÍ   s        r+   Ú_rebuild_parameter_with_staterÒ   ó  s5   € Ü�H‰H×Ñ˜t ]Ó3€Eð +€EÔô ˜5 %Ó(€EØ€Lr-   c           	      ó  — t        | dd «      }|r	 |«       }|S t        j                  | j                  «      }|r5| j                  |D �ci c]  }t        | |«      r|t        | |«      “Œ c}f}|S | j                  }|S c c}w )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Ô)ð œ' # tÓ,Ñ,Ø -ñðˆEð €Lð —L‘LˆEà€Lùòs   Á	 A=c                 ó  — t        |t        «      r't        |«      dk(  st        d|› �«      ‚|d   }|d   }n|}d }|r%|j	                  «       D ]  \  }}t        | ||«       Œ |r%|j	                  «       D ]  \  }}t        | ||«       Œ | S )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ˆqÜ�C˜˜AÕð 'ñ Ø×%Ñ%Ö'‰DˆAˆqÜ�C˜˜AÕð (à€Jr-   c                 óp   — | j                  d«      }t        |d   «      }|dd  D ]  }t        ||«      }Œ |S )Nr   r   rE   )ÚsplitÚ
__import__r:   )rÛ   Ú
componentsrØ   Ú	components       r+   r   r   0  s>   € Ø—‘˜C“€JÜ
�Z ‘]Ó
#€CØ  “^ˆ	Ü�c˜9Ó%‰ð $à€Jr-   c                 óT   — t         j                  j                  j                  | «      S )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                 ón  — t         j                  j                  j                  | D �cg c]!  }t         j                  j                  |«      ‘Œ# c}«      }t         j                  j                  j                  | D �cg c]!  }t         j                  j                  |«      ‘Œ# c}«      }||fS c c}w c c}w )ab  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   ¨&B-Á<&B2c                 óV   — t         j                  j                  j                  | |«      S )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�<‰<×/Ñ/°°gÓ>Ð>r-   c           	      ó  — | \  }}t         j                  j                  j                  ||D �cg c]!  }t         j                  j                  |«      ‘Œ# c}«      }t         j                  j                  j                  ||D �cg c]!  }t         j                  j                  |«      ‘Œ# c}«      }g }t        |||«      D ]6  \  }}}	|j                  |j                  ||	|j                  «       «      «       Œ8 t        |«      S c c}w c c}w )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‰ˆˆ1ˆaØ�‰�q—u‘u˜Q  1§6¡6£8Ó,Õ-ð 1ä�‹>Ðùò Bùò @s   ®&D
Â&D
c                 ó  ‡— t        t        «      }| D ]$  }||j                  «          j                  |«       Œ& |j	                  «       D ��ci c]  \  }}|t        |«      “Œ c}}Št        ˆfd„|D «       «      S c c}}w )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   óV   •K  — | ]   }t        ‰|j                  «          «      –— Œ" y ­wrr   )Únextr   )Ú.0rk   Ú
type_dict_s     €r+   Ú	<genexpr>z&_reorder_tensors_as.<locals>.<genexpr>œ  s"   øè ø€ ÐO¹°V”�j §¡£Ñ/×0¹ùs   ƒ&))r   rK   r   rœ   rß   ÚiterrÞ   )rí   Úordered_tensorsÚ	type_dictrk   re   Úcollr  s         @r+   Ú_reorder_tensors_asr  ‰  sr   ø€ ô œDÓ!€IÛˆØ�&—+‘+“-Ñ ×'Ñ'¨Õ/ð à/8¯©Ô/@ÔAÑ/@¡G A t�!”T˜$“Z‘-Ð/@ÒA€JÜÓO¹ÓOÓOÐOùó Bs   ÁA;c              #   óœ  K  — t        d„ «      }| D �]  }|j                  «       }|j                  r‚t        j                  j                  |«      }t        j                  j                  |«      }|j                  «       |j                  «       z  |j                  «       |j                  «       z  z   }n!|j                  «       |j                  «       z  }||   }|d   |z   |kD  r|d   dkD  r|d   –— g dgx}||<   |d   j                  |«       |dxx   |z  cc<   �Œ |j                  «       D ]  \  }	}
t        |	«      dkD  sŒ|	–— Œ y­w)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                  ó
   — g dgS )Nr   © r
  r-   r+   Ú<lambda>z_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  Ÿ  s3  è ø€ ô (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˜8 A™;Ø�Q‰×Ñ˜vÔ&Ø�Q‹˜4Ñ�ð! ð" —/‘/Ö#‰ˆˆQÜˆs‹8�a‹<Ø‹Iñ $ùs   ‚EEÅEc                 ó   ‡ ‡— ˆˆ fd„}|S )Nc                 óF   •— t        ‰«      | _        ‰| j                  d<   | S )NÚreturn)rY   Ú__annotations__)Úfunr%   Úrets    €€r+   Údeczannotate.<locals>.decÅ  s$   ø€ Ü" 6›lˆÔØ(+ˆ×Ñ˜HÑ%Øˆ
r-   r
  )r  r%   r  s   `` r+   Úannotater  Ä  s   ù€ õð
 €Jr-   c                 óz  — t         j                  j                  | «      }|€t        | «      }g }t         j                  j                  dd¬«      5  |j                  d„ |D «       «       |j                  d„ |j                  «       D «       «       |› ddj                  |«      › d�}d d d «       |S # 1 sw Y   S xY w)Nr   )Ú	thresholdÚ	edgeitemsc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wrr   ©Úrepr)r   Úas     r+   r  zrender_call.<locals>.<genexpr>Ô  s   è ø€ Ð.© Aœ˜QŸ©ùs   ‚c              3   óB   K  — | ]  \  }}|› d t        |«      › �–— Œ y­w)Ú=Nr  )r   rã   rä   s      r+   r  zrender_call.<locals>.<genexpr>Õ  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_callr1  Í  s£   € Ü�_‰_×)Ñ)¨"Ó-€FØ€~Ü�R“ˆà€HÜ	×	Ñ	×	'Ñ	'°!¸qÐ	'Õ	AØ�‰Ñ.©Ó.Ô.Ø�‰ÑD°V·\±\´^ÓDÔDØˆh�a˜Ÿ	™	 (Ó+Ð,¨AÐ.ˆ÷ 
Bð €H÷	 
Bð €Hús   ÁAB0Â0B:c                   ó   — e Zd ZdZdZd„ Zy)ÚKeyErrorMessagez(str subclass that returns itself in reprr
  c                 ó   — | S rr   r
  ©r"   s    r+   Ú__repr__zKeyErrorMessage.__repr__è  s   € Øˆr-   N)r   r   Ú__qualname__Ú__doc__Ú	__slots__r6  r
  r-   r+   r3  r3  ã  s   „ Ù3à€Iór-   r3  c                   ó   — e Zd ZdZdd„Zd„ Zy)ÚExceptionWrapperz?Wraps an exception plus traceback to communicate across threadsNc                 óž   — |€t        j                  «       }|d   | _        dj                  t	        j
                  |Ž «      | _        || _        y )Nr   r   )ÚsysÚexc_infoÚexc_typer+  Ú	tracebackÚformat_exceptionÚexc_msgÚwhere)r"   r>  rC  s      r+   Ú__init__zExceptionWrapper.__init__ï  sB   € ð ÐÜ—|‘|“~ˆHØ  ™ˆŒà—w‘wœy×9Ñ9¸8ÐDÓEˆŒØˆ�
r-   c                 óP  — d| j                   j                  › d| j                  › d| j                  › �}| j                   t        u rt        |«      }n)t        | j                   dd«      r| j                  |¬«      ‚	 | j                  |«      }|‚# t        $ r t        |«      d‚w xY w)z4Reraises the wrapped exception in the current threadzCaught Ú z.
Original rS   N)rS   )	r?  r   rC  rB  ÚKeyErrorr3  r:   Ú	Exceptionr   )r"   ÚmsgÚ	exceptions      r+   ÚreraisezExceptionWrapper.reraiseù  s¬   € ð ˜Ÿ™×.Ñ.Ð/¨q°·±°¸LÈÏÉÈÐWˆØ�=‰=œHÑ$ô " #Ó&‰CÜ�T—]‘] I¨tÔ4ð —-‘-àð  ó ð ð	.ØŸ™ cÓ*ˆIð
 ˆøô	 ò 	.ô ˜sÓ#¨Ð-ð	.ús   Á<B ÂB%)Nzin background)r   r   r7  r8  rD  rK  r
  r-   r+   r;  r;  ì  s   „ ÙJóór-   r;  c                  óÖ  — t         j                  j                  «       ryt         j                  j                  j                  «       ryt        t         d«      rt         j                  j                  «       ryt        t         d«      rt         j                  j                  «       ryt         j                  j                  «       } t        t         | d «      }|r|j                  «       r| S y ©Nr0   ÚmpsÚxpuÚmtia)r   r0   Úis_availableÚbackendsrN  r=   rO  rP  r4   r5   r:   )Úcustom_backend_nameÚcustom_device_mods     r+   Ú_get_available_device_typerU    s¡   € Ü‡z�z×ÑÔ ØÜ‡~�~×Ñ×&Ñ&Ô(ØÜŒu�eÔ¤§¡×!7Ñ!7Ô!9ØÜŒu�fÔ¤%§*¡*×"9Ñ"9Ô";ØÜŸ(™(×@Ñ@ÓBÐÜ¤Ð':¸DÓAÐÙÐ.×;Ñ;Ô=Ø"Ð"àr-   c                 óÞ  — t        «       }|r)|j                  «       dk(  r | t        j                  «      S |r)|j                  «       dk(  r | t        j                  «      S |r)|j                  «       dk(  r | t        j
                  «      S |r)|j                  «       dk(  r | t        j                  «      S |t        j                  j                  «       k(  r | t        t        |«      «      S y rM  )
rU  Úlowerr   r0   rN  rO  rP  r4   r5   r:   )Ú
get_memberÚdevice_types     r+   Ú_get_device_attrrZ  %  s¼   € Ü,Ó.€KÙ�{×(Ñ(Ó*¨fÒ4Ùœ%Ÿ*™*Ó%Ð%Ù�{×(Ñ(Ó*¨eÒ3Ùœ%Ÿ)™)Ó$Ð$Ù�{×(Ñ(Ó*¨eÒ3Ùœ%Ÿ)™)Ó$Ð$Ù�{×(Ñ(Ó*¨fÒ4Ùœ%Ÿ*™*Ó%Ð%Ø”e—h‘h×<Ñ<Ó>Ò>Ùœ'¤%¨Ó5Ó6Ð6àr-   c                  ó   — t        d„ «      S )Nc                 ó"   — | j                  «       S rr   )Úcurrent_device©Úms    r+   r  z+_get_current_device_index.<locals>.<lambda>7  s   €  a×&6Ñ&6Ô&8r-   ©rZ  r
  r-   r+   Ú_get_current_device_indexra  5  s   € äÑ8Ó9Ð9r-   c                  ó   — t        d„ «      S )Nc                 óF   — t        t        | j                  «       «      «      S rr   )rK   ÚrangeÚdevice_countr^  s    r+   r  z)_get_all_device_indices.<locals>.<lambda><  s   € ¤d¬5°·±Ó1AÓ+BÔ&Cr-   r`  r
  r-   r+   Ú_get_all_device_indicesrf  :  s   € äÑCÓDÐDr-   c                 óH   ‡— | D �‡cg c]  Št        ˆfd„«      ‘Œ c}S c c}w )Nc                 ó&   •— | j                  ‰«      S rr   )Úget_device_properties)r_  rû   s    €r+   r  z)_get_devices_properties.<locals>.<lambda>A  s   ø€  q×'>Ñ'>¸qÔ'Ar-   r`  )Ú
device_idsrû   s    `r+   Ú_get_devices_propertiesrk  ?  s"   ø€ áLVÔWÉJÀqÔÓAÕBÈJÑWÐWùÒWs   ‡r  c                  ó‚   — t         j                  j                  «       dkD  rt         j                  j                  «       S y)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   re  r]  r
  r-   r+   Úget_current_device_indexrn  D  s/   € ô ‡z�z×ÑÓ  1Ò$Ü�z‰z×(Ñ(Ó*Ð*Ør-   r1   ÚoptionalÚ	allow_cpuc                 ó´  — t        | t        «      rt        j                  | «      } d}t        | t        j                  «      r<|s| j                  dk(  rt        d| › �«      ‚| j                  dk(  rdn| j                  }t        | t        «      r| }|€F|r6t        j                  j                  «       rt        «       }|S t        «       }|S t        d| › �«      ‚|S )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: rm  zFExpected a torch.device with a specified index or an integer, but got:)r   r   r   r1   r   Ú
ValueErrorÚindexÚintÚjitÚis_scriptingrn  ra  )r1   ro  rp  Ú
device_idxs       r+   Ú_get_device_indexrx  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                 ó˜   — t        | t        j                  j                  «      s%| j	                  «       rt        j
                  | «      S | S )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}  ~  sC   € ô ˜&¤%§(¡(×"AÑ"AÔBØ×ÑÔô 	×Ñ˜6Ó"ðð ð	r-   c                 óˆ  — t        | t        j                  «      st        dt	        | «      › �«      ‚| j
                  r"t        j                  | «      j                  dz	  S | j                  r"t        j                  | «      j                  dz	  S | t        j                  k(  ryt        j                  | «      j                  dz	  S )z8
    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                   ó   — e Zd Zdd„Zdd„Zy)Ú_ClassPropertyDescriptorNc                 ó   — || _         y rr   )Úfget)r"   rˆ  Úfsets      r+   rD  z!_ClassPropertyDescriptor.__init__ž  s	   € Øˆ�	r-   c                 ó^   — |€t        |«      } | j                  j                  ||«      «       S rr   )r   rˆ  Ú__get__)r"   ÚinstanceÚowners      r+   r‹  z _ClassPropertyDescriptor.__get__¡  s,   € Øˆ=Ü˜“NˆEØ1ˆt�y‰y× Ñ  ¨5Ó1Ó3Ð3r-   rr   )r   r   r7  rD  r‹  r
  r-   r+   r†  r†  �  s   „ óô4r-   r†  c                 óZ   — t        | t        t        f«      st        | «      } t        | «      S rr   )r   ÚclassmethodÚstaticmethodr†  )Úfuncs    r+   Úclasspropertyr’  §  s&   € Ü�dœ[¬,Ð7Ô8Ü˜4Ó ˆÜ# DÓ)Ð)r-   úU`torch._utils.is_compiling` is deprecated. Use `torch.compiler.is_compiling` instead.)Úcategoryc                  ó>   — t         j                  j                  «       S rr   )r   ÚcompilerÚis_compilingr
  r-   r+   r—  r—  °  s   € ô
 �~‰~×*Ñ*Ó,Ð,r-   c                  ól   — t        j                  dd¬«       t        j                  j	                  «       S )zd
        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                 ó¨  — ddl m} t        | |«      r„t        j                  j                  t        j                  j                  j                  «      }	 t        j                  | j                  «       |� t        j                  j                  |«       y y t        j                  | «       y # |� t        j                  j                  |«       w w xY w)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   ÁB- Â-$CrG   rY  c                 óP   — t        t        | d «      }|€t        d| › d| › d�«      ‚|S )NzDevice 'z<' does not have a corresponding module registered as 'torch.z'.)r:   r   r   )rY  r?   s     r+   Ú_get_device_moduler¤  ã  sA   € äœE ;°Ó5€MØÐÜØ�{�mÐ#_Ð`kÐ_lÐlnÐoó
ð 	
ð Ðr-   rÛ   c                 óX   — dt         fd„}t        | t        f |d«       |d«      dœ«      S )NÚis_initc                 ó   ‡ — ˆ fd„}|S )Nc                 ój   •— ‰r| j                   j                  }n| j                  }t        d|› �«      ‚)Nz&Tried to instantiate dummy base class )r   r   r   )rØ   r-  r%   Ú
class_namer¦  s       €r+   Úerr_fnz/_dummy_type.<locals>.get_err_fn.<locals>.err_fnï  s1   ø€ ÙØ Ÿ]™]×3Ñ3‘
à Ÿ\™\�
ÜÐ!GÈ
À|ÐTÓUÐUr-   r
  )r¦  rª  s   ` r+   Ú
get_err_fnz_dummy_type.<locals>.get_err_fnî  s   ø€ ô	Vð ˆr-   TF)rD  Ú__new__)r‚  r   Úobject)rÛ   r«  s     r+   Ú_dummy_typer®  í  s5   € ðœDó ô ØŒvˆi¡j°Ó&6Á:ÈeÓCTÑUóð r-   c                   ó*   — e Zd Zd„ Zd„ Zd„ Zdefd„Zy)Ú_LazySeedTrackerc                 ó.   — d | _         d | _        g | _        y rr   ©Úmanual_seed_all_cbÚmanual_seed_cbÚ
call_orderr5  s    r+   rD  z_LazySeedTracker.__init__  s   € Ø"&ˆÔØ"ˆÔØˆ�r-   c                 óP   — ||f| _         | j                  | j                   g| _        y rr   r²  ©r"   Úcbr@  s      r+   Úqueue_seed_allz_LazySeedTracker.queue_seed_all  s&   € Ø#% y /ˆÔà×.Ñ.°×0GÑ0GÐHˆ�r-   c                 óP   — ||f| _         | j                  | j                   g| _        y rr   )r´  r³  rµ  r·  s      r+   Ú
queue_seedz_LazySeedTracker.queue_seed  s&   € Ø! 9˜oˆÔà×2Ñ2°D×4GÑ4GÐHˆ�r-   r  c                 ó   — | j                   S rr   )rµ  r5  s    r+   Ú	get_callsz_LazySeedTracker.get_calls  s   € Ø�‰Ðr-   N)r   r   r7  rD  r¹  r»  rK   r½  r
  r-   r+   r°  r°  ý  s   „ ò
ò
Iò
Ið
˜4ô r-   r°  ÚPc                   ón   — e Zd Zdefd„Zdeedf   ddfd„Zdej                  dej                  ddfd	„Z
y)
ÚCallbackRegistryrÛ   c                 ó    — || _         g | _        y rr   )rÛ   Úcallback_list)r"   rÛ   s     r+   rD  zCallbackRegistry.__init__  s   € ØˆŒ	Ø68ˆÕr-   r¸  Nr  c                 ó:   — | j                   j                  |«       y rr   )rÂ  rœ   )r"   r¸  s     r+   Úadd_callbackzCallbackRegistry.add_callback  s   € Ø×Ñ×!Ñ! "Õ%r-   r-  r%   c                 ó–   — | j                   D ]  }	  ||i |¤Ž Œ y # t        $ r# t        j                  d| j                  «       Y Œ:w xY w)Nz6Exception in callback for %s registered with gpu trace)rÂ  rH  ÚloggerrJ  rÛ   )r"   r-  r%   r¸  s       r+   Úfire_callbackszCallbackRegistry.fire_callbacks!  sL   € Ø×$Ô$ˆBðÙ�DÐ#˜FÓ#ñ %øô ò Ü× Ñ ØLÈdÏiÉiöðús   ‘œ)AÁA)r   r   r7  r   rD  r   r¾  rÄ  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                 óZ  — t         j                  j                  | d «      x}�|S t        j                  j                  | «      x}�ft        j                  j                  |«      }|t         j                  | <   |j                  €t        d«      ‚|j                  j                  |«       |S y )Nz)The loader attribute should always be set)
r=  Ú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Ô  rd  )rÚ  Úreduce)Ú	functoolsrå  )rÚ  Úintern)r=  rç  )rÚ  Úunichr)rÔ  Úchr)rÚ  Úunicode)rÔ  r   )rÚ  rÃ   )rÔ  rt  )Ú	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Ô  rH  )rÞ  rÞ  ÚresÚ
group_sizeÚ
gather_dimc                 óL  — |dk(  r| S t        | j                  «      }|dkD  rt        j                  |d| «      nd}|d   |k(  r5|dk(  r0dg|d| z   |d   ||   z  gz   ||dz   d z   }| j	                  |«      S t        j                  t        j                  | |d¬«      |¬«      S )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˜% 
Ñ+Ñ+Ð,ñ-ð �J ‘NÐ$Ð%ñ&ð 	ð �x‰x˜Ó$Ð$ô
 �y‰yœŸ™ S¨*¸!Ô<À*ÔMÐMr-   c                   óp   — e Zd ZU dZeed<   eed<   eed<   ee   ed<   ee   ed<   ee   ed<   ee   ed<   y	)
Ú_Framez1Frame information from memory profiler snapshots.ÚfilenameÚlinerÛ   Ú
fx_node_opÚfx_node_nameÚfx_node_targetÚfx_original_traceN)r   r   r7  r8  r   r  rt  r   r
  r-   r+   r  r  ­  s@   … Ù;àƒMØ
ƒIØ
ƒIà˜CÑ Ó Ø˜cÑ"Ó"Ø Ñ$Ó$Ø" 3Ñ'Ô'r-   r  c                   óJ   — e Zd ZU dZeed<   eed<   eed<   eed<   ee   ed<   y)Ú_BlockzMemory block information.r    Úrequested_sizeÚaddressrÑ   ÚframesN)	r   r   r7  r8  rt  r  r   rK   r  r
  r-   r+   r  r  º  s$   … Ù#à
ƒIØÓØƒLØƒJØ�‰LÔr-   r  c                   ó^   — e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   ee   ed<   y	)
Ú_SegmentzMemory segment information.r  Ú
total_sizeÚstreamÚsegment_typeÚallocated_sizeÚactive_sizeÚblocksN)	r   r   r7  r8  rt  r  r   rK   r  r
  r-   r+   r  r  Ä  s0   … Ù%àƒLØƒOØƒKØÓØÓØÓØ�‰LÔr-   r  c                   ó`   — e Zd ZU dZeed<   ee   ed<   ee	   ed<   eed<   eed<   ee   ed<   y)	Ú_TraceEntryzMemory trace entry information.ÚactionÚaddrr  r    r  Údevice_freeN)
r   r   r7  r8  r   r  r   rt  rK   r  r
  r-   r+   r  r  Ð  s4   … Ù)àƒKØ
�cÑ
ÓØ�‰LÓØ
ƒIØƒKØ˜SÑ!Ô!r-   r  c                   ó>   — e Zd ZU dZee   ed<   eeee         ed<   y)Ú	_SnapshotzMemory snapshot structure.ÚsegmentsÚdevice_tracesN)	r   r   r7  r8  rK   r  r  r   r  r
  r-   r+   r"  r"  Û  s$   … Ù$à�8‰nÓØ˜t D¨Ñ$5Ñ6Ñ7Ô7r-   r"  r  c                 óä  — ddl m} ddlm} t	        j
                  t	        j                  |«      › d�«      }d}| D �]0  }|j                  d«      }|j                  d«      }|r|sŒ+|j                  t        j                  j                  |«      «      sŒZ|j                  |«      }|€Œn|j                  di «      }	|j                  di «      }
|j                  d	d«      }|	j                  ||z
  «      }|€Œ»|
j                  |«      }|€ŒÏ|j                  d
«      |d<   |j                  d«      |d<   t        |j                  d«      «      |d<   |j                  d«      }|r||d<   |dz  }�Œ3 |S )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(  r)  r*  Únode_idxÚ	node_infoÚoriginal_traces                  r+   Ú_augment_framesr>  â  sz  € õ BÝ8ô ŸJ™JÜ�I‰IÐ1Ó2Ð3°7Ð;óÐð €EäˆØ—9‘9˜ZÓ(ˆØ—‘˜6Ó"ˆÙ™vØð %×+Ñ+¬B¯G©G×,<Ñ,<¸XÓ,FÔGØà(×,Ñ,¨XÓ6ˆØÐØà—\‘\ ,°Ó3ˆ
Ø Ÿ™ _°bÓ9ˆØ!Ÿ™Ð&6¸Ó:ˆð —>‘> &¨>Ñ"9Ó:ˆØÐØà!×%Ñ% hÓ/ˆ	ØÐØð (Ÿm™m¨DÓ1ˆˆlÑØ )§¡¨fÓ 5ˆˆnÑÜ"% i§m¡m°HÓ&=Ó">ˆÐÑð #Ÿ™ }Ó5ˆÙØ)7ˆEÐ%Ñ&à�‰
ŠðK ðN €Lr-   Úsnapshotc                 óº  — t        | t        «      r9t        | d«      5 }t        t        t        j                  |«      «      }ddd«       n| }j                  dg «      D ],  }|j                  dg «      D ]  }d|v sŒt        |d   «       Œ Œ. |j                  dg «      D ]-  }|D ]&  }t        |t        «      sŒd|v sŒt        |d   «       Œ( Œ/ |S # 1 sw Y   ŒŽxY w)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#  r  r  r$  )
r   r   Úopenr   r"  ÚpickleÚloadrZ   r>  rY   )r?  ÚfÚsnapshot_dictÚsegmentÚblockÚ
trace_listÚtrace_entrys          r+   Ú%_augment_memory_snapshot_stack_tracesrK  "  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ÃC)NF)Frr   )FF)grÕ   ræ  rË  Úloggingrÿ  r4  rC  r0  r=  r@  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  r1  r   r3  r;  rU  rZ  ra  rf  rk  rt  rn  r‚  rx  r}  r„  r†  r’  ÚFutureWarningr—  rŸ  Ú	lru_cacher¤  r   r®  r°  Ú	getLoggerr   rÆ  r¾  rÀ  rÓ  ÚIMPORT_MAPPINGÚNAME_MAPPINGr  r  r  r  r  r"  r>  rK  r
  r-   r+   Ú<module>rW     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-   